Overview
In this lesson, we will learn how to use Passive Infrared (PIR) sensor to detect the movement that happens nearby.
Components
- 1 * Arduino UNO
- 1 * USB Cable
- 1 * PIR Movement Sensor
- 1 * 220Ω Resistor
- 1 * LED
- Several jumper wires
Principle
The sensor has pins marked “OUT”, “-”, and “+” (for Output, GVD, and +5V).
PIR sensors respond to heat and can be triggered by animals such as cats and dogs, as well as by people and other heat sources. The output pin of a PIR sensor will go HIGH when a motion is detected.
Procedures
Step 1: Build the circuit
Step 2: Program
/*********************************************************** File name: 30_PIR_movement.ino Description: The LED will be turned on when the motion has been detected. Website: www.adeept.com E-mail: support@adeept.com Author: Tom Date: 2015/05/02 ***********************************************************/ int ledpin=11; //Set the digital 11 to LED int PIRpin=5; //Set the digital 5 to PIR void setup() { // put your setup code here, to run once: pinMode( ledpin,OUTPUT); //initialize the led pin as output pinMode( PIRpin,INPUT); //initialize the PIR pin as input } void loop() { if(digitalRead(PIRpin)==LOW)//Detecting whether the body movement information { digitalWrite(ledpin,LOW);//LED OFF }else { digitalWrite(ledpin,HIGH);//LED ON } }
Step 3: Compile the program and upload to Arduino UNO board
The LED will be turned on when any motion is detected.