Skip to content Skip to sidebar Skip to footer

HC SR501 Arduino PIR Turn On Automatically

HC SR501 Arduino PIR Turn On Automatically

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". 

1. What is a PIR sensor?

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.

2. 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

3. 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.

A.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:

  1. Low Power CMOS chip (suitable for using battery)
  2. CMOS chip with high input impedance operational amplifier
  3. Can detect two-way level / resistant to noise (interference)
  4. Built-in Power up disable & output pulse control logic
  5. Dual mode: triggerable & non-triggerable.

B. 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.
chip piko, pir arduino, hc sr501, sr501, pir sr501, hc 501, sr501 pir, rangkaian sensor pir dengan arduino, pir sensor sr501, sensor pir dengan arduino, sensor pir arduino uno, arduino uno pir, cara membuat sensor gerak dengan arduino, rangkaian pir arduino, rangkaian pir hc sr501, hc sr501 schematics, pir shcematics,
PIR HC SR501 Pin Out and Configuration

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.

4. 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.

chip piko, pir arduino, hc sr501, sr501, pir sr501, hc 501, sr501 pir, rangkaian sensor pir dengan arduino, pir sensor sr501, sensor pir dengan arduino, sensor pir arduino uno, arduino uno pir, cara membuat sensor gerak dengan arduino, rangkaian pir arduino, rangkaian pir hc sr501, hc sr501 schematics, pir shcematics,
PIR HC SR501 Arduino Uno

In this circuit, I use Pin 2 as the data receiving pin, but you can use other pins

5. 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 -
    Kode dasar edit dari

int pinSensor = 2;
int pinLed = 13;
int statusSensor = LOW;
int nilai = 0;

void setup() {
  pinMode(pinLed, OUTPUT);
  pinMode(pinSensor, INPUT);

void loop() {
  nilai = digitalRead(pinSensor);
  if (nilai == HIGH)
    digitalWrite(pinLed, HIGH);
    if (statusSensor == LOW) {

      statusSensor = HIGH;

    digitalWrite(pinLed, LOW);
    if (statusSensor == HIGH) {
      Serial.println("Tidak terdeteksi!");
      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 ketentuan = 4 * 60;               //Atur nilai maksimal 4 menit
const unsigned long batasAngka = 250; //Setiap 250 mili detik lakukan perhitungan
unsigned long millisSebelumnya = 0;   //Digunakan untuk millis
unsigned long millisSekarang = 0;     //Digunakan untuk millis
float penghitung = 0;                 

int sensorPin1 = 10;                  //Pin D10 untuk Sensor 1
int sensorPin2 = 11;                  //Pin D11 untuk Sensor 2
int sensorPin3 = 12;                  //Pin D12 untuk Sensor 3

int kondisiSensorPin1 = 0;            //Untuk menyimpan data HIGH/LOW dari Sensor 1
int kondisiSensorPin2 = 0;            //Untuk menyimpan data HIGH/LOW dari Sensor 1
int kondisiSensorPin3 = 0;            //Untuk menyimpan data HIGH/LOW dari Sensor 1

int lampu = 13;                       //Pin D13 Untuk Lampu/Relay

void setup()
  pinMode(sensorPin1, INPUT);         //Jadikan pin D10 sebagai input
  pinMode(sensorPin2, INPUT);         //Jadikan pin D11 sebagai input
  pinMode(sensorPin3, INPUT);         //Jadikan pin D12 sebagai input
  pinMode(lampu, OUTPUT);             //Jadikan pin D13 sebagai output

void loop()
  //Ambil data nilai millis
  millisSekarang = millis();              

  //Baca nilai dari sensor
  kondisiSensorPin1 = digitalRead(sensorPin1);
  kondisiSensorPin2 = digitalRead(sensorPin2);
  kondisiSensorPin3 = digitalRead(sensorPin3);
  //Kirim data nilai sensor ke serial monitor
  if (kondisiSensorPin1 == HIGH) {Serial.println("Pin 10 HIGH");}
  if (kondisiSensorPin2 == HIGH) {Serial.println("Pin 11 HIGH");}
  if (kondisiSensorPin3 == HIGH) {Serial.println("Pin 12 HIGH");}

  //Jika salah satu dari sensor memberikan sinyal HIGH, maka hidupkan lampu
  if ((kondisiSensorPin1 == HIGH) || (kondisiSensorPin2 == HIGH) || (kondisiSensorPin3 == HIGH)) 
    digitalWrite(lampu, HIGH);
    Serial.println("Lampu dihidupkan");
    penghitung = 0;

  //Hitung data setiap per 250 milidetik
  if ((millisSekarang - millisSebelumnya) >= batasAngka)
    penghitung = penghitung + .25; 
    Serial.println(" Detik");
    millisSebelumnya = millisSekarang;

  //Jika data yang dihitung telah sampai 4 menit, maka lampu dimatikan
  if (penghitung == ketentuan)
    digitalWrite(lampu, LOW);
    Serial.println("Lampu di matikan");

6. Download Datasheet BISS0001

Thank you for visiting Chip Piko website. May be useful.

Post a Comment for "HC SR501 Arduino PIR Turn On Automatically"