Did you know that most of the thefts at home happen when it is empty? But not everyone is rich enough to hire a security for their house and at the same time they themselves cannot be at home 24×7. Now what if there is a system which alerts you about an intruder through a text message? The following tutorial discusses how to make you own intruder alerting system.For this project Reader Should have knowledge of how to start with AVR and interface LCD with AVR.
Components Required
1. PIR Sensor
2. ATMega16 Development board
3. LCD board
4. SIM 300/900 GSM Module
5. 12V/2A Power Supply
6. SIM card with balance (or at least message offer maybe)
7. A PC or a Laptop (Optional. Needed in case of debugging)
Initial Setup and Testing of GSM modem
If you are already familiar with a GSM Modem then you may skip this step. This part of the tutorial is for the beginners or you can learn How to interface GSM with AVR.
Fig. 1: Image showing different sections of GSM Modem
Step 1: Inserting the SIM
Fig. 2: Image showing SIM Card inserted to its slot on GSM Modem
Fig. 3: Image showing safely inserted SIM Card on GSM Modem
Fig. 4: Image showing locking mechanism for SIM card on GSM Modem
Step 2: Attach the antenna to the SMA connector shown in the picture
Fig. 5: Image showing Antenna attached SMA connector on GSM Modem
Step 3: Attaching the power supply and Powering the modem
Fig. 6: Image showing power adaptor connection to GSM Modem
Step 4: Attaching the RS232 to USB Converter
Fig. 7: Image showing RS232 port on RS232 to USB Connector
Fig. 8: Image showing USB connection to GSM Modem
Step 5: Testing the modem through a PC/ Laptop
Fig. 9: Block Diagram of GSM Modem interfacing with PC
Once you have connected the modem and PC, you can open your default serial communication software on your PC and start sending AT commands to the modem and observing its replies.
Fig. 10: Screenshot of Serial Terminal on Windows
As you can see from the above screen shot, when I sent “AT”, the modem sends back “OK”. Similarly after every correct command the modem would reply with necessary parameters and an “OK”. If you enter any wrong or inappropriate command then the modem says “ERROR”
Why PIR sensor?
Well PIR sensors are designed to detect human beings specifically and so there is very low chance for a false alarm. You can use Infrared TX-RX pair also but their range is lesser and there is more probability for false alarm. Say, for example a cat comes close to the sensor’s field range or if there is a light variation in the room where you fixed the sensor. In both cases the IR sensor would react and generate a false alarm but PIR sensor will remain immune.
Amplifier Circuit & Code Explanation
Since the output signal from the PIR is very weak we use a simple amplifier circuit to get a stronger output.
Fig. 11: Circuit Diagram of Amplifier to boast signal for PIR Sensor
Code Explanation
– Initialize the USART and LCD functions
– Assign PB0 as input pin and put it in HIGH state
– Enter an infinite loop
– Check the status of PB0 pin. If it goes low, then go to Notify() function
Notify() function sends the following commands:
Command |
Description |
AT+CMGF=1<CR> |
To set the Message Format into Text mode. 1 is for Text mode and 0 is for PDU mode. |
AT+CMGS=”+919876543210”<CR> >Motion Detected<Ctrl+Z> |
Send the text “Motion Detected” to the number given inside the quotes. |
|
|
Here <CR> is nothing but the special character ‘r’ whose ASCII code is 13. Ctrl+Z has a ASCII code of 26
Testing & Troubleshooting
Testing the System
1. Connect everything according to the circuit diagram after burning the program into the microcontroller.
NOTE: TX of modem <-> RX of controller
RX of modem <->TX of controller
GND of modem <-> GND of controller
2. Place the PIR sensor facing away from you before you power ON the system.
3. Now power ON the system.
4. Wait a while for the SIM to get registered to the Network. It may take from 10-50 seconds for that. (You can know if it is registered or not by observing the network LED status. If the blinking rate is very low then it means the SIM is ready now)
5. Wave your hand in front of the PIR sensor. Now you should see the LED attached to the amplifier circuit light up and the LCD displaying “Motion Detected”. Within few seconds, you should get a message to the number you have given in the program. Like this:
Fig. 12: Image showing message received on a mobile phone on detection of an intruder
Troubleshooting
A. The SIM is not getting registered to the network
Possible Reasons:
1. The signal strength of the modem maybe weak. Make sure the Antenna is fixed firmly
2. Make sure the Network provider gives enough signal strength in your area and there are no jammers around.
3. Make sure the SIM card is valid.
B. Message not received by the user’s phone
Possible Reasons:
1. Check your program and see if you gave the right phone number or not.
2. See if the user’s phone has enough signal strength to receive a message.
3. You waved it too soon after powering ON the device. Remember the SIM card takes time to get registered to a Network.
4. There is no balance in the SIM card. Make sure the SIM card has some balance or a message offer.
Project Source Code
### Main Program /* * sim1way.c * * Created: 1/12/2014 3:14:58 PM * Author: Ganesh Selvaraj */ #define F_CPU 16000000UL #define USART_BAUDRATE 9600 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) #define PIR (PINB & 0b00000001) #include<avr/io.h> #include<util/delay.h> #include "lcd.h" void BlueInit() { UCSRB |= (1 << RXEN) | (1 << TXEN); // Enable transmission and reception UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes UBRRL = BAUD_PRESCALE; UBRRH = (BAUD_PRESCALE >> 8); } void BlueWrChar(unsigned char d) { while ((UCSRA & (1 << UDRE)) == 0); // wait till UDR is ready UDR = d; // send data } unsigned int BlueRdChar() { while ((UCSRA & (1 << RXC)) == 0); // wait until data has been received return(UDR); // return the byte } void BlueWrString(const char *msg) { while(*msg!='