3.5 $ P.I.R. Arduino Intruder Alarm

4,416

124

10

Published

Introduction: 3.5 $ P.I.R. Arduino Intruder Alarm

About: So basically i am a crazy person, who loves to think the most odd way ever possible,who makes what he thinks and also let other also make those . Check out my crazy projects if you like do follow me :D

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 .

Note this might look like an egg according to my Girl Friend dont try to boil it and eat it :P

Step 1: Ingredients

So for this project we would need

You will also need a powerbank as a power source

i used the one i made .
you can also make one

https://www.instructables.com/id/Powerduino-1-Powerbank/

Step 2: About the PIR Sensor

PIRs are basically made of a pyroelectric sensor.The one above as the round metal can with a rectangular crystal in the center.It can detect levels of infrared radiation. Everything emits some low level radiation, and the hotter something is, the more radiation is emitted. The sensor in a motion detector is actually split in two halves. The reason for that is that we are looking to detect motion (change) not average IR levels. The two halves are wired up so that they cancel each other out. If one half sees more or less IR radiation than the other, the output will swing high or low.

There are two Trimmer in the PIR sensor this pots adjust the delay time and the sensitivity ,individually i added the note in the 3rd pic for references.

There is also a jumper for selecting the trigger mode ,

There are two trigger modes

H (re trigger ):Output remains high when sensor is triggered repeatedly and low when idle.

L (Normal ): Output goes hig to low when triggered .Continous motion results in repeated high low pulse

Step 3: 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: Coding Time

About the 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);
           }
       }
  }

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Casting Contest

      Casting Contest
    • Microcontroller Contest

      Microcontroller Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    10 Comments

    Nice and Clear instruction. Thanks.
    Show some real egg to your Girl friend. LOL..

    sir, Can't we use an alternative without the police siren? It is somewhat expensive and big.

    2 replies

    yes you can use any thing u like

    Nice one. I think maybe the Arduino might not even be necessary. That PIR as far as I know that type, delivers a high out that can trigger a transistor with a siren in its collector

    3 replies

    Yes you are right , but in that case led could not be blinked ,
    Else another ne555 will be needed

    very true... although you could add a blink-led :-)
    But nevertheless an arduino gives more possibilities for expansion

    yes , the possibilities are endless , also learning is easy with Arduino