HomeLinuxPIR Sensor HC-SR501 Arduino Nano Tutorial – Step by Step Instruction

PIR Sensor HC-SR501 Arduino Nano Tutorial – Step by Step Instruction


Arduino Nano is a compact microcontroller-based board. It could course of a number of directions and might generate desired responses. Utilizing Arduino Nano GPIO pins a variety of sensors could be interfaced. One of many sensors consists of the PIR (HC-SR501). This text will cowl interfacing of PIR sensor with Arduino Nano board.

Introduction to PIR Movement Sensor (HC-SR501)

A PIR movement sensor, also referred to as a Passive Infrared Sensor, is a kind of digital system that’s generally used to detect the presence of a human or animal inside a sure vary. The HC-SR501 is a well-liked mannequin of PIR movement sensor that’s recognized for its reliability and ease of use.

It really works by utilizing a passive infrared detector to sense modifications in temperature, which could be brought on by the motion of an individual or animal. If the item motion is detected, a sign is shipped to gadgets comparable to a safety system or a lighting management panel. PIR movement sensors are sometimes utilized in house safety techniques, automated lighting techniques, and different purposes the place you will need to detect the presence of an individual or animal.

Working of PIR Movement Sensor (HC-SR501)

The HC-SR501 PIR movement sensor works by utilizing a passive infrared detector to sense modifications in temperature. It’s designed to detect the presence of a human or animal inside a sure vary, sometimes as much as about 8 meters (26 ft).

When the sensor is idle, it’s always monitoring the temperature in its subject of view. If the sensor detects a change in temperature, comparable to could be brought on by the motion of an individual or animal, it’s going to ship a sign to a linked system. Utilizing this sign, we are able to generate responses comparable to turning ON a light-weight or activating an alarm.

The PIR movement sensor has two potentiometers on board that can be utilized to regulate the sensitivity and Time delay of the sensor.

  • Sensitivity determines how a lot of a temperature change is required to set off a PIR sensor. It may be set relying upon movement we have to detect comparable to mouse or leaf motion.
  • Time delay determines how lengthy the sensor stays energetic after detecting a change in temperature.

Pinout HC-SR501

PIR sensor pin consists of:

  • VCC: That is the facility pin of the PIR sensor. Join it to a 5V energy supply.
  • GND: That is the bottom pin. Join it to the GND or unfavourable terminal of the facility supply.
  • OUT: That is the output pin. It sends a digital sign to a linked system when the sensor detects motion.
  • Regulate Delay: That is the sensitivity adjustment pin. Utilizing this sensitivity of the sensor could be adjusted.
  • Regulate Sensitivity: That is the time delay adjustment pin. It may be used to regulate the size of time that the sensor stays energetic after detecting a change in temperature.

PIR HC-SR501 has 3 output pins. Two pins VCC and GND are energy pins whereas the center or third pin is for output digital set off sign.

Interfacing PIR Movement Sensor (HC-SR501) With Arduino Nano

Interfacing a PIR movement sensor, such because the HC-SR501, with an Arduino Nano microcontroller is a simple course of that may be achieved with only a few parts. To start, join the VCC and GND pins on the PIR sensor to the 5V/VIN and GND pins on the Arduino Nano, respectively. Subsequent, join the OUT pin on the PIR sensor to any digital enter pin on the Arduino Nano.

As soon as these connections have been made, you need to use the Arduino Nano to learn the digital output of the PIR sensor and carry out a desired motion, comparable to turning on an LED or sending a notification. You will need to word that the PIR movement sensor could require a small quantity of calibration in an effort to operate correctly. This will sometimes be accomplished by adjusting the sensitivity and time delay settings utilizing the onboard potentiometers.

Required parts are:

  • Arduino Nano
  • PIR movement sensor (HC-SR501)
  • LED
  • 220 Ohm resistor
  • Connecting wires
  • Breadboard

Schematic
Given picture present wiring diagram of PIR sensor with Arduino Nano board:

Code
Open IDE (Built-in Growth Atmosphere). Choose Nano board and click on the add button after writing the under code.

int LED_PIN = 3; /*Pin outlined for LED*/
int PIR_Sensor_Pin = 5; /*Pin for PIR sensor*/
int pirState = true; /*Assuming no movement is detected*/
int val = 0; /*variable to retailer pin standing*/
int minimummSecsLowForInactive = 2000; /*Assume no movement detected if no exercise is detected for 2 sec*/
lengthy unsigned int timeLow;
boolean takeLowTime;
int calibrationTime = 10; /*time for sensor calibration based on datasheet*/
void setup() {
pinMode(LED_PIN, OUTPUT); /*LED declared as Output*/
pinMode(PIR_Sensor_Pin, INPUT); /*Sensor pin detected as Enter*/
Serial.start(9600);
Serial.print(“calibrating sensor “);
for(int i = 0; i < calibrationTime; i++){
Serial.print(“.”);
delay(1000);
}
Serial.println(” accomplished”);
Serial.println(“SENSOR ACTIVE”);
delay(50);
}
void loop(){
val = digitalRead(PIR_Sensor_Pin); /*Learn sensor worth*/
if (val == HIGH) { /*if situation to examine for the Enter state*/
digitalWrite(LED_PIN, HIGH); /*if acquired worth is HIGH LED ON*/
if (pirState) {
pirState = false;
Serial.println(“Movement detected!”); /*Print if movement is detected*/
delay(50);
}
takeLowTime = true;
}
else {
digitalWrite(LED_PIN, LOW); /*Flip OFF LED*/
if (takeLowTime){
timeLow = millis();
takeLowTime = false;
}
if(!pirState && millis() – timeLow > minimummSecsLowForInactive){
pirState = true;
Serial.println(“Movement ended!”);
delay(50);
 }  
   }
     }

Code began by defining the enter pin for PIR sensor and output pin for LED. An int variable val is outlined. This variable will retailer the state of the PIR output pin.

Subsequent, utilizing the pinMode operate, the LED and sensor pin are outlined as output and enter respectively. A if situation is used. If the Arduino Nano receives HIGH enter from the sensor LED will flip ON. Equally, if no movement is detected a LOW sign might be despatched to Arduino leading to turning the LED OFF.

Output
Beneath output might be displayed as soon as movement is detected by the PIR sensor. First sensor will calibrate itself after that it will possibly detect any movement.

{Hardware}
The LED is OFF as a result of no movement is detected.

Now the automobile is transferring and the LED is turned ON as movement is detected.

Conclusion

Arduino Nano could be interfaced with totally different sensors comparable to PIR. Utilizing this sensor any object movement could be detected. The PIR sensor with Arduino has a number of purposes comparable to house safety techniques or avenue lighting. This text covers the whole Arduino code and steps concerned in detecting object motion.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments