How to Use a PIR Sensor with Arduino

The main aim of this tutorial is to teach you how to use a HC-SR501 PIR sensor with Arduino. To effectively use the sensor with Arduino, there are basic things you need to know about the sensor, therefore, make sure you read to the end to learn how to use a PIR sensor with Arduino.

In this How-to tutorial, you will learn the following:

  • What is a PIR Sensor
  • How the PIR sensor is made and how a PIR sensor works     
  • Uses of the PIR sensor
  • Parts and Specifications of a PIR sensor
  • Improving the Efficiency of the PIR Sensor
  • How to Use a PIR Sensor Without Arduino
  • How to use a PIR sensor with Arduino

What is a PIR Sensor?

Labeled diagram of a PIR senor
Labeled diagram of a PIR sensor (source: componentsinfo.com)

PIR sensor means Passive infrared sensor, or Pyroelectric sensor. It is a sensor that senses the change in the heat energy in a system or a place and give out a high voltage output, but gives out a low voltage output when there is no change in the heat energy of the system or place where it is used. All objects with a temperature above Absolute Zero (0 Kelvin / -273.15 °C) emit heat energy in the form of infrared radiation, including human bodies and animals. The hotter an object is, the more radiation it emits.

How the PIR sensor is made and how a PIR sensor works

The HC-SR501 PIR sensor basically consists of two main parts: A Pyroelectric Sensor and A special lens called Fresnel lens which focuses the infrared signals onto the pyroelectric sensor.

How PIR sensor works
How PIR sensor works. (source: howtomechatronics.com)

A Passive infrared Sensor has two rectangular slots in it made of a material that allows the infrared radiation to pass. Two separate Infrared sensor electrodes are attached behind these two rectangular slots, one of the infrared sensor electrodes is responsible for producing a positive output, while the other is responsible for producing negative output.

It should be noted that what the Passive infrared sensor detects is a change in infrared levels and not measurement of ambient infrared levels.

The two electrodes are set up to produce a high voltage when there is a differential Infrared output between the two electrodes, i.e.  If one half of the slots sees more infrared radiation than the other, the output will swing high, and if there is low infrared radiation on the two slots, it means there will be no differential infrared output, then the electrodes will give zero volts output.

Uses of the PIR sensor

The PIR sensor is a heat sensing device, hence, it can be applied to any system where infrared sensing or heat sensing is required.

Examples of such applications are:

  1. Automatic lighting systems in staircases, closets, etc.
  2. Motion detection systems
  3. Security alarm systems

Parts and Specifications of a PIR sensor

parts of a pir sensor
parts of a PIR sensor (source: lastminuteengineers.com)
PIR-motion-sensor-pinout
PIR-motion-sensor-pinout

Shown above is a labeled diagram of the HC-SR501 passive infrared sensor showing most of the parts of the sensor. The PIR sensor has 3 pins, the pinout of a PIR sensor consists of the VCC, Output and Ground

VCC: This is where the input voltage is connected to the sensor. The integrated circuit in the Device is designed to work with 3V, but voltages ranging from 4.5V to 12V can be connected to VCC, this is because the PIR sensor has an inbuilt voltage regulator. However, 5V is often the recommended voltage that should be connected to the VCC pin of the PIR sensor.

Digital Out: this pin brings output voltage when the sensor senses the presence of an IR radiation.

GND: This is the zero volts potential point when the device is in operation, it is where the negative voltage of the battery is connected, or the point where the ground wire of the power supply is also connected when the device is in operation.

Sensitivity Adjust: This is a potentiometer that is used to adjust the sensitivity of the sensor, to set the maximum distance it should cover when in operation. The range is between 3 to 7 meters. Turning the potentiometer clockwise increases this distance, while turning it anticlockwise decreases this distance.

Time – Delay Adjust: This too is a potentiometer that is used to the length of time the output voltage given out by the sensor stays high before going low. This time ranges from 3 seconds to 300 seconds.

H – Jumper: This header pin is called the Hold or Retriggering or Repeat mode pin. If this jumper is looped to the common pin in the middle as shown on the image above, the output given out by the sensor will always remain high as long as the pyroelectric sensors are getting a differential IR radiation.

L – Jumper: This header pin is called the Intermittent or non-Re-triggerable or no-repeat mode pin. When it is looped with the common pin in the middle, it causes the output produced by the sensor to remain until the time set by the time adjustment knob elapses.

Signal Processing IC (BISS0001): This IC coordinates the actions going on in the HC-SR501 PIR sensor to operate as required.

3V DC Regulator: This regulator IC converts the input voltage connected to the VCC pin to the 3V value the signal processing IC can comfortably work with.

Protection Diode: This is a reverse-polarity protection diode used to protect sensitive parts of the sensor circuitry from damaging when VCC and Ground power supplies are switched.

Improving the Efficiency of the HC-SR501 PIR Sensor

On the circuit board of the PIR sensor are solder pads for soldering more components on the board. See image below.

How to use a PIR sensor with Arduino tutorial
The RL and RT solder pads (source: lastminuteengineers.com)

RT: This is where you can solder a light dependent Resistor which is also known as a photo resistor or LDR. The light dependent resistor when connected to a PIR sensor modifies the sensor to only work at night.

RL: This is where one can solder a heat dependent resistor, which is also known as a thermistor. This modifies the PIR sensor to be able to function properly under extreme temperature conditions.

How to Use a PIR Sensor Without Arduino

The HC-SR501 PIR Sensor can be used without an Arduino. To use the PIR sensor without an Arduino, follow the steps below:

Use a breadboard and jumper wires to make the connections

Step 1: Connect the positive terminal of a 9V battery to the VCC pin of the PIR sensor.

Step 2: Connect the negative terminal of the 9V battery to the Ground pin of the PIR sensor.

Step 3: Connect a 220Ω resistor to the output pin of the PIR sensor.

Step 4: Connect the positive leg of an LED to the 220Ω resistor.

Step 5: Connect the negative leg of the LED to the negative leg of the battery.

See circuit diagram below

How to use a pir sensor without Arduino
How to use a PIR sensor without Arduino

Circuit Operation

Once you’ve made the circuit as shown, allow the sensor to acclimatize itself with the heat energy of the environment for one minute, during this period, the LED might flicker. Then move your hand around the sensor, you will observe that the LED comes ON. If the H-jumper is in use, the LED will remain ON until you move your hand away from the sensor. But if the L-Jumper is in use, the LED will stay until the pre-set delay time has elapsed. Sometimes, the best way to initiate any form of circuit design is circuit simulation. You can simulate how a PIR circuit will behave in a Proteus software. Proteus is a software that is used in simulating an electronic circuit before building the real thing. If you do not have Proteus software on your computer, you can download Proteus 8, Proteus 8.11 and Proteus 8.12 on my site. All these versions of Proteus come with the Arduino library files. This means that you can simulate the PIR sensor in Proteus software with Arduino before building the real circuit.

How to use PIR sensor with Arduino

Now, we are about to discuss the main aim of this tutorial, which is how to use a PIR sensor with Arduino. One good thing about interfacing an Arduino with a PIR sensor is that, the Arduino will enable you integrate other sensors, so, if you want to implement a complex automated system using a PIR sensor and other sensors, you only need to make simple connections and use few lines of codes to achieve your aim. Using a PIR sensor with Arduino is very easy, follow the steps below to connect Arduino with a PIR sensor, after that you upload the Arduino code given below to the Arduino board and your motion detection system will start working immediately.

Step 1: Connect the VCC pin of the Arduino to Vin pin of the Arduino board.

Step 2: Connect the Ground pin of the sensor to any ground pin of the Arduino board.

Step 3: Connect the output pin of the PIR sensor to digital pin 8 of the Arduino board.

Step 4: Connect the Arduino board to your computer via USB cable.

Step 5: Upload the Arduino code to the Arduino board from your computer. (See Arduino code below)

See circuit diagram below.

How to use a PIR sensor with Arduino
How to use a PIR sensor with Arduino
int ledPin = 13;                // LED
 Pin
int inputPin = 8;               // Input Pin for PIR sensor
int val = 0;                    // variable for reading pin status
 
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
 }
 
void loop()
{
  val = digitalRead(inputPin);  // read input value
  
  if (val == HIGH)               // check if the input is HIGH
  {            
    digitalWrite(ledPin, HIGH);  // turn LED ON
  
    }

  else 
  {
    digitalWrite(ledPin, LOW);    // turn LED OFF
  
   
    }
  }

If you do not know how to set up your computer to use an Arduino with it, read this tutorial, what is Arduino and how to use Arduino.

Circuit Operation

If you followed the steps outlined above to connect the circuit and you uploaded the Arduino sketch, once you bring your hand close to the PIR sensor, the onboard LED connected to digital pin 13 of the Arduino board will come ON, and it will go OFF after the time set by the time-display knob has elapsed.

Note that, to use the H-jumper to put the sensor in hold mode, you need to connect the pin to Arduino and write few lines of code to realize the design.

Conclusion

Having learnt:

  • What is a PIR Sensor
  • How the PIR sensor is made and how a PIR sensor works     
  • Uses of the PIR sensor
  • Parts and Specifications of a PIR sensor
  • Improving the Efficiency of the PIR Sensor
  • How to Use a PIR Sensor Without Arduino
  • How to use a PIR sensor with Arduino

You can now apply the SR-501 PIR sensor to your designs and make the best out of them.

If you learnt something from this tutorial, consider reading other related tutorials we have on this site. Your comments are much welcomed in the comment section below.

Leave a Reply

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