An Easy Way to Build an Arduino Powered Motion Sensor Alarm

 

Have you ever wanted to build a project that had could detect the presence of a person in a room? If so, then you can do this very easily using the PIR (Passive Infra Red) Motion sensor. This Arduino motion sensor can detect the presence of a person in a room. Therefore, you can build projects such as burglar alarms and automated appliances. Attach this motion sensor along with an Arduino and place it in your room to build an intruder detection system.

This tutorial will show you to interface a motion sensor with an Arduino and to use it to build a burglar alarm. This system detects the presence of an intruder in your room and sends a signal to the Arduino. The Arduino then creates an alarm sound using a buzzer to scare the intruder away.

PIR motion sensor pinout

PIR motion sensor pinout

Required Materials

Hardware:

  1. Arduino or an Arduino clone board (freeduino), or you can make your own custom Arduino board.
  2. PIR Motion Sensor.
  3. A piezo buzzer or an 8-ohm speaker.
  4. 9V Battery and connector.
  5. Connecting wires.

Software:

Arduino IDE

How Does it Work?

Here, we are using a PIR motion sensor. PIR stands for Passive InfraRed. This motion sensor consists of a fresnel lens, an infrared detector, and supporting detection circuitry. The lens on the sensor focuses any infrared radiation present around it towards the infrared detector. Our bodies generate infrared heat and as a result, this gets picked up by the motion sensor. The sensor outputs a 5V signal for a period of one minute as soon as it detects the presence of a person. It offers a tentative range of detection of about 6-7 m and is highly sensitive.

 

How a PIR motion sensor works

How a PIR motion sensor works

 

When the PIR motion sensor detects a person, it outputs a 5V signal to the Arduino. Thus, an interrupt on Arduino is triggered. We define what the Arduino should do as it detects an intruder. Here, we are creating an alarm sound through a piezo buzzer. When the sensor detects an intruder, an alarm sound will get triggered through the buzzer.

 

The Arduino Motion Sensor System

The Arduino Motion Sensor System

 

The piezo buzzer is activated through the Arduino using PWM (Pulse Width Modulation) signals. The source code for this project at the end of this tutorial will show you how to do this.

Connecting the PIR Arduino Motion Sensor System

The connections required to interface the Arduino motion sensor and the piezo buzzer are really simple. Connect the motion sensor to your Arduino as per the following connection diagram. Connect the Vcc and GND on the sensor to the aAduino’s 5V and GND pins. Next, connect the Output signal pin on the motion sensor to the Arduino’s digital pin 2 (interrupt pin 0).

 

Arduino Motion Sensor and Piezo Buzzer connections

Arduino Motion Sensor and Piezo Buzzer connections

 

After hooking up the Arduino motion sensor, we have to connect the piezo buzzer to this system. To do this, connect the negative terminal of the buzzer (black wire) to the Arduino’s GND pin and the positive terminal of the buzzer (red wire) to the Arduino’s digital pin 9.

Uploading the Code for the Arduino Motion Sensor and Piezo Buzzer

Now, we have to test the Arduino motion sensor along with the piezo buzzer to see if it works. To do this, download the code for the Arduino motion sensor project. Next, open this code in the Arduino IDE. Upload the code to your Arduino. Check if it works by opening the serial monitor (at a baud rate setting of 115200bps).

Note that the motion sensor will take a minute to get calibrated with the surroundings after you power it up. The sensor gets activated whenever you are within a 6-7 m of the radius of the Arduino PIR motion sensor. After which, the piezo buzzer will begin to make an alarm sound and the string – “Intruder detected” gets printed on your serial monitor. The sensor outputs a LOW signal (0V) after a minute when you are no longer near the radius of the PIR motion sensor. Depending on the PIR motion sensor you use, its sensitivity and delay time can be adjusted. So, adjust it correspondingly till it reaches the sweet spot.

 

Arduino Motion Sensor Tutorial DIY Hacking

Arduino Motion Sensor serial monitor

 

Whenever the PIR motion sensor detects a person, it outputs a digital HIGH signal to the Arduino’s digital pin 2. This immediately triggers an interrupt function called: intruder_detect(). You can program the Arduino to do something when it detects an intruder by editing the function: intruder_detect(). Currently, it first prints the string: “Intruder detected”. Next, it runs a function called: siren() three times. The function: siren(), consists of the code required to create the alarm sound on the piezo buzzer or speaker. It does this by writing PWM signals of varying periods and frequencies to the piezo buzzer.

 

 

You will also notice that there is a delay associated with the motion sensor after each detection. Depending on the sensor, you may be able to adjust this delay.

Use this Arduino motion sensor to build burglar alarm systems, home automation systems, or any simple gadget that prevents people from getting into your room! Watch the sensor in action in the video below.

 

 

 

 

 

 

 

 

[/vc_column_text][/vc_column][/vc_row]
Recommended Posts
Showing 15 comments
  • the silly
    Reply

    albert chang is a beta cuck

  • Larry Fostano
    Reply

    Figured it out, thanks ,turns out i had voltage backwards on PIR. Like I said newbie,if nothing else I am getting a math exercise with the captcha.LOL
    Just an issue here , now it does work, I get the message intruder detected but after it sends message 4 times it stops,why?

  • Larry Fostano
    Reply

    Ok found out I had an issue with the code, my problem, still all I get is the word In.Could it be something to do with what I am using for the pir LHI878?

  • Larry
    Reply

    Ok so I believe I know the problem , just not sure what I can do to resolve it,any help would be appreciated. I have built the circuit above but do not have a PIR board , what I have is a PIR component, LHI878 rescued from a old motion switch. 3 wire GSD I have put +5vdc from Arduino to I believe S and – to G and pin 2 to D . Anyone here able to help me here, is this a viable circuit? Thank Newbie here

  • Larry
    Reply

    Uploaded your code, ran it at the baud rate you instructed , first time it just printed out in then intruder but now it just puts up a 1 in serial monitor.both NL and CR . Can you direct me to a fix? Also would like to use this or something similar for a driveway detector,driveway is 750′ long and would like some sort of a detector.Thanks

  • Tara Daniel
    Reply

    Hello!

    I am doing an assignment for school on this project and I would just like: 1) permission and 2) the author’s information so that I can properly cite them!

    Thank you!

  • M.Jeyaram
    Reply

    How to identify that object is human? suppose a bird (or) animal is involve that place(Home or public place). At that time alarm is ON stage.so, many peoples are disturbed. How to reduce the problem? Give me a solution…

    • K-R
      Reply

      The PIR sensor is not what you want for this. It operates by sensing a sudden change in temperature, any heated living thing can possibly trigger it. Now possibly you could set the threshold? (All theoretical here.) And possibly tell it to only go off if the temperature changes this much, so that a bird wont trip it but a human will.

  • prasanna
    Reply

    using aurdina unois cost effective one…without that can we operate buzzer?

  • Shreesottam
    Reply

    I am planning to interface it for switching on/off the light.
    What modifications Should I make in coding?
    intruder++;
    Serial.println(“Intruder detected”);
    for(int i=0; i<3; i++)//Play the alarm three times
    siren();
    }
    void siren()//This function will make the alarm sound using the piezo buzzer
    {
    for (count = 0; count < MAX_COUNT; count++) {
    for (count3 = 0; count3 <= (melody[count*2] – 48) * 30; count3++) {
    for (count2=0;count2<8;count2++) {
    if (names[count2] == melody[count*2 + 1]) {
    analogWrite(speakerOut,1023);
    delayMicroseconds(tones[count2]);
    analogWrite(speakerOut, 0);
    delayMicroseconds(tones[count2]);
    }
    if (melody[count*2 + 1] == 'p') {
    // make a pause of a certain size
    analogWrite(speakerOut, 0);
    delayMicroseconds(100);

  • JobPal
    Reply

    Hi! Can you show your circuit diagram with the breadboard. Thank You!

  • Logaraj
    Reply

    Hi sir, can i get the Ardino Programme for this project… Wondering if i could test and learn. Thank you very much Sir

  • michael
    Reply

    I posted your script/sketch in one of my videos. https://www.youtube.com/watch?v=QBX7nsvZj_Q&feature=youtu.be

  • Arvind Sanjeev
    Reply

    Hi, I am assuming that this is the problem with the motion sensor. Some of them have large delays for sensing i.e., after sensing one time, it stays high for a certain period of time. Unless you have one of those sensors in which accuracy and delay can be adjusted, you dont have any other options. Check this: http://diyhacking.com/pir-motion-sensor-automate-home/

pingbacks / trackbacks

Leave a Comment

30 − 26 =

Start typing and press Enter to search