Skip to main content

How To Interface PIR Sensor With Arduino And Coding

 

How To Interface PIR Sensor With Arduino

 
Hello... Ever thought of detecting motion via your Arduino.... if yes, then this one's for you. In this tutorial, We're interfacing PIR sensor today with Arduino. Let's gets started!

Block Diagram
Working of PIR Motion Sensor
Block Diagram
Components Required For This Tutorials
  1. 1 * Arduino Board
  2. 1 * PIR Motion Sensor(you can buy from here)  
  3. Breadboard
  4. Jumper wires
  5. Battery

What is PIR motion sensor & how it works?

Basically, a PIR stands for "Passive Infrared Sensor". The sensor works on the principle of infrared waves' detection those are being emitted by human bodies. They are undetectable to us but can be discovered by the devices designed for such special purposes. I'm going to go just a little deep, enough to make you understand the internal operation.
When a body moves in front of a PIR sensor, the temperature of that place changes where the body has moved. If the body makes a further movement, the composition of infrared waves being received by the PIR from that region changes and since the reading is not the same as last reading, it generates a signal for the microcontroller and we work on it accordingly.


Circuit Diagram
We can easily interface PIR motion sensor with Arduino-like our other sensor. But it all depends on our logic of the code, how efficiently do we want to detect motion through it.
A PIR has 3 pins, just like any other sensor, Vcc, Signal & Ground pin. A very simple circuit of interfacing PIR motion sensor with Arduino is shown below
circuit diagram of PIR Motion Sensor
Circuit 
PIR Motion Sensor description
                                                                                          PIR Motion Sensor                                          
The 2 knobs are there too. One for adjusting sensitivity by increasing or decreasing the range of motion detection and another one for response delay. If you're using PIR in your home security, I strongly suggest you set the range at maximum (towards right). However, the detection range offered by a PIR sensor is good enough, like about 6 metres as I've tested it successfully.

Source Code
Here is a very simple code for this tutorial which only detects if there is ANY motion and triggers an LED for confirmation.Write below code into Arduino IDE and compile it.

int pirSensor=5;                                                     // connect sensor at pin 5
int led=13;                                                             // connect led at pin 13
void setup() 
{
   Serial.begin(9600);                                             // initialize serial
   pinMode(led, OUTPUT);                                  //  initialize led as output
   pinMode(pirSensor, INPUT);                            //  initialize sensor as input  
}

void loop() 
{
  int sensorValue = digitalRead(sensor);                // read sensor value
  Serial.println(sensorValue);                                 // print sensor value  
  delay(100);                                                          //  delay 100 miliseconds
  if(sensorValue > 600)
  { digitalWrite(led,HIGH); }
}

Now you can connect the signal pin to any analog pin also but for that, you'll have to check what values do you get on the serial monitor and which value do you wish to use as a threshold for triggering any LED, buzzer, etc.
Note that the sensor first takes some time for its calibration and after that it starts detecting motion. If any motion is detected, it triggers the LED on Arduino board and keeps searching for the motion for a certain amount of time. It only settles low if there is no further motion detected for that given search period (which can be changed in code). Giving a search window to your sensor, makes it's working more efficient and there are better chances for you to get non-erroneous functioning.
I too did both codes and both worked fine for me. Here's a snap!
PIR motion sensor circuit
Demo
So that's an end to our tutorial  for this time. Hope you enjoyed reading. If you liked this tutorial then don't forget it to share with your friends. I'll be back with more..... till then #happyDIYing

If you have any question or query or feedback regarding this tutorial then leave a comment below and we will solve those as soon as possible.

Be sure to buy the stuff mentioned in this blog by clicking on the link below-
http://www.ebay.in/usr/4d_innovations?_trksid=p2053788.m1543.l2754

The vendor's offering interesting and working hardware at quite handy rates. Go give it a try! :)
 
 
Shoping to Components Link :


 

Comments

Popular posts from this blog

Arduino NANO 3X3X3 LED CUBE

DIY | 3X3X3 LED CUBE FOR ARDUINO NANO+ By   RGBFreak   in   Technology Arduino 17,143 146 22 Featured Download Favorite By   RGBFreak RGBFreak's YouTube Channel Follow More by the author: About: Hi there visitor! First of all thank you for checking out my profile! My name is Youri. I study Technical Computer Science in the Netherlands. I especially love the electronical part of my study. Since I l...   More About RGBFreak » Intro: DIY | 3x3x3 LED Cube for Arduino Nano+ Hi everyone! My name is RGBFreak and I created a YouTube channel quite recently. I love DIY and I especially love LED's, so that's why I decided to make my own 3x3x3 LED Cube! You will need the following items to make this LED Cube: • 27 single colored LED's. • Arduino Nano or one of his bigger brothers. • 3 NPN Transistors. I used the BC547. • 3 pin headers with 3 pins. • 1 pin header with 4 pins. • A piece of perfboard. • A few small cables. Ad

Ultrasonic Distance Sensor in Arduino With Tinkercad

  Ultrasonic Distance Sensor in Arduino With Tinkercad Let's measure distances with an ultrasonic rangefinder (distance sensor) and Arduino's digital input. We'll connect up a circuit using a breadboard and use some simple Arduino code to control a single LED. You may have already learned to   read a pushbutton   and   PIR motion sensor   with Arduino's digital input, and we'll build on those skills in this lesson. Ultrasonic rangefinders use sound waves to bounce off objects in front of them, much like bats using echolocation to sense their environment. The proximity sensor sends out a signal and measures how long it takes to return. The Arduino program receives this information and calculates the distance between the sensor and object. Find this circuit on Tinkercad Explore the sample circuit embedded here by starting the simulation and clicking on the proximity sensor. This will activate a highlighted area in front of the sensor with a circle "

DIGITAL UV-METER, WITH OLED DISPLAY. ARDUINO PROJECT FOR BEGINNERS

DIGITAL UV-METER, WITH OLED DISPLAY. ARDUINO PROJECT FOR BEGINNERS By   techn0man1ac   in   Technology Arduino 4,792 87 13 Featured Download Favorite By   techn0man1ac Techn0man1ac blog Follow About: Techn0man1ac - техноманьяк   More About techn0man1ac » Intro: Digital UV-meter, With OLED Display. Arduino Project for Beginners Video demonstration (English subtitles). Hello,   instructable . Today I will tell you how to make a simple digital VU meter (sound level meter) using Arduino and OLED displays and 2 resistors by yourself (DIY). The device is quite simple, for beginners it will be a rewarding experience. Add Tip Ask Question Comment Download Step 1: Components for This Arduino Project: 3 More Images Arduino Nano V3.0; 0.96 inch IIC I2C 128X64 OLED Display; One 10K, resistor(R1 no scheme); One 10K-100K potentiometer(R2no scheme); Wires. Add Tip Ask Question Comment Download Step 2: Dev