PIR sensor based burglar alarm with SMS alert.
This project is about a PIR sensor based burglar alarm with SMS alert. The circuit senses the intrusion using a PIR sensor and sends an SMS to to the given mobile number when an intrusion occurs. The number of intrusions taken place is also displayed on an LCD display. An 8051 microcontroller is used for monitoring the PIR sensor and sending the alert message using the GSM module. An alarm is also raised when the intrusion occurs.
PIR sensor.
PIR sensor means passive infrared sensor. It is used to detect and measure the IR (infra red) radiations emitting from a source. The hear of the PIR sensor is a sensor core made of pyroelectric materials like Gallium Nitride. They simple produce an electrical output according to the intensity of IR radiations falling on it. In most cases an array of such sensors cores are used to improve detection. Numerous Fresnel Lenses arranged in the form of a dome is place on the sensor face to focus as much as IR radiations on to the sensor face. When ever a movement occurs in front of the PIR sensor, the intensity of the IR radiations falling on the PIR sensor changes and so do the sensors electrical out of the sensor. The electronic circuit inside the sensor detects this variation and pulls the output pin of the PIR sensor HIGH for sometime. Usually the output pin is pulled HIGH for 3 to 4 second. Read this article Interfacing PIR sensor to 8051.
GSM Module.
GSM (Global Systems fro Mobile communication) Module is a device that can accept a SIM card and operate in a GSM network. A GSM module can perform various tasks in the network such as sending messages, accepting messages, dialing a phone number, receiving calls, sending and receiving voice messages, sending digital media etc. In simple words a GSM module can perform any task that is supported by the module itself and the network service provider. The network actually sees the GSM module just like a mobile phone. The common applications of GSM module are appliance switching devices, messaging systems, voice mailing systems, FAX systems etc.
GSM Module – Buyers Guide – are you looking to buy a GSM module? There are a handful of product variants for GSM module – like SIM900, SIM300, SIM800 etc. We have created this buyers guide to help you select the right GSM module for your project needs.
The GSM module we are using here is based on a SIM900 GSM chip. Read this article Interfacing GSM module to 8051.
Circuit diagram.
The GSM module communicates with the 8051 using serial communication. Tx pin of the GSM module is connected to Rx pin of the microcontroller (pin10) and Rx pin of the GSM module is connected to Tx pin of the microcontroller. Output pin of the PIR sensor is connected to P3.5 of the microcontroller. Data pins (D0 to D7) of the LCD module are connected to Port 0 of the microcontroller. Each pins of Port 0 are pulled up using a 10K x 8 resistor network. Port 0 of the 8051 is open drain and has no internal pull up resistor. So we need external pull -up resistors to make it work properly as output pins. Control pins (RS,RW and E ) of the LCD module are connected to P2.7, P2.6 and P2.5 of the microcontroller respectively. The LCD module we are using here is JHD162A. Read this article, Interfacing LCD module to 8051. Resistor R4 is used for setting the contrast of the display. Resistor R5 limits the current through the back light LED of the display.
Push button switch S2, capacitor C11 and resistor R6 are associated with the reset circuit. Capacitor C11 is used to de bounce the push button switch. The C11 actually by-passes the vibrations produced when the push button switch is pressed. If C11 is not used, the microcontroller will read all the vibrations as key presses and the system will perform multiples resets. Crystal X1 and capacitors C8, C10 are associated with the clock circuitry. The baud rate used for serial communication in this project is 9600. So the crystal needs to be exactly 11.0592 MHz for getting this baud rate.
Port 2.0 of the microcontroller is used for controlling the alarm. P2.0 is connected to transistor Q1 through resistor R7. R7 limits the base current of Q1. Resistor R0 (10K) is used for pulling up P2.0 pin. The relay is connected across the collector of Q1. D5 is a freewheeling diode. It by-passes the back emf produced when the relay is switched. If free-wheeling is not done, the back emf may destroy the transistor or even the microcontroller. The 12V buzzer is connected through the normally-open contact of the relay.
Program.
PIR EQU P3.5 //equates P3.5 to PIR RS EQU P2.7 //equates P2.7 to RS RW EQU P2.6 //equates P2.6 to RW E EQU P2.5 //equates P2.5 ot E ORG 00H //origin MOV TMOD,#00100001B //Timer1=Mode2 timer & Timer0=Mode1 timer MOV TH1,#253D //loads Th1 with 253D (9600 baud) MOV SCON,#50H //sets serial port to Mode1 and receiver enabled SETB TR1 //starts Timer1 MOV DPTR,#LUT //loads DPTR with starting address of LUT SETB P3.5 //sets P3.5 as input port for PIR sensor CLR P2.0 //sets 2.0 as output port for alarm MOV R7,#00D //loads R7 with 00D MAIN:ACALL DINT //calls DINT subroutine ACALL TEXT1 //calls TEXT1 subroutine ACALL LINE2 //calls LINE2 subroutine ACALL TEXT2 //calls TEXT2 subroutine ACALL TEXT3 //calls TEXT3 subroutine ACALL SPLIT //calls SPLIT subroutine ACALL NUM //calls NUM subroutine HERE:JNB PIR,HERE //loops here until PIR output is HIGH SETB P2.0 //sets P2.0 (alarm ON) INC R7 //increments R7 (No: of intrusions) ACALL DINT //calls DINT subroutine ACALL TEXT1 //calls TEXT1 subroutine ACALL LINE2 //calls LINE2 subroutine ACALL TEXT4 //calls TEXT4 subroutine ACALL TEXT3 //calls TEXT3 subroutine ACALL SPLIT //calls SPLIT subroutine ACALL NUM //calls NUM subroutine ACALL SMS //calls SMS subroutine HERE1:JB PIR,HERE1 //loops here PIR output is LOW CLR P2.0 //clears P2.0 (alarm OFF) SJMP MAIN //jumps to MAIN loop SMS:MOV A,#"A" //ascii of A ACALL SEND //sends the ascii code to GSM MOV A,#"T" //ascii of T ACALL SEND //sends the ascii code to GSM MOV A,#0DH //ascii of /r ACALL SEND //sends the ascii code to GSM ACALL DELAY1 //calls DELAY1 (1S) MOV A,#"A" //ascii of A ACALL SEND //sends the ascii code to GSM MOV A,#"T" //ascii of T ACALL SEND //sends the ascii code to GSM MOV A,#"+" //ascii of + ACALL SEND //sends the ascii code to GSM MOV A,#"C" //ascii of C ACALL SEND //sends the ascii code to GSM MOV A,#"M" //ascii of M ACALL SEND //sends the ascii code to GSM MOV A,#"G" //ascii of G ACALL SEND //sends the ascii code to GSM MOV A,#"F" //ascii of F ACALL SEND //sends the ascii code to GSM MOV A,#"=" //ascii of = ACALL SEND //sends the ascii code to GSM MOV A,#"1" //ascii of 1 ACALL SEND //sends the ascii code to GSM MOV A,#0DH //ascii of /r ACALL SEND //sends the ascii code to GSM ACALL DELAY1 //calls DELAY1 (1S) MOV A,#"A" //ascii of A ACALL SEND //sends the ascii code to GSM MOV A,#"T" //ascii of T ACALL SEND //sends the ascii code to GSM MOV A,#"+" //ascii of + ACALL SEND //sends the ascii code to GSM MOV A,#"C" //ascii of C ACALL SEND //sends the ascii code to GSM MOV A,#"M" //ascii of M ACALL SEND //sends the ascii code to GSM MOV A,#"G" //ascii of G ACALL SEND //sends the ascii code to GSM MOV A,#"S" //ascii of S ACALL SEND //sends the ascii code to GSM MOV A,#"=" //ascii of = ACALL SEND //sends the ascii code to GSM MOV A,#34D //ascii of " ACALL SEND //sends the ascii code to GSM MOV A,#"+" //ascii of + ACALL SEND //sends the ascii code to GSM MOV A,#"9" //ascii of 9 ACALL SEND //sends the ascii code to GSM MOV A,#"1" //ascii of 1 ACALL SEND //sends the ascii code to GSM MOV A,#"9" //ascii of 9 ACALL SEND //sends the ascii code to GSM MOV A,#"5" //ascii of 5 ACALL SEND //sends the ascii code to GSM MOV A,#"4" //ascii of 4 ACALL SEND //sends the ascii code to GSM MOV A,#"4" //ascii of 4 ACALL SEND //sends the ascii code to GSM MOV A,#"7" //ascii of 7 ACALL SEND //sends the ascii code to GSM MOV A,#"9" //ascii of 9 ACALL SEND //sends the ascii code to GSM MOV A,#"0" //ascii of 0 ACALL SEND //sends the ascii code to GSM MOV A,#"7" //ascii of 7 ACALL SEND //sends the ascii code to GSM MOV A,#"9" //ascii of 9 ACALL SEND //sends the ascii code to GSM MOV A,#"3" //ascii of 3 ACALL SEND //sends the ascii code to GSM MOV A,#34D //ascii of " ACALL SEND //sends the ascii code to GSM MOV A,#0DH //ascii of /r ACALL SEND //sends the ascii code to GSM ACALL DELAY1 //calls DELAY1 (1S) MOV A,#"I" //ascii of I ACALL SEND //sends the ascii code to GSM MOV A,#"n" //ascii of n ACALL SEND //sends the ascii code to GSM MOV A,#"t" //ascii of t ACALL SEND //sends the ascii code to GSM MOV A,#"r" //ascii of r ACALL SEND //sends the ascii code to GSM MOV A,#"u" //ascii of u ACALL SEND //sends the ascii code to GSM MOV A,#"d" //ascii of d ACALL SEND //sends the ascii code to GSM MOV A,#"e" //ascii of e ACALL SEND //sends the ascii code to GSM MOV A,#"r" //ascii of r ACALL SEND //sends the ascii code to GSM MOV A,#"!" //ascii of ! ACALL SEND //sends the ascii code to GSM MOV A,#"!" //ascii of ! ACALL SEND //sends the ascii code to GSM ACALL DELAY1 //calls DELAY1 (1S) MOV A,#1AH //ascii of CTRL+Z ACALL SEND //sends the ascii code to GSM ACALL DELAY1 //calls DELAY1 (1S) RET //returns from subroutine SEND:CLR TI //clears TI flag of SCON MOV SBUF,A //moves value in A to SBUF register WAIT:JNB TI,WAIT //waits here until TI flag is set RET //returns from subroutine SPLIT:MOV A,R7 //moves the value in R7 to A MOV B,#10D //loads B with 10D DIV AB //divides A with B MOV R6,B //moves the remainder to R6 MOV B,#10D //loads B with 10D DIV AB //divides A with B MOV R5,B //moves the remainder to R5 MOV R4,B //moves the quotient to R4 RET //returns from subroutine TEXT1: MOV A,#"I" //ascii of I ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"N" //ascii of N ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"T" //ascii of T ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"R" //ascii of R ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"U" //ascii of U ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"D" //ascii of D ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"E" //ascii of E ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"R" //ascii of R ACALL DISPLAY //calls DISPLAY subroutine MOV A,#" " //ascii of SPACE ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"A" //ascii of A ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"L" //ascii of L ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"A" //ascii of A ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"R" //ascii of R ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"M" //ascii of M ACALL DISPLAY //calls DISPLAY subroutine RET //return from subroutine TEXT2: MOV A,#"S" //ascii of S ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"C" //ascii of C ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"A" //ascii of A ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"N" //ascii of N ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"I" //ascii of I ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"N" //ascii of N ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"G" //ascii of G ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"." //ascii of . ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"." //ascii of . ACALL DISPLAY //calls DISPLAY subroutine RET //return from subroutine TEXT3: MOV A,#"I" //ascii of I ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"N" //ascii of N ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"T" //ascii of T ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"R" //ascii of R ACALL DISPLAY //calls DISPLAY subroutine RET //return from subroutine TEXT4: MOV A,#"A" //ascii of A ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"L" //ascii of L ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"E" //ascii of E ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"R" //ascii of R ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"T" //ascii of T ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"!" //ascii of ! ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"!" //ascii of ! ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"!" //ascii of ! ACALL DISPLAY //calls DISPLAY subroutine MOV A,#"!" //ascii of ! ACALL DISPLAY //calls DISPLAY subroutine RET //return from subroutine NUM:MOV A,R4 //moves 1st digit to A ACALL ASCII //calls ASCII subroutine ACALL DISPLAY //calls DISPLAY subroutine MOV A,R5 //moves 2nd digit to A ACALL ASCII //calls ASCII subroutine ACALL DISPLAY //calls DISPLAY subroutine MOV A,R6 //moves last digit to A ACALL ASCII //calls ASCII subroutine ACALL DISPLAY //calls DISPLAY subroutine RET //return subroutine DINT:MOV A,#0FH //loads a with 0FH ACALL CMD //calls CMD subroutine MOV A,#01H //loads a with 01H ACALL CMD //calls CMD subroutine MOV A,#06H //loads a with 06H ACALL CMD //calls CMD subroutine MOV A,#81H //loads a with 81H ACALL CMD //calls CMD subroutine MOV A,#3CH //loads a with 3CH ACALL CMD //calls CMD subroutine RET //return from subroutine LINE2:MOV A,#0C0H //loads a with 0C0H ACALL CMD //calls CMD subroutine RET //return from subroutine CMD: MOV P0,A //loads P0 with A CLR RS //clears RS pin CLR RW //clears RW pin SETB E //sets E pin CLR E //clears E pin ACALL DELAY //calls DELAY subroutine RET //return from subroutine DISPLAY:MOV P0,A //loads P0 with A SETB RS //sets RS pin CLR RW //clears RW pin SETB E //sets E pin CLR E //clears E pin ACALL DELAY //calls DELAY subroutine RET //return from subroutine DELAY1:MOV R6,#15D //loads R6 with 15D BACK: MOV TH0,#00000000B //loads TH0 with 00B MOV TL0,#00000000B //loads TH0 with 00B SETB TR0 //starts Timer 0 HERE2: JNB TF0,HERE2 //loops here until TF0 is set (roll over) CLR TR0 //stops Timer 0 CLR TF0 //clears TF0 DJNZ R6,BACK //jumps to BACK label (loops 15 times) RET //return from subroutine DELAY: CLR E //clears E CLR RS //clears RS SETB RW //sets RW MOV P0,#0FFh //writes P0 with all 1's SETB E //sets E MOV A,P0 //moves P0 to A JB ACC.7,DELAY //jumps to label DELAY when ACC.7 is set CLR E //clears E CLR RW //clears RW RET //return from subroutine ASCII: MOVC A,@A+DPTR //overwrites A with ascii of data in A RET //return from subroutine LUT: DB 48D //ascii of 0 DB 49D //ascii of 1 DB 50D //ascii of 2 DB 51D //ascii of 3 DB 52D //ascii of 4 DB 53D //ascii of 5 DB 54D //ascii of 6 DB 55D //ascii of 7 DB 56D //ascii of 8 DB 57D //ascii of 9 END //END statement
Notes.
- GSM modules available in the market comes with different supply voltages like 12V, 9V, 5V etc. The module I am using here operates on 12V DC. So make sure that your GSM module is operating on correct supply voltage.
- Make sure that all ground lines of (GSM module. PIR sensor module and rest of the circuit) are shorted together.
1 Comment
Thanks Praveen, today I learned a lot about PIR sensor. I was quite confused regarding this area but now the doubts are clear.