HOW TO USE PIR SENSOR WITH ARDUINO

How to use a PIR sensor without Arduino

in this tutorial, you will learn how to use HC-SR501 PIR sensor with Arduino. To effectively utilize this sensor, it’s essential to understand its basic functionality and features. A PIR (Passive Infrared) sensor is a widely used motion detector that can detect changes in infrared radiation in its environment, which typically corresponds to the movement of people or animals.

In this comprehensive guide, we’ll cover everything you need to know about the HC-SR501 PIR sensor, including its pin configuration, operating principles, and practical applications. We will start by explaining the core concepts of how the sensor works, followed by detailed instructions on wiring it to an Arduino board. Additionally, we will provide example code and step-by-step procedures to help you set up and test the sensor.

Understanding the sensitivity adjustments and delay time settings of the HC-SR501 is crucial for customizing its performance to fit specific needs. We will delve into these aspects and show you how to fine-tune the sensor for optimal detection in various scenarios.

By the end of this tutorial, you will have a solid grasp of how to integrate the HC-SR501 PIR sensor with Arduino, enabling you to create projects such as automatic lighting systems, security alarms, and motion-activated devices. Be sure to read through to the end to gain a complete understanding of how to make the most of this versatile sensor in your Arduino projects.

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?

parts of a pir sensor
parts of a pir sensor

A PIR sensor, which stands for Passive Infrared sensor or Pyroelectric sensor, detects changes in heat energy within an area. When it senses a variation in heat energy, it outputs a high voltage signal; otherwise, it outputs a low voltage signal when no change is detected. All objects with a temperature above Absolute Zero (0 Kelvin or -273.15°C) emit infrared radiation, including humans and animals. The hotter the object, the more infrared radiation it emits. This makes PIR sensors useful for detecting the presence of people or animals based on the heat they emit.

How the PIR Sensor is Made and How a PIR Sensor Works

The HC-SR501 PIR sensor is composed of two primary components: a pyroelectric sensor and a special lens known as a Fresnel lens, which concentrates infrared signals onto the pyroelectric sensor.

PIR sensor field of view
PIR sensor field of view

A Passive Infrared (PIR) Sensor features two rectangular slots designed from a material that permits the passage of infrared radiation. Positioned behind these slots are two separate infrared sensor electrodes: one responsible for generating a positive output and the other for producing a negative output. This setup enables the sensor to detect changes in infrared radiation levels rather than simply measuring the ambient infrared levels present in its environment.

The operational principle of the PIR sensor revolves around detecting variations in infrared radiation across its two electrodes. When one slot detects a higher level of infrared radiation compared to the other, it creates a differential output between the electrodes. This difference triggers the sensor to produce a high voltage output. Conversely, if both slots detect similar levels of infrared radiation, indicating no differential output, the electrodes will generate a low or zero-volt output.

Therefore, the PIR sensor’s ability to discern changes in infrared levels allows it to effectively sense the presence of warm objects, such as humans or animals, within its detection range. This makes PIR sensors highly suitable for applications requiring motion detection and occupancy sensing in various environments, including security systems, lighting controls, and energy management systems.

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.

  1. Automatic lighting systems
  2. Motion detection
  3. Security alarm systems

Parts and Specifications of a PIR Sensor

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.

The RL and RT solder pads
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.

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.

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)

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

In this tutorial, you have 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 *