Monday 24 January 2011

Pyroelectric Infrared sensors (PIR) Part1

Thought I might start moving some of my old posts across from my old site and put them all here in one place.

Pyroelectric Infrared sensors (PIR) (thermograph)

posted Jan 24, 2011 10:00 PM by robert sturzbecher   [ updated Jan 24, 2011 11:32 PM ]
Pyroelectric sensors are cool and so is thermograph but the main real downside is cost. 
If you don't need it to be accurate here is a cheap and easy way of adding it to your next Arduino project.

For this project I will use a pyroelectric sensor from a PIR motion detector. Of coarse the temperature reading is not going to be very accurate but if you need accuracy then you will need something better then a $2 PIR sensor. 

There are a few things to note about PIR sensors. 
  • Background temperatures and Sensor temperatures influence the output.
    Holding the sensor or heat near the case will also influence the output.
    (So don't put them next to things that can generate heat like motors, LEDs ,ect..)
  • Motion detector types have 2 elements inside them.
    A left and a Right. One will drop the output voltage and the other will increase it.
    (This is why we cover one file with foil tape) These sensors normally have square windows.
  • These sensors see humans, The motion detector PIR sensors have filters built in that are optimized to see the heat emitted by humans. 

Ok lets start

Modding the sensor is done with a small bit of foil tape. Because the sensor has a left&right sides that increase and decrease the output depending upon which side detects the most heat we will cover one side. I used foil tape as the metal is a good IR reflector and a good conductor of heat and will hopefully disperse the heat. I found it was better to block the side the lowers the voltage, but you can do ether.

Wiring the sensor is easy, They only have 3 pins (Drain/Vcc, Source/Out, Ground). To wire to an Arduino you need to connect up as below

  • Drain/Vcc goes to 5Volts.
  • Source connect directly to a Analog pin of the Arduino and needs a 47k resistor that connects to Ground. 
  • Ground goes to ground.
Above is an extract from datasheet with my notes on it.

I didn't have a 47k so I used a 20k, still works well.

The Code to get the sensor value.

                        sensorValue = analogRead(sensorPin);

What did you expect it to be more complex? You can use most of the Arduino demo sketches to use the sensor. The only thing to note it that analogRead works better if you put a delay in front of it to let things settle first. 

Putting to use 
If you want something a little more complex you could try mounting the sensor on servos and use it to track people and their appendages ;) and oh yes that is a wireless camera on top.
You could even use it to map the surrounding environment.

In the video below the head does a sweep reading the PIR sensor values then returns to the strongest point with the lights, then repeats. The values are outputted to the computer if connected.  

The next step for this that I am working on is to process the data computer side to create a 2d PIR image, almost like Thermo graph but without the stupidly expensive price tag. 

Read part 2 for the software.

The Datasheet is also downloadable from the product page above.

You can also get the sensors from other online stores like (I'm not plugging them its just were I shop)


  1. can you post there a code?

  2. I have the code for processing here for doing 2d images.

    For the code in the youtube video it is a mash up of the arduino analog read example and servo sweep example. The servo moves from side to side and stores servo position if the analog value is greater then previous analog value. Then at the end of a sweep return to the servo position with the greater analog read value.

  3. This comment has been removed by the author.

  4. I am doing a similar project at the moment. I have foil covering one half. While keeping the heat source ans sensor from moving, the output still decays back to the baseline fairly quickly. This makes it unsuitable for absolute measurements, like the temperature of my hand.
    I'm assuming yours didn't decay? If it did, wouldn't your graph be too noisy to use?