PIR sensor is used to detect the motion of a human body or animal. The PIR sensor receives IR rays from bodies and generates electrical signals. For more information about PIR sensor, refer to article on PIR sensor with AVR. This project describes the working of PIR sensor/motion sensor and its interfacing with 8051 microcontroller. Here a message is displayed on 16x2 LCD when motion is detected.
A PIR (Passive infrared) sensor consists of two slots which are sensitive to IR. When a person enters or leaves the region of these slots, it causes positive and negative differential change between these two slots. This change is detected and is used to generate a signal. In this program, the output of PIR sensor is taken on pin P3.2 (external interrupt 0, EX0) through a NOT gate using BC548 transistor. Here it is assumed that as motion is detected, a door opens and after some time it gets closed, the message of opening and closing of gate is displayed on 16×2 LCD.
The circuit connections are as follows:
· RS, RW, EN pins are connected to P3.4, P3.5, P3.6
· Data pins of LCD are connected to port2
· Output of PIR sensor is connected to pin P3.2 (external interrupt0) through a NOT gate.
Project Source Code
###
// Program to detect motion of a human body using PIR Sensor and 8051 Microcontroller#include<reg51.h>#define port2 P2sbit rs = P3^4;sbit rw = P3^5;sbit e = P3^6;//DELAY FUNCTIONvoid delay(unsigned int msec){int i,j ;for(i=0;i<msec;i++)for(j=0;j<1275;j++);}//COMMAND SENDING FUNCTIONvoid lcd_cmd(unsigned char item){port2 = item;rs= 0;rw=0;e=1;delay(1);e=0;return;}// DATA SENDING FUNCTIONvoid lcd_data(unsigned char item){port2 = item;rs= 1;rw=0;e=1;delay(1);e=0;return;}//STRING SENDING FUNCTIONvoid lcd_string(unsigned char *str){int i=0;while(str[i]!=' '){lcd_data(str[i]);i++;delay(10);}return;}void message() interrupt 0{lcd_cmd(0x80); //begining of line1lcd_string("DOOR OPEN");delay(10);}void main(){while(1){lcd_cmd(0x38); //2 LINE, 5X7 MATRIXlcd_cmd(0x0e); //DISPLAY ON, CURSOR BLINKINGdelay(10);lcd_cmd(0x80); //begining of line1lcd_string("DOOR CLOSED");EA=1;EX0=1;}}###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.