Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Arduino home security system using Sim900 Gsm module, Pir motion detector and magnetic door contact switch

By EG Projects

​In this tutorial i am going to make an arduino home security system. One can install this diy arduino security system project on his home main door. The diy arduino security system checks two things. First it checks if some one approached the door? Second it checks if door is opened by the person? When the former two conditions meet an sms/text message will be send to the owner of the house. The presence/motion of the person in front of the door is detected by the pir motion detector and door opening is checked by door contact switch OR reed switch. Both the sensors(pir motion and reed switch) are connected to arduino uno and any intrusion detected by the sensors is conveyed instantly to arduino uno. Arduino as an intrusion alert sends a sms/text message to the owner mobile number using gsm module.

Arduino Gsm Pir and door sensor security system

Arduino Gsm Pir and door sensor security system

PIR motion detection sensor

I used popular hcsr501 passive infrared motion detection sensor in the diy project. It can detect motion at a max distance of 7 meters. Sensitivity range of hcsr501 pir motion detector can be set by rotating the variable resistor/potentiometer mounted on the circuit board of hcsr501 pir motion sensor. It also has a second variable resistor/potentiometer which is used to set the delay time i will talk about it later(With Out pin of Hcsr501). Hcsr501 pir sensor has 3 pin. Two are power pins. Vcc is connected to +ve lead of power supply and Gnd is connected to -ve of power supply. The third pin is out pin. It normally remains low. When pir sensor detects presence of infrared emitting body in its range it sets the out pin high. Now the question is For how long does pir out pin remains high once the presence of person is detected? For this purpose the second variable resistor/potentiometer is present on hcsr501 pcb board you can set the delay time or out pin high time using the second variable resistor.
So where the pir sensor is to be mounted in order to detect the presence of person. It must be mounted on the upper portion of inlet of door. Below diagram best illustrates the mounting of pir above the door. 

Picture

Pir sensor installation above door and area covering angle.

Sim900 Gsm module(Arduino Gsm)

I am using SainSmart Sim900 GPRS/Gsm Module in the project. Its easy to use and its documentation is pretty straight forward. I worked with many other gsm modules build on SIMCom sim900 chip. I found SaintSmart to be best of all. The Chinese cheap sim900 gsm modules are really hard to use and due to bad circuit designs their power requirements differ from each other. SaintSmart gsm module works on 5 volts. It has five pins. In five three are power pins. Two ground pins and one +ve power pin. We supply power 5 volts to +ve pin and ground the Gnd pins. The remaining two pins are Uart pins.
All sim900 gsm modules communicates with external controllers/microcontrollers on Uart protocol. Uart protocol has two pins. One is TxD(Transmit) and other is RxD(Receive). In order to send and receive data to sim900 gsm module the external microcontroller must also have a Uart port. In simple words Uart communication takes place between two Uart ports. Gsm sim900 module has Uart port so our external microcontroller must also have one to communicate with gsm module. In Uart communication we connect TxD pin of first device to RxD of second one. Similarly Rxd of first one is connected with TxD of second one. After connection we set the baud rate of communication in software. Baud rate is simply the speed of communication between two devices communicating on Uart port. In circuit diagram of the project it will be cleared to you about uart connections.
Sim900 gsm module works on AT command set. Their are lot of AT commands if you go through the data sheet of sim900 chip set. We will use in our project only ones which a necessary to send an sms text message. I have an another tutorial on how to send an Sms with sim900 gsm module. You can visit it by clicking the below button.  

Gsm Arduino: Send an sms with Sim900

Door contact switch/Reed switch

A reed switch is an electrical device operated using a magnet in place. It consists of two half’s. One half contains actual switch and the other half contains just a magnet in it. When the magnetic half is brought near the switch half it starts conducting electricity. So how does it all happens? Actually the switch half contains a pair of magnetic rods. Normally when their is no magnetic filed present near switch the rods are a part from each other(Open circuit – No electric path). When we bring the magnetic half near the switch half the magnetic field brings the rods close and when the strength of magnetic field reaches the threshold limit the rods attach with each other(Making a physical contact – Path for electricity flow).
How to install the door reed switch? We usually mount the switch half on fix/immovable surface and the magnetic half is installed on the moving surface. In our case, i installed the magnetic half on door and the switch half on the wall near to door closing point. Both half’s must be in correct position and at correct distance to make a contact. Below you can see the correct placement and installation of door contact sensor.   

Door contact reed switch installation

Door contact reed switch installation
The block and flow diagram of the aduino home security system is given below. Pir motion detector and magnetic door switch sends their respective status to arduino. Arduino then decides what to do next with the inputs from pir and door sensor. If arduino finds both the sensors transmitted the positive status. It alerts the gsm module to activate and send a text sms on hard coded single sim number.  

Arduino home security system block diagram

Arduino home security system block diagram

Arduino Home Security – Project circuit diagram

Coming to the project circuit diagram. Only four I/O pins of arduino uno are used in the project. Two pins are of Uart channel Pin#0 and 1 of arduino uno. The other two are Pin#8 and 9. Pin#8 of arduino uno is connected to pir motion sensor out pin and pin#9 of arduino uno is connected to door contact sensor. Pir motion detector and door contact sensor can be powered through the arduino +5 volt output. But i prefer to use an external power supply for powering the pir and door sensor.
Door contact switch can be powered from +5v to +12v. I powered it with 5v power supply. If you input +12 volt to reed switch then you might need to insert a resistor in series with the reed switch because arduino pins are 5 volt tolerant and +12v(when contact is made) can destroy the input pin of arduino. When contact is made by reed switch the input voltage appears on the arduino digital pin. In our case on Door(Pin#9) pin. If the voltage is above 5 v it might destroy the input pin of arduino. So be careful before powering the reed switch.
Note: I write +12 v due to the fact that door sensor is installed at a distance from the main microcontroller(Arduino our case) and after contact the voltage drops across wire due to length of the wire.  

Gsm module needs an extra power during sms sending time. Use an adopter which can supply continuous 1 Ampere of current at 5 volts for powering sim900 gsm module. 1 ampere adopter is enough to power all the components(Arduino, Pir, Reed switch and Gsm module) used in the project circuit.

Arduino home security system with pir, gsm and door contact switch

Arduino home security system with pir, gsm and door contact switch
Coming to the code portion of the security project. First i defined the arduino digital pins which are going to interface with the pir motion detector and door contact switch(Arduino Pin#8 and 9). In the setup function i declared both the pins (Arduino Pin#8 and 9) as input. Since we are reading the status of the sensors so we must declare them input. After declaring the arduino sensor interfacing pins as input. I went on for the Uart module of arduino. Arduino Uart module is present on arduino pin#0 and 1. To declare and start the arduino uart module in arduino ide we use Serial.begin() command. To set the communication baud rate we insert the baud rate value in circular brackets after the word begin. In our case i set the communication rate at 9600 bits per second and command used to initialize it is Serial.begin(9600).   

In the loop function two variables are declared S1 and S2. Both variables are used to store the status of the pir and door sensor. The statement S1=digitalRead(door) is checking the status of the door sensor and storing the status in S1 variable. The statement S2=digitalRead(Out) is checking the status of pir and storing its status in S2 variable. Next an if statement is comparing the status of both sensors/variable(S1 and S2). If pir output is high and contact sensor is low then the control enters the body of if statement. In if statement body AT commands are used for sending a text message on a particular cell number.
​
For sending commands out by arduino on its Uart port Serial.println() statement is used in arduino ide. First  “AT+CMGF=1” is send. This command sets the sim900 gsm module in sms text mode. Then “AT+CMGS=” is send with “\”+923425500809\””. Its actually the recipient sim number or the number to which we want to send the sms. Back slash in the last statement is preventing the double quotations to be executed by arduino ide. Sim900 requires mobile number to be enclosed in double quotations. After the number comes the body/text of the sms. I am sending my website name www.microcontroller-project.com as text. You can send what ever you want. Then comes the most important statement Serial.write(26). To end message and to send it sim900 requires Ctrl+Z command. If we translate the Ctrl+Z in ascii code it translates to ’26’. So at the end of the code we are sending Ctrl+Z command to sim900 to send the text message.      

Future Work
The project can be further upgraded by controlling the other appliances like light and alarms etc if any threat is detected. Arduino relay board containing multiple relays can be used to switch on and off the peripherals(lights, alarm). Beside an sms alert message an email can also be send to the house owner by utilizing the GPRS function of sim900 gsm/gprs module.

code/files

Filed Under: Arduino, Electronic Projects, Microcontroller Projects

 

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.

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!


Featured Tutorials

  • Adjustable 0 to 30V 2A DC Power Supply Circuit (Part 1/13)
  • Adjustable +/- 1.25V to +/-22V 1A Power Supply Circuit (Part 2/13)
  • Adjustable 0 to 15V 1A Mini Power Supply (Part 3/13)
  • Constant 12V Power Supply for LED Circuits (Part 4/13)
  • Constant +/-9V DC Symmetrical Power Supply Circuit (Part 5/13)
  • Making a Circuit Breaker (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • STMicroelectronics and MACOM announce successful RF GaN-on-Si prototypes
  • Infineon expands its CoolSiC portfolio
  • STMicroelectronics and AWS collaborate for secure IoT connections
  • Pet feeding system using WhatsApp (protocol bridging with MQTT)
  • STMicroelectronics launches new MDmesh MOSFETs

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics Research robot samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • P-Channel MOSFET always on
  • Space Vector PWM Help Needed
  • DIY test leads - source for lead ends?
  • hardcore floquet bloch scattering problem help
  • Limiting variable DC power source

RSS Electro-Tech-Online.com Discussions

  • 24v dc relays not de-energising
  • How do I test amplifier speaker output polarity?
  • How to get lots of PCBs made cheap?
  • XOR Gate Circuit From Diodes
  • 3.3V microcontroller vs 5V relay
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 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 | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering