ad space

PIR Sensor with Arduino

 PIR sensor are used to sense heat radiation signature radiated by human or animal bodies. PIR stands for Passive Infrared. These sensors are widely used industrial automation for detection, home automation, alarm systems and many other application.

interfacing of Arduino with PIR sensor module

 Here we demonstrate how PIR sensor can be used with Arduino to turn on and off a LED when somebody is near the PIR sensor. The LED will turn ON whenever the PIR sensor detects somebody in its detection zone. In the last tutorial PIR sensor with AVR we used ATmega328p microcontroller to do the same thing but using C programming language. 




This is how a PIR sensor module looks like.


The bottom side of the PIR sensor module and its various pins(GND, Data, Power), trigger jumper, sensitivity potentiometer, delay potentiometer is shown below.

Interfacing PIR sensor with Arduino

Below picture shows how you can interconnect PIR sensor with Arduino. The schematic shows that the PIR sensor data output pin(the middle one) is connected to pin 2 of the Arduino. A LED with resistor is connected to pin 12 of the Arduino with other end to the ground of Arduino. The PIR sensor ground and Vcc pins should be connected to the Arduino ground and Vcc, that is, they share same power supply and ground.

The following shows interfacing of Arduino with PIR sensor module and the LED.

interfacing of Arduino with PIR sensor module

Video Illustration: Watch the following video to know how PIR sensor with Arduino works.


Arduino Code for PIR sensor

In the following code, pin 2 is configured as input to get data from the PIR sensor. Pin 12 is configured as output because LED indicator is connected to it via resistor. In the loop, we use simple if/else statement to check whether there is any data from the sensor. If there is then we turn on the LED otherwise it remains off.


int pirstate = 0;

void setup () {
pinMode(12,OUTPUT);
pinMode(2,INPUT);
}

void loop() {
pirstate = digitalRead(2);

if(pirstate == HIGH){
	digitalWrite(12, HIGH);	
}
else
	digitalWrite(12,LOW);

}


PIR sensor is one kind of sensor to create alarm system. Some other methods of making alarm system using sensors are IR sensor(Infrared sensor), Laser Diodes, LDR(Light Dependent Resistor). See the following tutorials form using other types of sensors.

- Laser Diode & LDR based alarm system using Arduino

Light Dependent Resistor (LDR) Light Detector Alarm with Arduino

Post a Comment

Previous Post Next Post