radarsensor

last year i built this very simple motion detection device. it will trigger a noteOn midi message when someone enters a room, and a noteOff message when there's no activity. it's using a RCWL-0516 radar sensor and a digispark clone (basically a attiny85).

radarsensor

//with Digispark (Default - 16.5mhz)
//RCWL-0516 Microw. Radar-ModulRCWL-0516

#define USB_CFG_DEVICE_NAME     'm','i','d','i','R','a','d','a','r'
#define USB_CFG_DEVICE_NAME_LEN 9
#include <DigiMIDI.h>

#define PINLED 1  //onboard led
#define PINSENSOR 2 //radar sensor
#define NOTE 99  //midi note
#define VELO 64  //midi velocity
#define CHAN 9  //midi channel

DigiMIDIDevice midi;

int state = 0;

void setup() {
  pinMode(PINSENSOR, INPUT);
  pinMode(PINLED, OUTPUT);
  midi.sendNoteOff(NOTE, VELO, CHAN);
}

void loop() {
  midi.update();

  if (digitalRead(PINSENSOR) == 1) {
    if (state == 0) {
      digitalWrite(PINLED, HIGH);
      midi.sendNoteOn(NOTE, VELO, CHAN);
      state = 1;
    }
  } else {
    if (state == 1) {
      digitalWrite(PINLED, LOW);
      midi.sendNoteOff(NOTE, VELO, CHAN);
      state = 0;
    }
  }
  midi.delay(100);
}

the device show up as a midi device and the following code is an example of how to connect to it in supercollider...

MIDIClient.init;
MIDIIn.connectAll;
MIDIdef.noteOn(\radarOn, {|...args| [\radarOn, args].postln}, 99);
MIDIdef.noteOff(\radarOff, {|...args| [\radarOff, args].postln}, 99);

MIDIdef.trace;