Motion sensing – Passive Infrared (PIR) sensor Unit

Motion sensing – Passive Infrared (PIR) sensor Unit

The Passive Infrared sensor unit is not included in the standard kit, but is part of our expanded kit distributed at our project days.

Passive infrared or PIR sensors as they’re often called are used to detect motion of people or animals within in area. They are used extensively with security and burglar alarm systems, or as parts of a smart building where office lights get turned on only when staff are in some part of a building. If you look at the ceiling of many houses and offices you will often see a little white box in the corner – which is usually a PIR sensor detecting motion in that particular room.

Adafruit has a great article explaining the details of how PIRs work, but in essence they all work by detecting infrared light moving between zones in the monitoring area.

Infrared light is a form of light that is invisible to the human eye, but which is emitted by warm objects. Since human and animal bodies are warm, they radiate infrared heat which can be seen by cameras with infrared sensors, thermal imaging cameras (as shown in this image where warmer colours correspond to higher temperatures measured at each location in the image), or in our case a simpler device such as a passive infrared sensor.

You will notice on every PIR that they have facetted lenses (meaning the lens has lots of flat sections) that divide the physical area in front of the lense into ‘zones’ with the infrared energy from each zone focussed down onto different segments of the infrared sensor inside the PIR. The sensor electronics then measure differences between all these zones to detect the motion of warm objects moving between zones.

PIR Sensor properties

Like all electronic components, a PIR has lots of properties one needs to be aware of when designing an application or solution that uses the sensor. The interesting ones for us include:

Angle

Our particular PIR sensor that we use has an obvious facetted dome/bump on the one side of the sensor. This dome should be pointed at the area in which motion is to be detected. The dome has a field of view of roughly 100 degrees, which means if you imagined holding the dome up to your eye and looked ‘through it’ to see what the dome ‘sees’, you would be able to see the area in front of you inside a 100 degree angle – ie: 50 degrees to the left and to the right of an imaginary line projecting out from the center of your eye/dome.

Range

The reliability with which moving bodies can be detected decreases as the range increases, with a maximum human detection range of roughly 5 meters (although this depends on the physical environment, obstructions, and ambient temperature)

Speed

The sensor can detect walking speed movement, and once motion is detected the sensor will keep its detection output signal in a high state (ie: a ‘1’ value on the digital output) for 2 seconds since the last motion was detected.

Using the sensor in UIFlow

The PIR sensor is very easy to use in UIFlow. You add the PUR Unit as per normal, noting that the PIR unit gives a digital output and therefore likes to be connected to Port B, but is also compatible with ports A and C.

UIFlow PIR block
PIR example program

Adding the PIR Unit to your program creates a new PIR sub-menu under the Units menu, with a single Get pir<X> status block. This block outputs a number ‘1’ if motion has been detected within the last two seconds, and a ‘0’ otherwise.

It would have been handier if this block had been designed to give a True or False output to make it easy to use directly in an If block. Instead, as shown in the example program screenshot, you need to use one of the comparison blocks from the Logic menu to compare the status to the number 1 to detect if motion has been trigger.

Fun challenges

Try the following two exercises to see if you can ‘beat’ the sensor! Post a project on the EduPortal with your results!

  1. Setup the sensor pointing at an area and see how slowly or quickly you have to sneak past the sensor to avoid being detected
  2. See if there’s anything you can wear (jersey/mask/tin foil wrap!) to make yourself completely invisible to the sensor!

Related Articles

Responses