HC-SR501 PIR Sensor With Arduino

by Rachana Jain in Circuits > Arduino

164 Views, 2 Favorites, 0 Comments

HC-SR501 PIR Sensor With Arduino

How to connect PIR Sensor with Arduino

A PIR sensor (Passive Infrared Sensor), also known as a Pyroelectric or PIR motion sensor, is used to detect motion and the presence of a subject within its field of view. These sensors are widely used in security alarm systems, automatic doors, and lighting automation.

The HC-SR501 is a popular and easy-to-use PIR motion sensor that can be interfaced with an Arduino. In this tutorial, we will explore how the HC-SR501 sensor works and how to connect and use it with an Arduino to detect motion.

Supplies

  1. Arduino UNO R3
  2. 16 x 2 LCD
  3. 10 kΩ Potentiometer
  4. 220 Ω Resistance
  5. Full Size Bread board
  6. HC-SR501 PIR Sensor
  7. Connecting Wires

How Does a PIR Sensor Work?

Working of PIR sensor.jpg
PIR sensor Module Top View.jpg

The PIR sensor operates by detecting infrared (IR) radiation emitted by objects. Every object with a temperature above absolute zero (-273°C) emits IR radiation. Human bodies, due to body heat, emit detectable levels of infrared radiation.

Unlike active sensors, PIR sensors do not emit any radiation; they only detect infrared radiation from their surroundings.

Key Components of a PIR Sensor

  1. Pyroelectric Sensor: This is the core component that senses changes in infrared radiation levels. When a warm object like a human body enters or moves within its detection range, the sensor detects the change in IR radiation.
  2. Fresnel Lens: This lens focuses infrared rays onto the pyroelectric sensor and increases the sensor’s coverage area. It plays a crucial role in improving detection range and sensitivity.

HC-SR501 PIR Motion Sensor Module Pinout

HC-SR501 PIR Motion Sensor Module Pinout Diagram.jpg

The HC-SR501 PIR sensor module features three pins for connection:

VCC: This pin is used to supply power to the sensor. It accepts an input voltage ranging from 4.5V to 12V, though it is most commonly powered with a 5V source.

GND: This is the ground pin and should be connected to the ground (0V) of the power supply.

OUT: This is the output pin of the sensor. It delivers a digital signal that indicates motion detection. When motion is detected, the pin outputs a HIGH signal (typically 3.3V or 5V). If no motion is detected, the output remains LOW (0V).

Wiring HC-SR501 PIR Sensor to Arduino

Interfacing HC-SR501 PIR Sensor to an Arduino.jpg
WhatsApp Image 2024-05-31 at 8.12.01 AM (1).jpeg
WhatsApp Image 2024-05-31 at 8.12.01 AM.jpeg

Now, let’s learn how to interface the HC-SR501 PIR motion sensor with an Arduino UNO microcontroller.

As shown in the wiring diagram below, connecting the PIR sensor to the Arduino is quite simple. The sensor’s output pin is connected to digital pin 2 of the Arduino. Additionally, a 16×2 LCD display is connected to show messages indicating whether motion is detected or no motion is present.

Code

Upload the following code:

/*
How to Interface HC-SR501 PIR Sensor with Arduino
by www.playwithcircuit.com
*/
#include <LiquidCrystal.h> // We are using JHD 16x2 alphanumeric LCD using HD44780 controller for its controller
LiquidCrystal lcd(12, 11, 6,7,8,9);
int sensorInput = 2; // Output for PIR sensor input for controller
int sersorReturn=0;
void setup() {
pinMode(sensorInput, INPUT); // declare sensor pin as input pin
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// set the cursor to (column = 0,row = 0)
lcd.setCursor(0, 0);
lcd.print("PIR Sensor Says:");
// set the cursor to (column = 0,row = 1)
lcd.setCursor(0, 1);
}
void loop() {
sersorReturn = digitalRead(sensorInput); // read input value
if(sersorReturn == HIGH)
{
// set the cursor to (column = 0,row = 1)
lcd.setCursor(0, 1);
lcd.print("Motion Occurs");
}
else
{
// set the cursor to (column = 0,row = 1)
lcd.setCursor(0, 1);
lcd.print("Motion Stops ");
}
}


To learn more checkout: How to Interface HC-SR501 PIR Sensor with Arduino