What is a PIR sensor
HC SR501 Arduino PIR How to make the light turn on automatically – PIR (Passive Infra Red) sensor is a sensor capable of detecting Human “Movement”.
PIR sensor is a sensor that detects changes in infrared radiation originating from the movement of an objects. This sensor is basically work by Sensor Pyroelectric.
An pbjects or humans emit infrared radiation. When objects move, the radiation emitted will change. This radiation change is utilized by the PIR sensor and processes it into a signal.
This signal, we will be processed for certain needs, one of which is to indicate the presence of humans.
Where will the PIR sensor be used?
PIR sensors can be used in many applications, both at home, garden, office and others, such as:
- Auto light on
- AC turns on automatically
- Alarms for CCTV
- Ventilation Fan
- Anti-theft alarm
- etc
How the PIR Sensor HC SR501 works?
Many types and manufacturers produce PIR sensors, such as Panasonic, Adafruit, Kemet, Murata, Parallax, Seed Technology, Sparkfun, Zilog and others.
When we talk about sensors, we are actually talking about one main component of the detector. But if we talk about the HC SR501 PIR sensor, we are actually talking about the HC SR501 sensor module.
What is a module?
The module is an electronic board that already consists of additional supporting components, from the main component.
The PIR sensor (main component) only detects changes in infrared temperature and emits a very small electrical signal.
This electrical signal must be amplified so that we can use it in the next stage. One component of this signal amplifier is IC BISS0001.
BISS0001 is an IC that is used specifically to read the output signal from the PIR sensor and convert it into a signal that can be used by other components such as microcontrollers.
Some of the features of the BISS0001 IC are:
- Low Power CMOS chip (suitable for using battery)
- CMOS chip with high input impedance operational amplifier
- Can detect two-way level / resistant to noise (interference)
- Built-in Power up disable & output pulse control logic
- Dual mode: triggerable & non-triggerable.
How does the HC SR501 PIR sensor work?
Inside the PIR SR501 module there are several additional components, like Fresnel lens, Sensor, IC BISS001, sensitivity settings, time delay settings, jumper triggers, safety diodes, 3.3V regulators.
Procedure:
Infrared radiation emitted by an object will hit the Fresnel Lens. The Fresnel lens will transmit and focus the infrared radiation to the Pyroelectric Sensor.
Pyroelectric sensor will issue a small signal and received and processed by IC BISS0001. The output of signal processing will be influenced by the Sensitivity Potentiometer, Delay and Jumper Trigger.
Sensitivity is the module’s ability to detect movement. The higher the sensitivity set on this potentiometer, the farther the distance that can be detected. This module can detect a maximum of about 7 meters.
Delay is the lag time of signaling the output with a logic HIGH. If the lag time is set low, the minimum time is about 3 seconds. If the lag time is set high, the maximum time is about 5 minutes.
Arduino HC SR501 PIR Circuit
The SR501 module is a very easy to use module. This module only has 3 pins, 2 of them as power (VCC GND) and 1 as output signal. For the circuit is as follows.
In this circuit, I use Pin 2 as the data receiving pin, but you can use other pins.
Arduino SR501 PIR Program
a. Motion Detect
The PIR sensor will issue a HIGH voltage when it detects movement and vice versa. Here is a program (some of comment in Indonesian) to display notifications to the Serial Monitor and internal LED when there is movement or not.
/*
Motion Sensor - https://www.chippiko.com/
Basic code by https://learn.adafruit.com/
*/
int pinSensor = 2;
int pinLed = 13;
int statusSensor = LOW;
int value = 0;
void setup() {
Serial.begin(9600);
pinMode(pinLed, OUTPUT);
pinMode(pinSensor, INPUT);
}
void loop() {
value = digitalRead(pinSensor);
if (value == HIGH)
{
digitalWrite(pinLed, HIGH);
if (statusSensor == LOW) {
Serial.println("Detected!");
statusSensor = HIGH;
}
}
else
{
digitalWrite(pinLed, LOW);
if (statusSensor == HIGH) {
Serial.println("Not Detected!");
statusSensor = LOW;
}
}
}
b. Turn on the light when someone is in the room and turn it off when the person leaves the room
Now we will make a device that will turn on the light when the sensor detects the movement of people and will read the movement for a span of 4 minutes.
If within 4 minutes there is no movement at all, then the light will turn off.
The working principle is that when the sensor detects movement, the sensor will send HIGH logic to the microcontroller.
So, the microcontroller will count from 0 to 240 seconds with each addition of 0.25 seconds.
In 1 second, the microcontroller will read data from the sensor 4 times.
For example, the microcontroller gets HIGH data from the sensor while it is counting to 100 seconds, then the calculation value will return to 0.
From this, we can make the sensor will continue to turn on the light continuously and will turn off the light if in 4 minutes there is no movement at all.
This program uses Millis. To understand how Millis() works, go to here.
For best results, please turn the Sensitivity potentiometer at the highest value (full to the right) and delay at the lowest value (full to the left).
int minute = 4 * 60; //4 minute for max
const unsigned long numberLimit = 250; //every 250 ms do calculation
unsigned long previousMillis = 0;
unsigned long nowMillis = 0;
float toCount = 0;
int sensorPin1 = 10;
int sensorPin2 = 11;
int sensorPin3 = 12;
int condSensorPin1 = 0;
int condSensorPin2 = 0;
int condSensorPin3 = 0;
int lamp = 13;
void setup()
{
Serial.begin(9600);
Serial.println("Mulai");
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
pinMode(lamp, OUTPUT);
}
void loop()
{
//Get the millis value data
nowMillis = millis();
//get data from sensor
condSensorPin1 = digitalRead(sensorPin1);
condSensorPin2 = digitalRead(sensorPin2);
condSensorPin3 = digitalRead(sensorPin3);
//Send sensor value data to serial monitor
if (condSensorPin1 == HIGH) {Serial.println("Pin 10 HIGH");}
if (condSensorPin2 == HIGH) {Serial.println("Pin 11 HIGH");}
if (condSensorPin3 == HIGH) {Serial.println("Pin 12 HIGH");}
//If one of the sensors gives a HIGH signal, then turn on the light
if ((condSensorPin1 == HIGH) || (condSensorPin2 == HIGH) || (condSensorPin3 == HIGH))
{
digitalWrite(lamp, HIGH);
Serial.println("Lamp is Turn On");
toCount = 0;
}
//Count data every 250 milliseconds
if ((nowMillis - previousMillis) >= numberLimit)
{
toCount = toCount + .25;
Serial.print(toCount);
Serial.println(" Second");
previousMillis = nowMillis;
}
//If the calculated data has reached 4 minutes, then the light is turned off
if (toCount == minute)
{
digitalWrite(lamp, LOW);
Serial.println("Turn is Turn Off");
}
}
Download Datasheet BISS0001
Thank you for visiting Chip Piko website. May be this HC SR501 Arduino PIR article is useful.