Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

GSM Based Intruder Alerting System

By Ganesh Selvaraj March 24, 2014

 

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.

Image showing different sections of GSM Modem

Fig. 1: Image showing different sections of GSM Modem

Step 1: Inserting the SIM

Image showing SIM Card inserted to its slot on GSM Modem

Fig. 2: Image showing SIM Card inserted to its slot on GSM Modem

 

Image showing safely inserted SIM Card on GSM Modem

Fig. 3: Image showing safely inserted SIM Card on GSM Modem

 

Image showing locking mechanism for 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

Image showing Antenna attached SMA connector on GSM Modem

Fig. 5: Image showing Antenna attached SMA connector on GSM Modem

Step 3: Attaching the power supply and Powering the modem

Image showing power adaptor connection to GSM Modem

Fig. 6: Image showing power adaptor connection to GSM Modem

Step 4: Attaching the RS232 to USB Converter

Image showing RS232 port on RS232 to USB Connector

Fig. 7: Image showing RS232 port on RS232 to USB Connector

 

Image showing USB connection to GSM Modem

Fig. 8: Image showing USB connection to GSM Modem

Step 5: Testing the modem through a PC/ Laptop

Block Diagram of GSM Modem interfacing with PC

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.

Screenshot of Serial Terminal on Windows

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.

Circuit Diagram of Amplifier to boast signal for PIR Sensor

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:

Image showing message received on a mobile phone on detection of an intruder

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!='')
{
BlueWrChar(*msg);
msg++;
}
BlueWrChar(13);
}
void BlueWrCMD(const char *msg)
{
while(*msg!='')
{
BlueWrChar(*msg);
msg++;
}
}
void Waiting(int j) // simple delay function
{
uint8_t i;
for(i=0;i<j;i++)
_delay_ms(200);
}
void Notify()
{
BlueWrString("AT+CMGF=1");
Waiting(1);
BlueWrCMD("AT+CMGS=");
BlueWrChar(34);  // "
BlueWrCMD("+91xxxxxxxxxx"); // Replace the 'x's with a valid Phone number
BlueWrChar(34);
BlueWrChar('');
BlueWrChar(13); // <CR> OR r
Waiting(1);
BlueWrCMD("MOTION DETECTED");
BlueWrChar(26);  // CTRL+Z
Waiting(15);
clrscr();
LCD_write_string("  MESSAGE SENT  ");
Waiting(30);
}
int main()
{
DDRB=0b11111110;
PORTB=0b00000001;
BlueInit(); // initialization of USART
lcd_init();
LCD_write_string("   GSM BASED    ");
gotoxy(1,0);
LCD_write_string("INTRUDER ALERTER");
Waiting(10);
clrscr();
gotoxy(0,7);
LCD_write_string("BY");
gotoxy(1,0);
LCD_write_string("GANESH SELVARAJ");
BlueWrString("AT");
Waiting(10);
clrscr();
LCD_write_string(" SYSTEM ACTIVE!");
while(1)
{
if(PIR==0)
{
clrscr();
LCD_write_string("MOTION DETECTED");
Notify();
Waiting(10);
clrscr();
LCD_write_string(" SYSTEM ACTIVE!");
}
}
return 0;
}


LCD Program



#ifndef LCD_H_
#define LCD_H_
#define rs PA7
#define rw PA6
#define en PA4
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>
#include<inttypes.h>
void lcd_init();
void dis_cmd(char);
void dis_data(char);
void lcdcmd(char);
void lcddata(char);
void clrscr();
void gotoxy(char,char);
void LCD_write_string(const char *);
void LCD_write_string(const char *str) //store address value of the string in pointer *str
{
int i=0;
while(str[i]!='') // loop will go on till the NULL character inthe string
{
dis_data(str[i]); // sending data on LCD byte by byte
i++;
}
return;
}
void lcd_init() // function for initialize
{
DDRA=0xFF;
dis_cmd(0x02); // to initialize LCD in 4-bit mode.
dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x80); // 8-- 1st line 0- 0TH position
}
void dis_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1 = ((cmd_value>>4) & 0x0F); //shift 4-bit and mask
lcdcmd(cmd_value1); // send to LCD
cmd_value1 = cmd_value & 0x0F; //mask lower nibble because PA4-PA7 pins are used.
lcdcmd(cmd_value1); // send to LCD
}
void dis_data(char data_value)
{
char data_value1;
data_value1=((data_value>>4)&0x0F);
lcddata(data_value1);
data_value1=data_value&0x0F;
lcddata(data_value1);
}
void lcdcmd(char cmdout)
{
PORTA=cmdout;
PORTA&=~(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);
}
void lcddata(char dataout)
{
PORTA=dataout;
PORTA|=(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);
}
void clrscr()
{
_delay_ms(100);
dis_cmd(0x01);
_delay_ms(10);
}
void gotoxy(char a,char b)
{
if(a==0)  a=0b10000000;
else if(a==1) a=0b11000000;
dis_cmd(a|b); 
}
#endif

###

 


Circuit Diagrams

Circuit-Diagram-AVR-ATMega16-GSM-Module-Based-Intruder-Mobile-Alarm-System

Project Video


Filed Under: Electronic Projects
Tagged With: atmega16, avr, intruder alarm, pir sensor, sim card
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • DC/DC Converter with wide range input
  • i need an embedded c program that will read a 12 bit memory address from the io pins and output the data to pins from the memory in a 8051 mcontroller
  • schematic of the Current 4~20mA to Voltage 3.3/5/10VDC Converter HW-685
  • Does mobility carrier ratio changes with Wn? (0.18um) inverter design
  • Gate Driver Suggestions for Two-Switch Non-Inverting Buck-Boost Converter

RSS Electro-Tech-Online.com Discussions

  • 12v battery, 18v magic
  • JBL charge 4 dead motherboard?
  • Back to the old BASIC days
  • Reclaiming missing motherboard header
  • Need help in repairing a dead motherboard

Featured -USB Series

  • Controller Chip Selection for Developing USB Enabled Device (Part 6/6)
  • Signal and Encoding of USB System (Part 5/6)
  • USB Requests and Stages of Control Transfer (Part 4/6)
  • USB Descriptors and their Types (Part 3/6)
  • USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)
  • Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Recent Articles

  • Littelfuse driver achieves less than 1 µA standby current for energy-efficient designs
  • Microchip optimizes power consumption in transceiver-less FPGA design for automotive applications
  • What is an IoT platform and when is one useful?
  • Silanna launches laser driver IC with sub-2 ns FWHM pulse for LiDAR application
  • LEM introduces current sensors with bandwidth up to 2.5 MHz for precision applications

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe