Passive InfraRed (PIR) sesnors

Most of us use passive infrared sensors in our daily life.

  • Have you ever been into a bathroom where the lights turn on automatically?
  • Have you ever walked near a house entrance and the door light turned on? 
  • Have you ever been into a supermarket or a store where the doors opened automatically?

In all the above situations, human presence is being detected by passive infrared sensors.

A toddler discovers PIR sensors – GIPHY

What is infrared radiation?

All objects that have a temperature above absolute zero emit heat in the form of radiation. We can not see it but we can feel it on our bodies. For example, when we sit near a fireplace we can feel the radiation of the fire warming our skin.

Infrared radiation was discovered by William Herschel by accident in 1800 while conducting an experiment to find out the temperature of different colors. He used a prism to separate a light beam to the colors of the visible spectrum.

When a light beam enters through a prism, it is separated to the colors of the visible spectrum. By Wikipedia

Herschel placed several thermometers on the various colors exiting the prism and he noticed that red has the highest temperature and violet the lowest. One of the thermometers was placed by accident a bit outside the red tint light and he observed that it recorded even higher temperature.

Herschel discovers by accident invisible radiation that transfers heat. From:

Nowadays we know that visible light is only a small portion of the electromagnetic radiation spectrum. Apart from it, there is infrared radiation, microwaves, and radio waves that have lower frequencies from visible light. On the other side of the spectrum with higher frequencies, there is ultraviolet radiation (responsible for sunburns in summer), x-rays and gamma rays.

The electromagnetic spectrum. Picture by

Visualizing infrared radiation

Infrared radiation is not visible to human eyes. In order to visualize it, we use special infrared cameras that were first developed in 1929 for military purposes. They have a lense that allows infrared rays to pass through and reach a matrix of infrared sensors. The outcome of those sensors is processed and visualized using either grayscale tones or the colors of the visible spectrum correlating red to the highest temperature and violet to the lowest.

Visualizing the heat transfer from a laptop to the human body
An infrared camera view of a woman straightening her hair
Glasses block infrared rays

PIR sensors

Passive InfraRed sensors – PIR are extremely popular and fairly cheap. One of the most popular modules you can find online is the HC-SR501 that costs around 0,8 euros on eBay (December 2018).

PIR Motion Detector HC-SR501

Module anatomy

The main component of the module is a pair of sensors made from infrared sensitive materials like gallium nitride, caesium nitrate, polyvinyl fluorides, derivatives of phenylpyridine, and cobalt phthalocyanine. These two sensors are enclosed in a metal container which has a small window made of silicon and allows infrared radiation to go through. This metal container is fixed on the module PCB. The module also has a plastic cover that consists of many Fresnel lenses.

Below the plastic cover with the Fresnel lenses, there is the metal container in which there are the two sensors.

The working principle of PIR sensor

PIR sensors are called passive, because they do not emit some kind of signal to then wait for its return like ultrasound sensors (they emit ultrasounds) or obstacle avoidance sensors (they emit infrared light) for example. The nature of the materials used in manufacturing them creates an electrical current when they are exposed to infrared radiation. More specifically the HC-SR501 module:

  • haw two sensors connected in such a way that when one of them is exposed to a different amount of infrared radiation from the other the module creates a HIGH pulse that is passed through the OUT pin to Arduino or any other board connected.
  • When there is no movement of heat emitting objects in the area the two sensors elements get the same amount of infrared radiation.
  • When a warm body (people, animals etc.) passes in front of the sensor module the two elements momentarily absorb different amount of infrared radiation and the module sends a HIGH pulse.
The gray wall emits a constant low infrared radiation. When a human passes by the sensor the is a momentary difference in radiation between the two elements.

The importance of the plastic cover

The plastic cover of the module is designed to enhance its range and viewing angle. 

The HC-SR501 module has a viewing angle of 120 degrees and a range of 7 meters

If we take a closer look at the cover we can see that there are tiny lenses on every side.

Photo by Ardafruit

These are called Fresnel lenses and they owe their name to the French engineer that designed them in the 1820s. Primarily they were used in lighthouses to extend the scope of the light in the sea.

Adjusting the settings

HC-SR501 module has two potentiometers for adjusting the sensor’s sensitivity (range) and time delay.

1: Adjusting Sensitivity (Sx) 2: Adjusting the time that HIGH signal stays on after spotting a movement (Tx).

Connecting the sensor to Arduino

The module has three pins:

  • VCC is connected to 5V pin in Arduino
  • GND is connected to ground (GND) in Arduino
  • OUT pin is connected to any of the digital pins in Arduino

Normally the OUT pin is LOW but when the sensor spots a movement it produces a HIGH pulse. In the sketch below I have connected the sensor to digital pin 2 and I also connected a red led to digital pin 13.

The program is fairly simple:

  • It repeatedly reads digital pin 2 and
  • if the input is HIGH it writes HIGH to digital pin 13 (led light on)
  • else it writes LOW to digital pin 13 (led light off)