top of page

PIR Sensors Guide with Arduino Programming for motion detection

Updated: Mar 4


Overview of PIR Sensor




All living objects, whose body temperature is more than 0°C, emit the heat in form of infrared radiation through their body, also called as thermal radiations. This Radiated energy is invisible to human eye. These Signals can be detected by using PIR sensor which is specially designed for such purpose.




PIR sensor i.e. Passive Infrared Sensor, passive word indicates PIR Sensor does not generate or radiate any energy for detection purposes.


PIR Sensors don't detect or measure "HEAT"; they detect the infrared radiation emitted or reflected from objects.


They are small, inexpensive, low power and easy to use. They are commonly found at home, medical, factories etc. areas.

 

Specification of PIR Sensor

  • Detection range: up to 7 meters

  • Detection angle: 110 degrees

  • Operating voltage: DC 4.5V - 12V DC

  • Output signal: 3.3V digital output

  • Delay time: adjustable from 0.3 seconds to 5 minutes

  • Operating temperature: -15°C to +70°C

  • Sensitivity: Adjustable

 

How PIR Sensor Work







  • PIRs are basically made of a pyroelectric sensor, which can detect levels of infrared radiation.

  • Above figure of PIR element shows the round metal can with a rectangular crystal in the centre.

  • Every object emits some low-level radiation, and the hotter objects emits more radiations.



  • The sensor is split in two slots, which are wired up so that they cancel each other out.

  • If one half sees more or less IR radiation than the other, the output will swing high or low.

  • Input signals from both terminals of PIR element are amplified using amplifier circuit and compared using comparator circuit.

  • The PIR element is covered by lens to increase range of operation.

At Idle Position 


  • PIR motion sensor uses element RE200B for infrared detection. Both slots of this sensor are connected to differential amplifier.

  • When the sensor is idle, both slots detect same amount of IR.

  • So, there is no error signal between differential inputs. The output of comparator circuit is zero.

Object in Motion


  • When any warm object passes in front of the sensor, it intercepts one slot of the PIR sensor. This causes a positive differential change between the two slots. This change is indicated by Part A in below figure.

  • When the warm body leaves the sensing area, the sensor generates negative differential change. This change is indicated by Part B in below figure.



Differential changes between two slots


  • Both these changes in pulse are the detection of warm body which radiate infrared signals.

 

PIR Sensor Pinout



PIR Sensor Pin Description


Pin 1 – GND


We have to connect this pin to Ground.

Pin 2 – Output


This pin gives output (3.5V) when the motion is detected.

Pin 3 – VCC


This pin provides supply voltage(+5v) to PIR element and internal circuit.

 

Modes of Operations


This sensor has two modes of operations:


1. Single Trigger Mode




  • To select Single Trigger mode, the jumper setting on PIR sensor must be set on LOW.

  • In case of Single Triggered Mode, Output goes HIGH when motion is detected.

  • After specific delay (tsel) the output goes to LOW even if the object is in motion.

  • The output is LOW for some time and again goes HIGH if object remains in motion.

  • This delay (tsel) is provided by user using the potentiometer. This potentiometer is on board of PIR sensor module.

  • In this way, the PIR sensor gives HIGH/LOW pulses if object is in continuous motion.

2. Repeat Trigger Mode



  • To select Repeat Trigger mode, the jumper setting on PIR sensor must be set on HIGH.

  • In case of Repeat Triggered Mode, Output goes HIGH when motion is detected.

  • The output of PIR sensor is HIGH until the object is in motion.

  • When object stops motion, or disappears from the sensor area, the PIR continues its HIGH state up to some specified delay (tsel).

  • We can provide this delay (tsel) by adjusting the potentiometer. This potentiometer is on board of PIR sensor module.

  • In this way, the PIR sensor gives HIGH pulse if object is in continuous motion.

 

Changing Sensitivity and Delay time 


  • There are two potentiometers on PIR motion sensors board: Sensitivity Adjust and Time delay adjust.

  • It is possible to make PIR more sensitive or Non-Sensitive Enough. The maximum sensitivity can be achieved up to 6 meters.

  • Time Delay Adjust potentiometer is used to adjust the timetsel shown in above timing diagrams.

  • Clockwise Movement makes PIR more Sensitive.

 

Lenses





  • Two things are important while manufacturing PIR sensor: Low cost and High Sensitivity.

  • Both these things can be magically achieved by using Lens cap.

  • The lenses increase range of operation; increases sensitivity and change pattern of Sensing vary easily.

 

PIR Sensor Circuit Diagram


 

Note: PIR sensor: Never keep PIR Sensor close to the Wi-Fi antenna, ESP32, or NodeMCU.PIR (Passive Infrared) sensor close to a WiFi antenna impacts the sensor's performance.PIR sensors detect changes in infrared radiation for motion detection.WiFi signals emit electromagnetic radiation that can interfere with the PIR sensor. Which causes false detection.So always keep the PIR sensor and WiFi antenna as far apart as possible.Also, you can try to shield the PIR sensor from the WiFi signal. This can be done by using metal shields or Faraday cages around the PIR sensor.

 

Now whenever PIR detect motion, the LED will glow else it will remain OFF which is shown below,



 

Alternate options for PIR Sensor

  • PIR sensor HC-SR505

  • PIR sensor AM312

  • PIR Sensors EKMB1393111K

 

PIR Sensor interfacing with Arduino





PIR Sensor Code for Arduino


const int PIR_SENSOR_OUTPUT_PIN = 4;     /* PIR sensor O/P pin */
int warm_up;

voidsetup(){
  pinMode(PIR_SENSOR_OUTPUT_PIN, INPUT);
 Serial.begin(9600);  /* Define baud rate for serial communication */
  delay(20000);   /* Power On Warm Up Delay */
}

voidloop(){
  int sensor_output;
 sensor_output = digitalRead(PIR_SENSOR_OUTPUT_PIN);
  if( sensor_output == LOW )
  {
    if( warm_up == 1 )
     {
     Serial.print("Warming Up\n\n");
      warm_up = 0;
      delay(2000);
    }
   Serial.print("No object in sight\n\n");
    delay(1000);
  }
  else
  {
    Serial.print("Object detected\n\n");   
    warm_up = 1;
    delay(1000);
  } 
}

 

The output of the code will depend on the input detected by the PIR sensor connected to pin 4 of the microcontroller.


When there is no motion detected by the sensor, the program will print "No object in sight" every second. However, for the first 2 seconds after the program starts, it will print "Warming Up" once to indicate that the PIR sensor is warming up and not yet fully functional.


When motion is detected by the sensor, the program will print "Object detected" once and then continue to print "No object in sight" every second until the sensor no longer detects motion. The program will then go back to waiting for motion detection.

 

 

Examples of PIR Sensor interfacing


 

2 views0 comments

Comments


bottom of page