Motion Sensor and MIDI  for soundinstallation

Hello peeps,
i need help on a sound installation project. i´ve got 2 parralax PIR motion sensors connected to my arduino. the sensors are mounted on 2 wooden objects. if a person is approaching an object the motions sensors will detect it. now i want the sensors reaction to trigger a soundfile for each object. for i am firm with sequenzers, i regard midi as the most flexible way to use in this case.
I am not firm with code. any ideas?

miksen

Both using PIR detectors and sending MIDI data from Arduino has been done, so you should be able to find info about it by searching the forum.

Or check the long list of great Arduino knowledge here:

Code for parallax motion sensor here:
http://www.arduino.cc/playground/Code/PIRsense

thank you MikMo,

i found a code for triggering drum sounds with midi by hitting switches and piezos. i tried to modify the code for my needs.
i changed switches for my sensors / it is all about on and off, right? do you think this will work?
i will try this evening.

miksen

If I remember correctly, the Parallax PIR’s data pin goes high when the detector is triggered. According to the playground entry they do go low from time to time, randomly, but that shouldn’t matter. Good MIDI practice is to send a “noteOn” event with detection, add a short delay (delay(10) or delay(20)) to prevent multiple triggering, then as soon as the pin returns a LOW again send the corresponding MIDI noteOff event.

A way I did this on my own little RF-to-MIDI project was to set an internal flag, “sounding,” whenever I sent a noteOn event; this was a reminder to the circuit to send a corresponding noteOff the moment the trigger was released.

On the sampler side, set yourself up in one-shot sample, drum mode (whatever your particular hardware/software calls it) so the entire sound clip will play regardless of the length of the triggering note event.

Oh, let me pseudo-code this;

if PIR = “HIGH” then
noteOn;
sounding = “HIGH”;
delay(20);

if PIR = “LOW” and sounding = “HIGH” then
noteOff;
sounding = “LOW”;

hey nomouse,

thank you very much. i ve got the basic setup runnin. sensor detects motion and sends midi note on. triggering a one-shot sample works as well. only thing is that the sensor seems a little unstable. i found something in the forum about calibration time every time the circuit is powered up. i try to add this to code.
you are right sometimes the sensor goes low, even if a motion is still present. i will try to tell arduino to ignore this by your “sounding” idea. i hope this works out.
thank you so far…

miksen

hi,
just to close this thread. everything is working. i got two sensors detecting different directions. each sensor causes a different midi signal (and a different soundfile to be played in the end). a little annoying is the fact that every soundfile is triggered 3 times each sensor detection. for i use very atmospheric sounds with a pretty long attack and release time it does not really matters.
here comes the code:

//this bases on the code for midi drumkit
// copyleft 2006 Tod E. Kurt <tod@todbot.com http://todbot.com/
// put together and rearranged by miksen for marcia at art academy duesseldorf 2008

//VARS
#define midichannel 1 //defines the channel we use for midi note on and off

#define note_box1 35 //define the midi note for first soundfile

#define note_box2 38 //defines the midi note for second soundfile

int calibrationTime = 30; //the time we give the sensor to calibrate (10-60sec)

long unsigned int lowln; //the time when the sensor outputs a low impulse

long unsigned int pause = 5000; //the amount of milliseconds has to be low before we assume no more motion is present

int pirsensorAPin = 7;
int pirsensorBPin = 8;
int ledPin = 13;

void setup() {
Serial.begin(31250); //MIDI baud rate
pinMode(pirsensorAPin, INPUT); //Sensor 1
pinMode(pirsensorBPin, INPUT); //Sensor 2
pinMode(ledPin, OUTPUT); //blinking LED indicates that midi data is send
digitalWrite(pirsensorAPin, LOW); //both sensors set to LOW
digitalWrite(pirsensorBPin, LOW); //no motion state
for(int i = 0; i < calibrationTime; i++){
delay(1000);
delay(50);

}
}

void loop() {
if(digitalRead(pirsensorAPin) ==HIGH){ //motion is detected
noteOn(midichannel, note_box1, 100); //midi note on is send
delay(500);
}

if(digitalRead(pirsensorAPin) == LOW ){ //no more motion
noteOff (midichannel, note_box1, 0); //midi note off is send
delay(500);
}

if(digitalRead(pirsensorBPin) ==HIGH){ // same for the second sensor
noteOn(midichannel, note_box2, 100);
delay(1000);
}

if(digitalRead(pirsensorBPin) == LOW ){ //same as above
noteOff (midichannel, note_box2, 0);
}
}

// Send a MIDI note-on message
void noteOn(byte channel, byte note, byte velocity){
midiMsg( (0x80 | (channel<<4)), note, velocity);
}

// Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | (channel<<4)), note, velocity);
}

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
digitalWrite(ledPin,HIGH); // indicate we’re sending MIDI data
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
digitalWrite(ledPin,LOW);
}

improvements are welcome…

thanks everybody who helped me out with this :wink:

miksen