Passive infrared sensor (PIR)

Necessary knowledge: [HW] User Interface Module, [HW] Combo module,
[AVR] Digital Inputs/Outputs, [LIB] Pins

Theory

PIR sensor

Passive infrared sensor measures infrared (IR) radiation from objects in it's field of view. All objects emit some low level radiation. The hotter something is the more radiation is emitted. Human eye is not capable to see IR radiation, but it's possible to use special cameras and sensors to detect it. The sensor is called passive because it doesn't emit light to get measurements. The sensor in PIR is actually split into two parts. The reason for that is to measure motion. Two parts of sensor are wired up in a way that they cancel each other out. If one detects more or less IR radiation than the other, the output will swing high or low.

PIR sensor is mostly used for detecting living being movement and thus is generally known as passive infrared detector (PID). The sensor is also sensitive enough to even detect IR radiation source movement while the object is already in it's field of view.

PID usually consists from three components:

  • passive infrared sensor (PIR)
  • lens for directing radiation to the sensor
  • control circuit
PID - motion detector

Practice

PID sensors output is usually simple digital signal. If the sensor has detected something then it usually outputs high impulse which stays high for a given time period (the time might be adjustable). This gives the sensor capability to switch a relay or be used as an input for microcontroller. These devices can turn on a light or be used as a part of alarm system.

Using the detector with a microcontroller is not much different from reading a regular push button switch. PID can be connected to digital or analog input. Be sure to check the pinout of the detector before connecting it to microcontroller. It is especially important to not mix up power and ground pins cause failure to do so usually ends up in breaking the detector.

On Robotic HomeLab III the detector has to be connected to Combo module encoder input if the sensor requires 5V power or analog/digital input of choice if voltage requirement is 3.3V. Be sure to check the sensor voltage rating before connecting. If the 5V encoder input is used then the external power source has to be connected on the Controller module.

 

// Robotic HomeLab PID sensor (detector) example program
#include <homelab/pin.h>
 
// Detector input pin define
// Homelab II
//pin pir_pin = PIN(F, 0);
// Homelab III
pin pir_pin = PIN(C, 4);
 
// Main program
int main(void)
{
  // Setting LED pins to output
  pin_setup_output(led_green);
  pin_setup_output(led_red);
  // Setting detector pin as input
  pin_setup_input(pir_pin);
 
  // Endless loop
  while (1)
  {
    // If the sensor has not detected anything then the green LED is on
    // If something is detected then the RED led turns on
    if(pin_get_value(pir_pin) == 0)
    {
        led_on(led_green);
	led_off(led_red);
	}
    else
    {
	led_on(led_red);
	led_off(led_green);
    }
  }
}
en/examples/sensor/ir_passive.txt · Last modified: 2020/07/20 09:00 by 127.0.0.1
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0