How to interfacing PIR sensor and how it work with PIC16F877A microcontroller
In this tutorial we will learn how to works PIR sensor module and how it interface with PIC16F877A microcontroller. PIR sensors are commonly used in security alarms and automatic lighting applications.
You can watch the following video or read the written tutorial below.
The working principle of the PIR sensor:
A passive infrared sensor (PIR sensor) is an electronic sensor that detect infrared (IR) light radiating from human or animal body.
The module actually consists of a pyroelectric senor which generate energy when exposed to heat. That means when a human or animal body will get in the range it will detect a movement because human or animal body emits heat energy in a from of infrared radiations. PIR sensor are commonly called simply "PIR", or sometimes "PID", for "passive infrared detector". The term passive refers to the fact that PIR devices do not radiate energy for detection purposes. They work entirely by detecting infrared radiation (radiant heat) emitted by or reflected from objects.
The module also consists a specially designed cover maned Fresnel lens, which focuses the infrared signals onto the pyroelectric sensor.
The HC-SR501 sensor module :
The module has three pins Vcc, GND and Out pins. The Vcc and GND pins also powering the module and an output pin which gives the HIGH logic level if an objects is detected. Also it has two potentiometers. Ones for adjusting of the sensitivity and the other for the adjusting the time the output signal stay high when object is detected. This time can be adjusted from 0.3 seconds up to 5 minutes.
circuit schematic:
The circuit schematic is very quick simple. The PIR sensor module is connected to RD0 pin and the Lcd display is connected to PORTB of Microcontroller. Here we have used 3.3k ohm resistor for adjusting Lcd display contrast.
Source Code
# define PIR PORTD.RD0 // PIR module is connected RD0 pin
// LCD Module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// END lcd module connections
void main() {
Lcd_Init(); // Initialize the Lcd module
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1, " PIR SENSOR "); // Lcd print text
Lcd_Out(2,1, " INTERFACING "); // Lcd print text
delay_ms(1000); // 1 second delay
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, " Developed By ");
Lcd_Out(2,1, "MINA TECHNOLGY");
delay_ms(2000); // 2 second delay
while(1){
if(PIR==1){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1," Motion Detect ");
while(PIR); // wait for signal goes LOW
}
else {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, "Motion not detect");
while(!PIR); // wait for signal goes HIGH
}
}
}
Download free source code
Post Comments