Guide for PIR Motion Sensor with Arduino

PIR or Passive Infrared Sensors help you to sense motion. They consume less power, easy to use and inexpensive. They are made up of a pyroelectric sensor ( which is visible as the round metal can with a rectangular crystal in the center ) which can detect levels of infrared radiation.



  • Infrared Radiation : Exists in the electromagnetic spectrum at a wavelength that is longer than visible light. Objects that generate heat also generate infrared radiation which cannot be seen but can be detected.


  • Fresnel Lens : White Ball which allows efficient light condensing giving a larger range of IR to the sensor.


  • Pyroelectric Sensor : The pyroelectric sensor is made up of crystalline material that generates a surface electric charge when exposed to heat in the form of infrared radiation. When the amount of radiation striking the crystal changes, the amount of charge also changes and can be measured with a sensitive FET device built into the sensor.


  • Pyroelectricity : It is the ability of certain materials to generate a temporary voltage when they are heated or cooled.

How does it work ?

It uses the radiated temperature of every object it sees in the infrared spectrum. It records the area in front looks and then compares everything to it.

Parts Required

  1. 1 x Arduino UNO
  2. 1 x PIR Sensor
  3. Jumper Wires
  4. 1 x Breadboard

Pin Wiring

   Sensor Pin       Arduino Pin
      VCC                5V
      GND                GND
     Output             Pin 2


A really simple Fritzing connection :




// Modified by Saumitra Kapoor based on PIR Sensor by Limor Fried
int led= 13; //LED connected to pin 13 
int sensepin= 2; // Arduino Pin connected to OUT of PIR
int state=LOW; // Assuming No motion initally
int value= 0; // Variable which stores status of the sensor

void setup() // Executed once
    pinMode(led,OUTPUT); // LED as output
    pinMode(sensepin, INPUT); // Sensor as input
    Serial.begin(9600); // Baud Rate : Characters/sec. In this case, bits/sec

void loop()
    value= digitalRead(sensepin); // Read PIR value
    if( value == HIGH)
         digitalWrite(led, HIGH); // Turn LED on
         delay(100); // Delay of 100 milliseconds
         if( state == LOW)
            Serial.println("Motion!"); // Motion detected
            state = HIGH; // Flipping state to HIGH
          digitalWrite(led, LOW); // Turn LED off
          delay(250); // Delay of 250 milliseconds
          if( state == HIGH)
            Serial.println("Motion Stopped");
            state= LOW; // State flipped back to LOW

Final Thoughts

The PIR Sensor requires a ‘warm-up’ time in order to function properly. This is due to the settling time involved in ‘learning’ its environment. This could be anywhere from 10-60 seconds. During this time there should be as little motion as possible in the sensors field of view.

I hope you found the guide useful. Let me know your project ideas by dropping a comment below.

Saumitra Kapoor

Leave a Reply