PIR sensor arduino

What is a PIR sensor and how to you use it?

Posted on

How to use it – PIR sensor (Passfive InfraRed Sensor) is a sensor that can detect the movement of humans and animals. This sensor works by detecting changes in electromagnetic radiation emitted by the body. All objects emit electromagnetic radiation. Surface temperature, area and characteristics of objects will affect electromagnetic wavelengths. When the body moves, electromagnetic radiation also changes. This change in electromagnetic radiation is detected by pyroelectric elements in the PIR sensor. More about PIR Senor please click here.

 

PIR sensor arduino
Image edited from grabcad.com

 

With certain angles, the radiation received by the Fresnel lens will be focused on the pyroelectric. For more details, please click here.

The pin sensor has three pins:
– VCC for power (+)
– GND for power (-)
– OUT for sensor output data results

Work principle

The module we use here is HC-SR501 where this sensor will issue HIGH logic or 5 volt voltage when it detects human movement. When not detecting movement, this sensor will issue LOW logic or 0V voltage.

Schematic

For the basic circuit, please follow the following picture.

Schematic pir arduino

Basic Program

This program has a simple principle. Pin 2  of Arduino is used as an input to accept the logic voltage from the sensor. When the sensor detects movement, the OUT pin of this sensor will issue HIGH logic or 5 volt. When pin 2 accepts this HIGH logic, Arduino will send the word “HIGH” to Serial Monitor. But, if pin 2 accepts LOW logic or 0 volt, then Arduino sends the word “LOW” to the serial monitor.

// hamboelektronik.com //

int pinSensor = 2;
int val = 0;

void setup() {
 Serial.begin(9600);
 pinMode(pinSensor, INPUT);
}

void loop() {
  val = digitalRead(pinSensor);
  
  if (val == HIGH){
    Serial.println("HIGH");
  }
  else Serial.println("LOW");

  delay(100);

}

 

Program to Turn on LEDs

In this program principle is if pin 2 accepts HIGH logic, Arduino will give HIGH logic on pin 13, when connected to the LED. Then the LED will turn on. If pin 2 accepts the LOW logic, Arduino will give LOW logic to pin 13 so that the LED will turn off.

// hamboelektronik.com //

int pinSensor = 2;
int val = 0;
int led = 13;

void setup() {
 pinMode(pinSensor, INPUT);
 pinMode(led, OUTPUT);
}

void loop() {
  val = digitalRead(pinSensor);
  
  if (val == HIGH){
    digitalWrite(led, HIGH);
  }
  else digitalWrite(led, LOW);

  delay(3000);

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *