Oct 18 2009
Motion Detection Arduino Code
/*
motion detection code for parallax module from radio shack
**20091015 brb**
basic motion/infrared detection software
**20091015 brb**
add similtaneous green led blinks during motion poll
parts:
3 leds (2 green, 1 red)
1 parallax PIR sensor
on detection of any motion, binary signal on digital pin 8
changes, which causes led on digital pin 5 to light
while motion is not being detected, blink the pins leds on
digital pins 6 and 11. this pause is accomplished by
incrementing a loop timer from 100 to 200 and then reseting
it to zero every 100 intervals (currently 10 miliseconds).
every whole second the led pins alternate being on and off
i reccomend setting the motion detection to H output using
the jumpers on its board; this will make it continuously
trigger the event on constant motion
*/
int ledPin = 5;
int ledPinG1 = 6;
int ledPinG2 = 11;
int modectPin = 8;
int pinin = 0;
int counter = 100;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPinG1, OUTPUT);
pinMode(ledPinG2, OUTPUT);
pinMode(modectPin, INPUT);
}
void loop()
{
pinin = digitalRead(modectPin);
while (pinin == 0) {
digitalWrite(ledPin, LOW);
counter = counter + 1;
if(counter == 100){
digitalWrite(ledPinG2, HIGH);
digitalWrite(ledPinG1, LOW);
}
if(counter == 200){
digitalWrite(ledPinG2, LOW);
digitalWrite(ledPinG1, HIGH);
counter = 0;
}
delay(10);
pinin = digitalRead(modectPin);
}
digitalWrite(ledPinG2, LOW);
digitalWrite(ledPinG1, LOW);
digitalWrite(ledPin, HIGH);
}

