A PIR motion sensor, is a small, low power and inexpensive sensor that is used to sense objects emitting low level radiation e.g humans, cats, dogs, etc. Mostly these sensors are used in motion detecting devices e.g motion activated lamps.
PIRs or referred to as PIR, “Passive Infrared”, “Pyroelectric”, or “IR motion” sensors, are easy to interface with, that is, if it detects something the output goes High else its always LOW.
PIRs have simple circuit made up of capacitors, resistors, voltage regulator(3.3V) and a BISS0001 chip that does all the processing. For settings, the sensor has two variable resistors to set sensitivity and delay time. Also there is a retrigger setting jumper.
Top View, Fresnel Lenses
We’ll learn how to interface PIR sensor with an Arduino Uno. Here is the part list we’ll need.
– PIR Motion Sensor
– Arduino Uno
– Jumper pack
– Mini Breadboard
– Connect PIR motion Sensor Signal pin to Arduino digital pin 7
– Connect positive lead of the LED to Arduino digital pin 6
– Connect both LED and PIR sensor ground pins to Arduino ground pin
– Connect both LED and PIR sensor VCC pins to Arduino +5V pin
Arduino code, PIR_Motion_Sensor.ino
* pir -- 7
* led -- 6
* vcc -- +5v
* gnd -- gnd
#define On 1 //led on value
#define Off 0 //led off value
#define pir_pin 7 //PIR sensor input pin
#define led_pin 6 //led output pin
//set PIR pin as input
//set led pin as ouput
digitalWrite(led_pin,HIGH);//set LED on
digitalWrite(led_pin,LOW);//set LED off
//Check if there is motion
//read sensor ouput value
returntrue;//if person detected return true
returnfalse;//if no person detected return false
How the Code works
in the macro definitions, we define all the pins, PIR connected to pin 7 and LED to pin 6 on the Arduino.
#define pir_pin 7
#define led_pin 6
Then we have two functions, ‘setLed’ and ‘motionDetected’. The ‘setLed’ method takes a parameter that defines whether to turn the On/Off the LED.
The ‘motionDetected’ function reads the PIR sensor output and returns a HIGH or LOW
The two methods are then used in the loop function where we continously check if the sensor is triggered (using motionDetected() method), if there is a person the LED goes on else its off.
finally we give our program a delay of 250 milliseconds between sensor reads
Running the code
Click ‘Run on Arduino’ to upload code to your Arduino board.