Telephone Security System With Arduino
by fcodiegomoreira in Circuits > Arduino
926 Views, 2 Favorites, 0 Comments
Telephone Security System With Arduino
Your home will be unprotected if you do not apply this project. This project will help you trigger an alarm via cell phone when an intruder breaks into your home.
That way, if you use this project, you will receive an SMS via cell phone and will be able to keep your home protected in case of invasions.
For this, we will use the Arduino Compatible Board with the SIM800L Module and PIR Sensor. The PIR sensor will be responsible for detecting the presence of an intruder and the SIM800L will be responsible for sending an alert SMS to the home owner.
Supplies
- Arduino Compatible Board
- Sensor PIR
- Resistor 10kR
- Jumpers
- Protoboard
- SIM800L Module
The Heart of the Project
The heart of the project is the SIM800L module. This module will be able to receive Arduino commands and send SMS to the user's cell phone. That way, when the user receives the alert, he can call the police or perform any other type of action.
The Arduino Compatible Board will be responsible for checking the state of the sensor and will then send an alert message to the user if it detects the presence of an intruder.
This process is carried out thanks to the control commands between the Arduino and the SIM800L Module. Therefore, from that, we will introduce you step by step for you to build this system, leave your home protected and warn you whenever any intruder invades it.
If you want to download the Arduino Compatible Board, you can access this link and get the files to buy your boards at JLCPCB.
Now, let's get started!
The Project Electronic Circuit and the Programming
First, we will make the electronic circuit available and then we will discuss the project code step by step for you.
<p>#include <SoftwareSerial.h><br>SoftwareSerial chip(10, 11);</p><p>String SeuNumero = "+5585988004783";</p><p>#define sensor 12</p><p>bool ValorAtual = 0, ValorAnterior = 0;</p><p>void setup() { Serial.begin(9600); Serial.println("Inicializando Sistema..."); delay(5000); chip.begin(9600); delay(1000);</p><p> pinMode(sensor, INPUT); //Configura o Pino do Sensor como Entrada }</p><p>void loop() { //Le o valor do pino do sensor ValorAtual = digitalRead(sensor);</p><p> if(ValorAtual == 1 && ValorAnterior == 0) { IntrudeAlert; ValorAnterior = 1; }</p><p> if(ValorAtual == 0 && ValorAnterior == 1) { NoMoreIntrude(); ValorAnterior = 0; }</p><p>}</p><p>void IntrudeAlert() //Funcao para enviar mensagem de alerta Umidade Baixa { chip.println("AT+CMGF=1"); delay(1000); chip.println("AT+CMGS=\"" + SeuNumero + "\"\r"); delay(1000); String SMS = "Intrude Alert!"; chip.println(SMS); delay(100); chip.println((char)26); delay(1000); }</p><p>void NoMoreIntrude()//Funcao para enviar mensagem de alerta Umidade Normal { chip.println("AT+CMGF=1"); delay(1000); chip.println("AT+CMGS=\"" + SeuNumero + "\"\r"); delay(1000); String SMS = "No More Intrude!"; chip.println(SMS); delay(100); chip.println((char)26); delay(1000); }</p>
In the code shown below, we initially declared the serial communication library SoftwareSerial.h, as shown below.
#include <SoftwareSerial.h>
After defining the library, the communication pins Tx and Rx were defined. These pins are alternate pins and are used to allow serial communication on other Arduino pins. The SoftwareSerial library was developed to allow you to use the software to replicate the functionality
SoftwareSerial chip(10, 11);
After this, the cellphone number was declared was is shown below.
String SeuNumero = "+5585988004783";
The electronic design scheme is simple and easy to assemble. As you can see on the circuit, the Arduino Compatible Board is responsible for reading the sensor status and then sending an SMS to the home owner.
The message will be sent if an intruder is detected inside the house. The PIR (Passive Infra Red) Sensor is a sensor used to detect movement from the infrared signal. From the signal sent to the Arduino, the SIM800L module will send a message to the user.
The Diode will be used to provide a voltage drop to supply the SIM800L module. Since the module cannot be powered with 5V. In this way, a voltage of 4.3V will arrive to power your module and ensure that it works safely.
The Void Setup() Function
In the void setup function, we will initialize the serial communication and configure the sensor pin as an input. The region of the code is presented below.
<p>void setup()</p><p>{ </p><p>Serial.begin(9600); Serial.println("Inicializando Sistema...");<br>delay(5000); chip.begin(9600); delay(1000); pinMode(sensor, INPUT); //Configura o Pino do Sensor como Entrada }</p>
As is possible to see, the two serial communication was initialized. The Serial.begin is used to initialize the native serial of the Arduino and the chip.begin is the serial emulated through the SoftwareSerial library. After this, we will for the void loop function.
The Project and the Void Loop Function
Now, we will present the main logic of programming in the void loop function.
<p>void loop()<br>{ //Le o valor do pino do sensor ValorAtual = digitalRead(sensor);</p><p> if(ValorAtual == 1 && ValorAnterior == 0) { IntrudeAlert();</p><p> ValorAnterior = 1; }</p><p> if(ValorAtual == 0 && ValorAnterior == 1) { NoMoreIntrude();</p><p> ValorAnterior = 0; }</p><p>}</p>
First, the signal from the PIR presence sensor will be read as is shown below.
<p>ValorAtual = digitalRead(sensor);</p>
After this, it will be verified if the value in variable ValorAtual it is 1 or 0, as is shown below.
<p>if(ValorAtual == 1 && ValorAnterior == 0)<br> { IntrudeAlert();</p><p> ValorAnterior = 1; } if(ValorAtual == 0 && ValorAnterior == 0) { NoMoreIntrude();</p><p> ValorAnterior = 0; }</p>
Case the variable ValorAtual it's 1 and the variables ValorAnterior it's 0, the sensor actually is activated and anteriorly it's deactivated (ValorAnterior == 0). In this way, the function will be executed and the user will receive the message on your cellphone. After this, the value of the variable ValorAnterior will be equal at 1.
In this way, the variable ValorAnterior will be signalized that the actual state of the sensor is actuated.
Now, case the value of the variable ValorAtual is 0 and the value of the ValorAnterior variable it is equal at 0, the sensor doesn't detect intrude and then its value is actuated.
In this way, the system will send the message for the cellphone of the user and will update the actual value of the sensor for 0. This value will indicate that the sensor is doesn't actuate at the moment.
The messages that were sent for the user are presented above.
Now, we'll learn how to work the function to send the messages for the user's cellphone.
Functions to Send Messages
In this system, there are two functions. They are functions with the same structure. The difference between them is the name and the message sent, but when we analyze it, we will see that they are completely the same.
Next, we will present the complete structure of the functions and discuss the code.
void IntrudeAlert() //Funcao para enviar mensagem de alerta Umidade Baixa
{ chip.println("AT+CMGF=1"); delay(1000); chip.println("AT+CMGS=\"" + SeuNumero + "\"\r"); delay(1000); String SMS = "Opened Door!"; chip.println(SMS); delay(100); chip.println((char)26); delay(1000); }void NoMoreIntrude()//Funcao para enviar mensagem de alerta Umidade Normal { chip.println("AT+CMGF=1"); delay(1000); chip.println("AT+CMGS=\"" + SeuNumero + "\"\r"); delay(1000); String SMS = "Closed Door!"; chip.println(SMS); delay(100); chip.println((char)26); delay(1000); }
The SIM800L Module uses the AT Command to control its functions. Therefore, through these commands, we'll send the message for the user's cellphone.
The AT+CGMF = 1 is used to configure the module to work in SMS Text mode. After the delay, the system will send the message for the user through the following command.
chip.println("AT+CMGS=\"" + SeuNumero + "\"\r");
In the command, the SIM800L module will be prepared to send a message for the cellphone number registered in the string SeuNumero. After this, the system will load the message in the string and will send for the user's cellphone, as is shown below.
String SMS = "Closed Door!";
chip.println(SMS); delay(100); chip.println((char)26); delay(1000);
The char(26) is used to signalize the end of the message. This working process is similar for two functions to send a message for the user.
Acknowledgments
Now, we appreciate the support of JLCPCB to carry out this work and, if you are interested, access the following link and download the Arduino Compatible Board.