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!
Components Required For This Tutorials
- 1 * Arduino Board
- 1 * PIR Motion Sensor(you can buy from here)
- Breadboard
- Jumper wires
- 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 |
PIR Motion Sensor
|
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!
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.
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! :)
Thanks..really appreciate your support!
ReplyDeleteHimanshu,
DeleteYour Welcome. If you have any query than let me know
Thanks a ton!
DeleteI'm on for some more....
Ya sure
DeleteLet me know what do you want to do.. :)
This comment has been removed by the author.
ReplyDeleteFree Study
ReplyDeletetcp ip reference model
Peephole Optimization
software hierarchy
bully algorithm
rad model
security of digital signature
ReplyDeletevariable proportions law assumptions
different loading schemes
phases language processor
regular expression regular definition cd
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
ReplyDeleteI really like your blog and I also recommend you to check out Occupancy. Thank you
ReplyDeleteThis 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!!!
ReplyDeleteI really love it and amazing information in this blog. it's really good and great information well done. PIR Sensor in Bengaluru.
ReplyDeleteThank you for posting this excellent information..it is very useful to me..!
ReplyDeleteClick here:
Motion Sensor in Delhi
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
ReplyDeleteReally great article, Glad to read the article. It is very informative for us. Thanks for posting.
ReplyDeleteMLSU BA 1st Year Result