INTERFACING HC-SR501 PIR HUMAN MOTION DETECTOR SENSOR WITH ARDUINO UNO R3

INTERFACING HC-SR501 PIR HUMAN MOTION DETECTOR SENSOR WITH ARDUINO UNO R3

Introduction

The PIR sensor stands for the Passive Infrared sensor. It is a low-cost sensor which can detect the presence of Human beings or animals. This sensor has three output pins VCC, Output, and Ground as shown in the pin diagram above. Since the output pin is 3.3V TTL logic it can be used with any platforms like Arduino, Raspberry, PIC, ARM, 8051 etc.

The module can be powered from voltage 4.5V to 20V but, typically 5V is used. Once the module is powered allow the module to calibrate itself for a few minutes, 2 minutes is a well-settled time. Then observe the output on the output pin. Before we analyze the output we need to know that there are two operating modes in this sensor such as Repeatable (H) and Non- Repeatable (L) and mode. The Repeatable mode is the default mode.

The output of the sensor can be set by shorting any two pins on the left of the module as shown below. You can also notice two orange color potentiometers that can be used to set the sensitivity and time which will be explained further below.

Repeatable (H) mode

In Repeatable (H) mode the output pin D out will go high (3.3V) when a person is detected within range and goes low after a particular time (time is set by “Off time control” potentiometer). In this mode, the output pin will go high irrespective of whether the person is still present inside the range or has left the area. The sensitivity can be set using the “sensitivity control” potentiometer

Non- Repeatable (L) mode

In “I” mode the output pin D out will go high (3.3V) when a person is detected within range and will stay high as long as he/she stays within the limit of the Sensors range. Once the person has left the area the pin will go low after the particular time which can be set using the potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer

 

Inputs

Pin Number

Pin Name

Description

1

Vcc

Input voltage is +5V for typical applications. Can range from 4.5V- 12V

2

High/Low Output (D out)

Digital pulse high (3.3V) when triggered (motion detected) digital low(0V) when idle(no motion detected

3

Ground

Connected to the ground of a circuit

.                                     

 

Components Required:

·        Arduino UNO

·        PIR Sensor

·        Buzzer

·        LED

·        Bread Board

·        Jumper Wires

Circuit Diagram:

 

 

 

 

 

 

 

 

 

 

 

 

 

Connections:

·  The Vcc pin of the Arduino board is connected with VCC of PIR Sensor.

·  Pin 2 of Arduino board is connected with D out of PIR Sensor.

·  Pin 3 of the Arduino board is connected with the +ve terminal of the buzzer.

·  Pin 4 of the Arduino Board is connected with +ve of the LED.

·  The GND pin of the Arduino board is connected with the Ground of PIR Sensor.

 

Arduino Code:

// Interfacing PIR Sensor with Arduino

int pir=2;            //initialize Sensor

int led= 3;          //initialize LED

int buzzer= 2;    //initialize Buzzer

int pirvalue=0;   //initialize sensor value

 

void setup() {

pinMode (buzzer, OUTPUT);   //defining Buzzer as output

pinMode (led, OUTPUT);         //defining Led as output

pinMode (pir, INPUT);      //defining PIR as Input

Serial.begin(9600);           //start Serial Monitor

digitalWrite (pir,LOW);     //wait for sensor calibration

delay(1000);                     //delay 1000 miliseconds

}

void loop() {

pirvalue=digitalRead(pir);      //saving input values in pin value

Serial.println(pirvalue);          //print value on serial monitor

delay(200);                            //delay 200 miliseconds

if (pirvalue==HIGH);             //if input value is high

{

digitalWrite(led, HIGH);         //turn on LED

digitalWrite(buzzer, HIGH);  //turn on buzzer

}

}

Result of project: