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

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

Comments

author
chrisjlionel (author)2016-08-15

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

author
Geethaka (author)2016-08-02

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

author
geekrex (author)Geethaka2016-08-02

yes you can use any thing u like

author
Geethaka (author)geekrex2016-08-02

Thank u sir.

author
diy_bloke (author)2016-05-02

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

author
geekrex (author)diy_bloke2016-05-02

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

author
diy_bloke (author)geekrex2016-05-03

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

author
geekrex (author)diy_bloke2016-05-03

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

author
kavish laxkar (author)2016-04-30

baware of indians..:P

author
geekrex (author)kavish laxkar2016-04-30

why bro

About This Instructable

4,026views

122favorites

License:

Bio: 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 ... More »
More by geekrex:DIY 3D Printed Desk Lamp$200 DIY 3D Printer Build$1 DIY Fidget Toy
Add instructable to: