Circuit 3D

PIR and IR sensors

A PIR sensor (passive infrared) detects motion by sensing a change in the infrared that warm bodies give off; an IR sensor shines its own infrared light and detects it bouncing back or arriving from a remote. People glow most strongly near 9 µm, by Wien’s law: 2,898 µm·K ÷ 310 K ≈ 9.3 µm.

λpeak = 2,898 µm·K ÷ T

where λpeak is the wavelength given off most strongly and T the surface’s temperature in kelvin.

A PIR is passive: it sends out nothing and only watches.

What is a PIR sensor?

A PIR sensor is a motion detector that senses the infrared given off by people and animals, switching its output high when a warm body moves across its view.

It is passive, sending out nothing, which makes it cheap and low-power: the sensor in burglar alarms, automatic lights and hand dryers. Figure 1 shows why it needs movement.

A B A − B triggers

Walking, zone A: element A warms while B doesn’t, so the difference swings positive past the threshold and triggers the module: its output goes HIGH for its set hold time.

Figure 1. A PIR’s two sensing elements, wired so their signals subtract, each watching its own zone through the lens. The curve is the difference as a person walks past.

How does a PIR motion sensor work?

Inside are two pyroelectric elements, materials that make a tiny charge when their temperature changes, wired so their signals subtract; a warm body crossing their views warms one, then the other.

The white dome is a Fresnel lens that splits the room into many such zones. A filter window passes long-wave infrared, around 5 to 14 µm, where a body near 37 °C glows most, and blocks visible light. A steady scene, or a slow change such as a warming room, hits both elements equally and cancels out.

What is an IR sensor?

An IR sensor usually means an active one: an IR LED shines invisible infrared and a photodiode or phototransistor beside it measures how much comes back.

A comparator, set by a small trimmer potentiometer, turns that into a digital output. It suits obstacle detection over a few centimeters and line-following, since black absorbs infrared. Pale surfaces reflect much more than dark ones, as Figure 2 shows, so range depends on the target as well as the distance.

5 cm seen

White surface, 5 cm: it reflects 4× the light the comparator needs, so the module detects it and pulls its output low.

Figure 2. An IR obstacle module: an IR LED, a photodiode and a comparator set to see a white card at 10 cm, in a simple model where reflected light falls with the square of distance.

How does an IR remote receiver work?

A remote flashes an IR LED in bursts at a carrier frequency, usually 38 kHz, and the receiver module only responds to that flashing, outputting a clean digital signal.

The receiver, such as a TSOP38238, filters out steady infrared from the sun and lamps, then pulls its output low whenever it hears a burst. Remote codes set bits by the timing of bursts and gaps; in the common NEC code a 1’s gap is three times a 0’s, as Figure 3 shows.

LED OUT 2,250 µs

A 1 bit: the LED flashes at 38 kHz for 562.5 µs, about 21 flashes, then rests for 1,687.5 µs. The receiver pulls its output low during the burst, so the bit lasts 2,250 µs in all.

Figure 3. One bit of the common NEC remote code: the LED’s 38 kHz burst and a 38 kHz receiver’s output, which is low while it hears the burst.

What is the difference between PIR and IR sensors?

A PIR only receives the infrared that warm bodies already give off, so it detects living movement; an active IR sensor makes its own infrared, so it detects any object that reflects or blocks its beam.

PIRs cover rooms, out to several meters, but ignore still objects and can’t tell distance. IR obstacle sensors work only over centimeters, but see anything, moving or not. Both use infrared, invisible to the eye though often visible to a phone camera.

How do you connect a PIR sensor to an Arduino?

To connect a PIR sensor to an Arduino, wire its VCC to 5 V, GND to ground and OUT to a digital pin; the output goes high, to about 3.3 V, when it detects motion.

On the common HC-SR501, one trimmer sets sensitivity and the other how long the output stays high, from a few seconds to a few minutes. Give it about a minute after power-up to settle. An IR obstacle module wires the same way, with its output usually going low when it sees something. An Arduino reads either with digitalRead.

How do you work out infrared wavelengths and IR LED resistors?

To work out an infrared wavelength, divide 2,898 µm·K by the temperature in kelvin, so 310 K peaks near 9.3 µm; for an IR LED’s resistor, divide the supply minus its forward voltage by the current.

Example 1: the infrared a body gives off

At what wavelength does a surface at 37 °C give off the most infrared?

Given
a surface at 37 °C, 310.15 K
Find
the wavelength it gives off most strongly
Solution
λpeak = 2,898 µm·K ÷ 310.15 K = 9.34 µm
Answer
9.34 µm, thermal infrared

Example 2: an IR LED’s resistor

An IR LED drops 1.2 V. What resistor runs it at about 20 mA from 5 V?

Given
a 940 nm IR LED dropping 1.2 V, on 5 V, aiming for 20 mA
Find
its series resistor
Solution
R = (5 V − 1.2 V) ÷ 20 mA = 190 ΩThe next standard value up, 220 Ω, gives (5 V − 1.2 V) ÷ 220 Ω = 17.3 mA
Answer
220 Ω

Summary

Key equations

  • λpeak = 2,898 µm·K ÷ T Wien’s law
  • R = (Vsupply − VLED) ÷ I an IR LED’s resistor
  • NEC bit = 562.5 µs + space 0 or 1

Key terms

Passive
Only receives, sends nothing.
Pyroelectric
Makes charge when heated.
Fresnel lens
Splits the view into zones.
Carrier
The 38 kHz flashing.

Practice problems

  1. What does a PIR sensor detect?

  2. Someone stands perfectly still in front of a PIR. What happens?

  3. Why do IR remotes flash at about 38 kHz?

  4. An IR LED drops 1.2 V. What resistor gives about 20 mA from 5 V?

  5. Why does a black line show up to an IR line sensor?

FAQ

Can a PIR sensor see through glass?

Barely. Ordinary glass blocks most of the long-wave infrared a PIR looks for, so it won’t see people through a window.

How far can a PIR sensor detect?

A typical HC-SR501 module reaches about 3 to 7 meters, adjustable, over a cone of roughly 110°.

Why does my PIR sensor trigger by itself?

Usually warm air from heaters, sunlight on nearby surfaces, a noisy supply, or not letting it settle for a minute after power-up.

Can I see infrared light?

Not with your eyes, but most phone cameras show a 940 nm remote’s LED as a faint flicker.

What is the difference between a PIR and a microwave motion sensor?

A PIR passively watches for infrared changes; a microwave sensor sends out radio waves and detects their Doppler shift, so it can see through thin walls.

Do IR sensors work in sunlight?

Remote receivers mostly do, thanks to their 38 kHz filter. Simple obstacle modules can be fooled by bright sunlight, which contains plenty of infrared.

Is infrared heat?

Infrared is light just beyond red that warm objects give off, which is why we feel it as heat. Remotes use near-infrared, far shorter in wavelength.

What is an IR LED?

An LED that gives off infrared, usually at 850 or 940 nm, invisible to the eye; it drops about 1.2 to 1.5 V and needs a series resistor like any LED.