pir
Passive Infra-red Sensor

From Wikipedia, Passive Infra-Red sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects n its field of view. The term passive refers that PIR sensor does not emit or generate any energy for detection purpose.

So what is the function of PIR? Well, it is usually used as a motion detector. You may have come across with this sensor before. Remember when you enter a shop, a device say ” Hello, welcome”. That device is using PIR to detect your motion entering the shop. Another application of PIR is that it is used in energy saving application. When there is motion, then the lights would be turned on. When there is no motion, the lights would be turned off.

pir3
Three connections to use PIR sensor:
Vcc, GND, Output

The connection from PIR sensor to Arduino as shown below:

pir schematic
Schematic of using PIR sensor with LED and buzzer as output.
pir1
A variable resistor (Orange) is used to adjust the output “ON” delay time.

PIR is just like any other device that gives digital output. It will give output HIGH whenever there is motion detected.

DSC06759

Sample code with PIR:


#include <LiquidCrystal.h>

LiquidCrystal lcd(5,6,7,8,9,10);

#define buzzer 11
#define pir 12
#define led 13

void setup()
{
 pinMode(buzzer,OUTPUT);
 pinMode(led,OUTPUT);
 pinMode(pir,INPUT);
 lcd.begin(16,2);
 lcd.setCursor(4,0);
 lcd.print("Passive");
 lcd.setCursor(1,1);
 lcd.print("Infra-Red (PIR)");
 delay(1500);
}

void loop()
{
 lcd.clear();
 int pir_state=digitalRead(pir);
 if(pir_state == 1)
 {
 lcd.print("Motion Detected");
 digitalWrite(buzzer,HIGH);
 digitalWrite(led,HIGH);
 }
 else
 {
 lcd.print("No Motion");
 digitalWrite(buzzer,LOW);
 digitalWrite(led,LOW);
 }
 delay(500);
}

Video demo for PIR sensor.

Advertisements