Let’s talk about PIR motion sensor with Arduino, a very useful sensor for detecting people and animals via infrared. PIR stands for “passive infrared”, which is how the sensor works. That is, only by receiving infrared radiation from the human body or larger animals (depending on the adjusted sensitivity).
The sensor we are going to use is in the image below. Note the time (on time) and distance (in meters) adjustment potentiometers.
The way the module works is simple: when it detects a presence, the output goes to a high level (5V) for the time set on the potentiometer, otherwise it remains at a low level (0V).
The code also ends up being simple, as can be seen below. Pin 2 is defined as the sensor input and pin 13 (Arduino onboard LED) as the output indicator. I check how digital input 2 is, if it is at a high level I turn on output 13. If it is at a low level, I turn off output 13.
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2)){
digitalWrite(13, HIGH);
}else{
digitalWrite(13, LOW);
}
}
I made a video of the sensor’s operation, observe the behavior of the red LED connected to pin 13. After it no longer detects the presence of my hand, it still stays on for about 2 seconds.
Final words
Although there are other ways of detecting human and animal bodies, PIR sensors are still widely used in the most diverse areas. In the future I will bring an article to the blog about microwave presence sensors.
Speaking of sensors, also see this article about the DHT11 temperature sensor. Want to buy the PIR sensor used in this article? use my affiliate link here.
Leave a Reply