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)
}
}
}
}

}

Advertisements
Tagged , , ,

2 thoughts on “Basic IR Motion Alarm with Arduino

  1. Jay says:

    Would you be able to tell me how to modify the code using an IR led and receiver instead of the PIR?

    Thanks

    • loganemakf says:

      I’m not quite sure I understand what it is you want to accomplish…Do you want the alarm to sound when sent a specific IR pattern (like a remote), or just when the IR transmitter turns on? Or maybe you had something else in mind!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: