Arduino Motion Sensor Alarm Tutorial: The Easy Way

Arduino Motion Sensor Tutorial DIY Hacking

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, automated appliances, etc. 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 pin out

PIR motion sensor pin out

What are the stuff required to do this project?

Hardware:

  1. Arduino or an arduino clone board (freeduino), or make your own custom arduino board with this tutorial.
  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, a 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.

Working of a PIR motion sensor DIY hacking

Working of a PIR motion sensor

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

Arduino Motion Sensor Tutorial

Arduino Motion Sensor Tutorial

The piezo buzzer is activated through the arduino using PWM signals. The source code for this project at the end of this tutorial will show you how to do this.

Step 1: Connecting the PIR arduino motion sensor

The connections required for interfacing the arduino motion sensor and the piezo buzzer is really simple. Connect the motion sensor to arduino as per the following connection diagram. Connect the Vcc and GND of the sensor to arduino’s 5V and GND pins. Next, connect the Output signal pin of the motion sensor to arduino’s digital pin no 2 (interrupt pin 0).

Arduino Motion Sensor Tutorial DIY Hacking

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 arduino’s GND pin. And the positive terminal of the buzzer (red wire) to arduino’s digital pin no 9.

Step 2: 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 from here. 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 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 posses, it’s sensitivity and delay time could be adjusted. So, adjust it correspondingly till it reaches the sweet spot.

Arduino Motion Sensor Tutorial DIY Hacking

Arduino Motion Sensor serial monitor

Here, whenever the PIR motion sensor detects a person, it outputs a digital HIGH signal to 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 for creating the alarm sound on the piezo buzzer or speaker. It does this by writing PWM signals of varying period and frequencies to the piezo buzzer.

Arduino Motion Sensor Tutorial DIY Hacking

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.

So, use this arduino motion sensor to build burglar alarm systems, home automation systems or any simple gadget which prevents people from getting into your room ;) Watch the sensor in action in the video below:

 

Recommended Posts
Showing 6 comments
  • 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/

Leave a Comment

+ 41 = 43

Start typing and press Enter to search