How To Interface PIR Sensor With Arduino

By
Advertisement
Hello Arduinians... 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! :)

14 comments:

  1. Thanks..really appreciate your support!

    ReplyDelete
    Replies
    1. Himanshu,

      Your Welcome. If you have any query than let me know

      Delete
    2. Thanks a ton!
      I'm on for some more....

      Delete
    3. Ya sure

      Let me know what do you want to do.. :)

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi Himanshu,Thanks for sharing cool idea of Arduino Project. "Cool Post, Interesting.. There are lot of Arduino Micro controller Projects where you can take ideas for Final Year submission. Engineers Garage is also the website which is only for Electronics and Electrical Engineers. Where students can find various Projects ideas and tutorials on Micro controller, Electric Circuits and more. This is the good platform where you can post your projects. Its a very good portal for Electronics Projects for final year students. Visit : Engineers Garage

    ReplyDelete
  4. I really like your blog and I also recommend you to check out Occupancy. Thank you

    ReplyDelete
  5. This is really interesting blog on PIR Sensor in Mumbai, You are a very skilled blogger. I've joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your web site in my social networks! Thank You!!!

    ReplyDelete
  6. I really love it and amazing information in this blog. it's really good and great information well done. PIR Sensor in Bengaluru.

    ReplyDelete
  7. Thank you for posting this excellent information..it is very useful to me..!
    Click here:
    Motion Sensor in Delhi

    ReplyDelete
  8. Quite useful for electronics beginners. PIR sensor is commonly used in many security and intrusion detection systems and you have explained quite well interfacing it with Arduino Uno. Thanks

    ReplyDelete
  9. Really great article, Glad to read the article. It is very informative for us. Thanks for posting.

    MLSU BA 1st Year Result

    ReplyDelete