Tag Archives: motion alarms

Basic IR Motion Alarm with Arduino

Just a little side project I worked on to create a better version of the basic radioshack motion alarm. Arduino based (hackduino specifically), expandable, and a good project to start playing with Arduino and electronics.

Motion Alarm Diagram

And here’s the code (it’ll look better once you paste it into the Arduino IDE):

///////////////////////////////////////////////////////////////////////////////
///////////////////////////// PIR Motion Alarms ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////// by loganemakf /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// VARIABLES

int ledPin = 12;
int pirPin = 3;
int alarmPin = 8;
long counter = 0;

// SETUP
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(alarmPin, OUTPUT);
digitalWrite(pirPin, LOW);

// warmup time
digitalWrite(ledPin, HIGH);
for (int i = 0; i = 180000){ // if the counter reaches 180 seconds
digitalWrite(alarmPin, LOW); // turn the alarm off
while(digitalRead(pirPin) == HIGH){ // while the motion continues
digitalWrite(ledPin, HIGH); // turn on the led until motion stops
}
digitalWrite(ledPin, LOW); // then turn the led off
counter = 0; // set the counter back to 0
}
else{ // otherwise (counter is less than),
if(digitalRead(pirPin) == LOW){ // check to see if there is motion
delay(2000); // and wait 2 seconds to ensure none
if(digitalRead(pirPin) == LOW){ // If there is still no motion
counter = 0; // reset counter
delay(40000); // and leave alarm on for 40 seconds
digitalWrite(alarmPin, LOW); // then turn the alarm off
}
else{ // and if there happens to be motion
goto label; // goto label (skip unneeded HIGH check)
}
}
}
}

}

Tagged , , ,