Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Burglar Alarm With PIR Motion Sensor

DZone's Guide to

Burglar Alarm With PIR Motion Sensor

Ever wanted to create your own burglar alarm? This tutorial will show you how to, using an Intel Galileo and a PIR Motion Sensor.

· IoT Zone
Free Resource

Download Red Hat’s blueprint for building an open IoT platform—open source from cloud to gateways to devices.

A friend from C# Corner asked me about the PIR Motion Sensor and its working. Recently I got it for one of my projects, and when it was in my hands, the first thing that came to 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 are always 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 up to 6 meters. It plays a buzzer and lights up LEDs when detects any intrusion in my room. Let's understand more about PIR Motion Sensor and its technology to create some cool stuff 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.

WP_20150831_010WP_20150831_011WP_20150831_012

 

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.

Working
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 it working in action.

Prerequisite

  • Arduino Compatible board with power supply

  • PIR Sensor

  • An LED

  • A Buzzer

Grove – PIR Motion Sensor

In this article I am going to use Grove’s PIR Motion Sensor and going to show how it works 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. 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

Connections

WP_20150831_020
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
 turnOnBuzzer();
 else
 turnOffBuzzer();
 }
 void turnOnBuzzer()
 {
 digitalWrite(LED,HIGH);
 for (int i = 0; i < length; i++)
 {
 if (notes[i] == ' ')
 {
 delay(beats[i] * tempo); // rest
 }
 else
 {
 playNote(notes[i], beats[i] * tempo);
 }
// pause between notes
 delay(tempo / 2);
 }
 }
 void turnOffBuzzer()
 {
 digitalWrite(LED,LOW);
 digitalWrite(speakerPin,LOW);
 }

 

code





















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

Build an open IoT platform with Red Hat—keep it flexible with open source software.

Topics:
galileo ,pir ,sensor ,iot

Published at DZone with permission of Pooja Baraskar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}