ECE 2030
Arduino Based System
Design
Daw Khaing Su Wai
Experiment 13
Interface with PIR motion sensor
PIR motion sensor
• The PIR sensor detects when a person or animal moves in or out of sensor range.
• This sensor is used in most modern security systems, automatic light switches, garage door
openers and similar applications to react to motion.
• All objects, including the human body, at temperatures above absolute zero (0 Kelvin / -273.15
°C) emit heat energy in the form of infrared radiation.
• The hotter an object is, the more radiation it emits.
• This radiation is not visible to the human eye because it is emitted at infrared wavelengths.
• The PIR sensor is specifically designed to detect such levels of infrared radiation.
A PIR sensor consists of two main parts:
• A pyroelectric sensor, which you can see in the image below as a round metal with a rectangular
crystal in the center.
• A special lens called a fresnel lens which Focuses the infrared signals on the pyroelectric sensor.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• A pyroelectric sensor consists of a window with two rectangular slots and is made of
a material (typically coated silicon) that allows infrared radiation to pass through.
Behind the window, there are two separate infrared sensor electrodes, one
responsible for producing the positive output and the other for producing the
negative output.
• when one half sees more or less IR radiation than the other, we get the output.
• When there is no movement around the sensor, both slots detect the same amount
of infrared radiation, resulting in a zero output signal.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• But when a warm body like a human or an animal passes by, it first intercepts half of the sensor.
• This causes a positive differential change between the two halves.
• When the warm body intercepts the other half of the sensor (leaves the sensing region), the opposite
happens, and the sensor produces a negative differential change.
• By reading this change in voltage, motion is detected.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• A Fresnel lens is what increases the range and field of view of the PIR sensor. Its slim, lightweight
construction and excellent light gathering capability make it extremely useful for making PIRs small in size
yet powerful.
• A Fresnel lens consists of a series of concentric grooves carved into the plastic. These contours act as
individual refracting surfaces, gathering parallel light rays at a focal point.
• As a result a Fresnel lens, although smaller in size, is able to focus light similarly to a conventional optical
lens.
• To increase the range and field of view of the PIR sensor, the lens is divided into several facet-sections,
each section of which is a separate Fresnel lens.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• PIR controller takes the output from the Pyroelectric sensor and does some minor processing on it to emit
a digital output pulse.
• The module comes with a 3.3V precision voltage regulator, so it can be powered by any DC voltage from
4.5 to 12 volts, although 5V is commonly used.
• The module comes with a protection diode (also known as a safety diode) to protect the module from
reverse voltage and current. So even if you accidentally connect the power with incorrect polarity, your
module will not be damaged.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• PIR controller takes the output from the Pyroelectric sensor and does some minor processing on it to emit
a digital output pulse.
• Apply power 5V – 12V and ground. The sensor output goes HIGH when motion is detected and goes LOW
when idle (no motion detected).
• By connecting this output to the microcontroller, you can react to motion by turning lights ON/OFF,
enabling a fan, enabling a Halloween prop, or perhaps taking a picture of an intruder.
• And the best part is that it consumes less than 2mA of current and can detect motion up to 7 meters (21 ft)
with sensitivity control.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• The module comes with a 3.3V precision voltage regulator, so it can be powered by any DC voltage from
4.5 to 12 volts, although 5V is commonly used.
• The module comes with a protection diode (also known as a safety diode) to protect the module from
reverse voltage and current. So even if you accidentally connect the power with incorrect polarity, your
module will not be damaged.
• The PIR sensor has a potentiometer on the back to adjust the sensitivity.
• This potentiometer sets the maximum detection range. Sensitivity can be adjusted over a range of
approximately 3 meters to 7 meters (9 to 21 feet). Rotating the pot clockwise will increase the sensitivity
and thus the range, and vice versa.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• There is another potentiometer on the back of the PIR sensor to adjust the Time-Delay.
• This potentiometer sets how long the output will remain HIGH after motion is detected. It can be adjusted
from 1 second to about 3 minutes. Turning the potentiometer clockwise increases the delay, while turning
the potentiometer counter-clockwise decreases the delay.
There are two trigger modes that determine how the sensor will react when motion is detected.
• Single Trigger Mode: The constant motion will cause a single trigger.
• Multiple Trigger Mode: The constant motion will cause a series of triggers.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• Single Trigger Mode
• Multiple Trigger Mode
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
• RT – This connection is for a thermistor or temperature-sensitive resistor. Adding this allows the HC-SR501
to be used in extreme temperatures. This also increases the accuracy of the detector to some extent.
• RL – This connection is for Light Dependent Resistor (LDR) or Photoresistor. Adding this component allows
to operate in the dark. This is useful for building motion-sensitive lighting systems.
• These additional components can be soldered directly to the module or extended to remote locations
using wires and connectors.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor Pinout
• VCC is the power supply for the sensor. You can connect an input voltage anywhere
between 5 to 12V to this pin, although 5V is commonly used.
• Output pin is the 3.3V TTL logic output. It goes HIGH when motion is detected and goes
LOW when idle (no motion detected).
• GND is the ground pin.
https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
PIR motion sensor
Reading PIR Sensors
• The PIR acts as a digital output, it can be high voltage or low voltage, so all you need to do
is listen for the pin to flip high (detected) or low (not detected) by listening on a digital
input on Arduino.
• Power the PIR with 5V and connect ground to ground. Then connect the output to a digital
pin.
• In this example will use pin 2.
• The code is basically just keeps track of whether the input to pin 2 is high or low.
• It also tracks the state of the pin, so that it prints out a message when motion has started
and stopped.
https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir-w-arduino
Circuit Diagram
https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir-w-arduino
Code
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
Code
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
//Don't forget that there are some times when you don't need a microcontroller.