Arduino Intruder Alarm Using PIR


Passive infrared sensors are great for motion detection projects, i brought it recently for a college project and i was actually being tempted to use it .
Unfortunately all i got from The INTERNET were not that much fun .
I took out some of my favorite old parts and started tinkering with it .

The result was a motion detected Intruder alarm.
I added two led to simulated police siren light and added Siren to it for the real fun.
The sensitivity was made to medium values , and then the fun began .

Step 1: Materials

So for this project we would need
  • Arduino UNO(compatibles ones work too);
  • 1x Blue Led
  • 1x Red Led
  • PIR Sensor
  • 12 V Siren
You will also need a powerbank as a power source

Step 2: Connecting the sensor and the components





The PIR sensor has three pins
  1. Vcc
  2. Data
  3. Ground
so the connections are simple we connect
Vcc to 5v
Gnd to Gnd
Data to 3
Now for the siren
Connect
positive to pin 11
Gnd to Gnd
Lastlat the Led are connected to 7 and 8

Step 4: Code

int calibrationTime = 45;
//the time when the sensor outputs a low impulse long unsigned int lowIn; //the amount of milliseconds the sensor has to be low //before we assume all motion has stopped long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime; int pirPin = 3; //the digital pin connected to the PIR sensor's output int ledPin = 11; int led1=8; int led2=7; ///////////////////////////// //SETUP void setup(){ Serial.begin(9600); pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); pinMode(led1,OUTPUT); pinMode(led2,OUTPUT); digitalWrite(pirPin, LOW); //give the sensor some time to calibrate Serial.print("calibrating sensor "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); } Serial.println(" done"); Serial.println("SENSOR ACTIVE"); delay(50); } void alert() { digitalWrite(led1,HIGH); digitalWrite(led2,LOW); delay(50); digitalWrite(led2,HIGH);digitalWrite(led1,LOW); delay(50); } void loop(){ if(digitalRead(pirPin) == HIGH){ analogWrite(ledPin, 50); alert(); digitalWrite(led1,LOW); digitalWrite(led2,LOW); ;//the led visualizes the sensors output pin state if(lockLow){ //makes sure we wait for a transition to LOW before any further output is made: lockLow = false; Serial.println("---"); Serial.print("motion detected at "); Serial.print(millis()/1000); Serial.println(" sec"); delay(50); } takeLowTime = true; } if(digitalRead(pirPin) == LOW){ digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state if(takeLowTime){ lowIn = millis(); //save the time of the transition from high to LOW takeLowTime = false; //make sure this is only done at the start of a LOW phase } //if the sensor is low for more than the given pause, //we assume that no more motion is going to happen if(!lockLow && millis() - lowIn > pause){ //makes sure this block of code is only executed again after //a new motion sequence has been detected lockLow = true; Serial.print("motion ended at "); //output Serial.print((millis() - pause)/1000); Serial.println(" sec"); delay(50); } } }
Previous
Next Post »
3IG