Burglar Alarm with PIR Motion Sensor 4

A friend from C# Corner asked me about PIR Motion Sensor and its working. Recently I got it for one of my project, when it was in my hands first thing came in my mind was to write an article about it. Working with Sensors is always amazing. I am always excited when I run my first Sketch with a new type of Sensor and they always get successful in impressing me. This Sensor is one of them, it is so small yet powerful. When somebody walks into my room it notifies me, isn’t that cool? For demonstration I made a Burglar Alarm System with this. Its detecting range is upto 6 meters. It plays buzzer and light up LED when detects any intrusion in my room. Let us understand about PIR Motion Sensor and its working to create some cool stuffs like this.

PIR Motion Sensor

“A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view.” It is also referred to PIR, “Passive Infrared”, “PID”, “Pyroelectric”, or “IR motion” sensors. These are small, inexpensive and operates on low power. PIR sensors are most commonly used to detect motion like if someone moves in or out within the Sensor’s range.


How it Works

Everything emits some radiations if human, animal or any object passes within the Sensor’s range, the temperature at that point in the sensor’s field of view will rise from room temperature to body temperature, and then back again. The sensor will detect the change in Infrared Radiation. PIR Sensors are basically made of a “Pyroelectric sensor” which can detect levels of infrared radiation “Pyroelectricity” means- heat that generates electricity, hence these sensor converts change in Infrared Radiation to Change in Output Voltage. These sensors usually have a small plastic covering which is actually the lens which increases its sensing range. The Plastic lens have may multiple facets to focus the infrared energy onto the sensor. Each individual facet is a Fresnel lens. PIRs does not emit any Infrared and unlike other active sensors they does not send out anything hence they are called Passive Sensors. This image will help you to understand the working of PIR sensor.

For this project we are going to make a Burglar Alarm System. It will detect intrusion or any fire outbreak in your home. Let us see its working in action.


Arduino Compatible board with power supply
PIR Sensor
A Buzzer

Grove – PIR Motion Sensor

In this article I am going to use Grove’s PIR Motion Sensor and going to show its working with Intel Galileo Gen1. You can reproduce the same example with Galileo gen2 or Arduino boards. This sensor has Grove compatible interface, you have to just connect it through the Base Shield and start programming for it. If you are not aware of Grove Sensors please go through my article Grove Starter Kit With Intel Galileo Gen 2: Getting Started . This sensor has max 6 meters of detecting range but by default it is 3 meters, you can increase or decrease it by attaching a Potentiometer to the circuit. Other Specifications are-


• Grove compatible interface
• Voltage range: 3V–5V
• 2.0cm x 4.0cm twig module
• Detecting angle: 120 degree
• Detecting distance: max 6m (3m by default)
• Adjustable detecting distance and holding time


Since we are using Grove’s Sensors we don’t have to worry much about the connections or polarity. Here I have placed the Base Shield on my Galileo Gen 1 and connected the PIR Sensor to pin D2 and I also hooked up an LED to pin D4 and a Buzzer to pin D3 so in case if a motion is detected it will alert us.

The Code

void loop()
 if(isPeopleDetected()) //if it detects the moving people
 void turnOnBuzzer()
 for (int i = 0; i < length; i++)
 if (notes[i] == ' ')
 delay(beats[i] * tempo); // rest
 playNote(notes[i], beats[i] * tempo);
// pause between notes
 delay(tempo / 2);
 void turnOffBuzzer()


The code is self-explanatory. When a motion is detected we are sending output to the Buzzer and LED.
I am including a complete working code with this article, you are free to download it and can play around that.


Other Project Ideas with PIR Sensor

Thief-guarding System
Occupancy sensors- If somebody is in room it will turn on the lights
Motion activated outdoor flood lights (definitely will save electricity)
Automatic Doors

Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “Burglar Alarm with PIR Motion Sensor

  • Jonathan Gallardo

    Is it possible if you can attach a file with the code? I have an intel edison board and Im trying to use this code with it and try to perform this as well. Thanks!

    • Pooja Baraskar Post author

      Hi Akarsh, I will be soon writing a blog post about all the stuffs that you need to get started with IoT. Stay tuned. Meanwhile you can also join my webinar on this Sunday to know more on IoT.