PIR Sensors Guide with Arduino Programming for motion detection

Overview of PIR Sensor

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.

Grid Eye Illusion
Grid eye illusion


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

PIR Sensor Block Diagram
PIR Sensor Blocks


PIR Element
PIR Element


  • 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.
PIR Sensing
  • 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.
PIR Sensor Slots Output

Differential changes between two slots

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


PIR Sensor Pinout

This Picture Shows PIR Sensor Pin Description
Pin Diagram of PIR Sensor


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

PIR Single Trigger Mode
Single trigger mode timing diagram


  • 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

PIR Repeat Trigger Mode
Repeat trigger mode timing diagram


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



PIR Detector With Lens
PIR Detector with Fresnel 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

This Picture Shows pir sensor circuit diagram
PIR Sensor Circuit Diagram



  • 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,

This gif show how pir sensor detect motion


Alternate options for PIR Sensor

  • PIR sensor HC-SR505
  • PIR sensor AM312
  • PIR Sensors EKMB1393111K


PIR Sensor interfacing with Arduino

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;

 Serial.begin(9600);  /* Define baud rate for serial communication */
  delay(20000);   /* Power On Warm Up Delay */

  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;
   Serial.print("No object in sight\n\n");
    Serial.print("Object detected\n\n");   
    warm_up = 1;


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.


To know more about PIR Sensor using Arduino refer to this link


Examples of PIR Sensor interfacing

  1. PIR Sensor Interfacing with PIC18F4550
  2. PIR Sensor Interfacing with ATmega16
  3. PIR Sensor Interfacing with 8051
  4. PIR Sensor Interfacing with Arduino
  5. PIR Sensor Interfacing with TI Launchpad
  6. PIR Sensor interfacing with NodeMCU
  7. PIR Sensor interfacing with ESP32
  8. PIR Sensor interfacing with ARM MBED

Components Used

PIR Sensor
PIR motion sensors sense the Infrared signal radiated from moving objects including human or animal body. It is generally used to detect the presence of human or animal motions.