Arduino gsm alarm project. Wireless alarm system based on Arduino

To protect your home from uninvited guests, everything more people install alarms. They allow timely warning of intrusion into the premises. Today there are various types alarms, but in lately The popularity of GSM alarms has begun to grow, since they allow you to receive information about intrusion at any distance from an object, the main thing is that the owner has a phone with him at the time, and this phone is online. Unfortunately, these systems are not yet too cheap to give preference exclusively to them. But nowadays you can make a simple GSM alarm yourself. And the popular Arduino board will help in this matter.


This project is a security (alarm) system to notify of intruders entering the house. The system uses GSM technology.



An intrusion detection module is connected to the microcontroller board of this security system, which can be based, for example, on an IR sensor or an ultrasonic proximity sensor. When a signal is received from such a module, an SMS message is sent to the user’s phone indicating that their home has been broken into.


The figure below shows a block diagram of the security system.



The main elements of the system are the microcontroller board (for example, Arduino Uno) and GSM/GPRS module SIM900A. The entire system can be powered from a single 12V/2A power supply.


The image below shows circuit diagram home system security with GSM based on Arduino.



The operation of the system is very simple and does not require much explanation. When the power supply is applied, the system goes into standby mode. However, when J2 is short-circuited, a warning message is automatically transmitted to a preset number mobile phone. Any detection sensor can be connected to the J2 input connector. It should be noted that a low level on pin 1 of J2 is active and turns on the security system.


In addition, the system has added the ability to make a call by pressing the S2 button. Using the S3 button you can reset this call.


Below is the code for Arduino.


//Connect the Tx pin to pin D3 of the GPS module //Connect the Rx pin to pin D4 of the GPS module //connect the SMS sending signal to pin D7 (active level low) //Connect the CALL signal to pin D8 (active level low) //Connect the call reset signal END to pin D9 (active level low) #include NewSoftSerial mySerial(3,4); // configure the RX and TX pins for communication with the GSM module #define msg_key 7 #define call_key 8 #define end_key 9 String number ="0000000000"; // Here, instead of zeros, you need to enter a 10-digit mobile number void setup() ( Serial.begin(9600); mySerial.begin(9600); pinMode(msg_key,INPUT); pinMode(call_key,INPUT); pinMode(end_key,INPUT ); digitalWrite(msg_key,HIGH); digitalWrite(call_key,HIGH); digitalWrite(end_key,HIGH); void loop() ( //send sms every time msg_key is triggered if (digitalRead(msg_key)==LOW) / / Checking whether the send sms button is pressed ( mySerial.println("AT+CMGF=1"); // Set the mode as text mode delay(150); mySerial.println("AT+CMGS=\"+00"+ number+"\""); // Specify the recipient's number in international format, replacing zeros delay(150); mySerial.print("Warning! Intruder Alert!"); // Enter a message delay(150); mySerial.write(( byte)0x1A); // End of message character 0x1A: equivalent to Ctrl+z delay(50); mySerial.println(); ) // Make a call when call_key is triggered else if (digitalRead(call_key)==LOW) // Check , whether call_key has already been pressed ( mySerial.println("ATD+91"+number+";"); //Determine the number to call while(digitalRead(call_key)==LOW); delay(50); ) //Reset the call else if (digitalRead(end_key)==LOW) //Check if the call reset button is already pressed ( mySerial.println("ATH"); while(digitalRead(end_key)==LOW); delay(50 ); ) )

Thus, you can quite easily create a GSM alarm system based on the Arduino board with your own hands. Such an alarm system, in terms of its cost, will certainly be cheaper than branded analogues on the market today, and it will function in an almost identical way.

Main modules– GSM module SIM800L, Arduino Nano (you can use any Uno, etc.), step-down board, cell phone battery.

Rice. 1. Module layout burglar alarm on Arduino

Alarm production

We mount it on a breadboard through pads, which will allow you to replace modules if necessary. Turn on the alarm by supplying 4.2 volt power through the switch on SIM800L and Arduino Nano.



When the first loop is triggered, the system first calls the first number, then drops the call and calls back to the second number. The second number was added just in case if the first one is suddenly disconnected, etc. When the second, third, fourth, and fifth loops are triggered, an SMS with the number of the triggered zone is sent, also to two numbers. The diagram and sketch for those interested are in the description under the video.
We place all electronics in a suitable housing.



If you don't need 5 cables, connect the 5V Arduino pin to the unneeded inputs. GSM alarm system with 5 loops and a battery, which will allow the device to continue working autonomously for several days, even during a power outage. You can connect any security contact sensors, relay contacts, etc. to them. As a result, we get a simple, inexpensive, compact security device for with SMS transmission and dialing to 2 numbers. It can be used to protect a dacha, apartment, garage, etc.

More details in the video

Today we will talk about how to use Arduino collect security system. Our “security” will guard one circuit and control one siren.

For Arduino this is not a problem, and, as you will see from the program code and the device diagram, you can easily increase the number of protected access points and the number of notification or indication devices.
Security system can be used to protect both large objects (buildings and structures), and small items (boxes, safes), and even portable cases and suitcases. Although you need to be careful with the latter, if you install a security system, for example, on a suitcase with which you decide to travel, and the warning system goes off at some airport, then I think you will have a serious conversation with the local security service :-)

A simplified operating principle of the device is as follows (Fig. 1). After turning on the power, the device goes into operating mode and waits for arming. Arming and disarming are carried out with one button. To increase security, it is better to place this button inside a protected area (safe or box). Before turning on the security mode, the door must be opened slightly. When you turn on the security mode (press the button) electronic circuit waits until you close the door to the room (safe door, box lid, etc.).

A limit switch of any type must be installed on the door (or door), more on that later. By closing (or opening), the limit switch will inform the device that the protected circuit is closed, and the device will go into security mode. The system will notify you about entering the security mode with two short signals (like in car alarms). In this mode, the device “catches” the opening of the door. After opening the door, the system waits a few seconds (this is an adjustable value, about ten seconds for rooms, one or two for a box) for the security mode to turn off; if this does not happen, the siren turns on. The algorithm and circuit are designed in such a way that you can turn off the siren only by completely disassembling the housing and turning off the power.

Device security system very simple (Fig. 2). Based on the board Arduino. The limit switches are connected like a regular button, through pull-up resistors. I will dwell separately on the end switches. They are either normally closed or normally open. You can turn on a regular button as a limit switch, only the travel of a regular button is very large, the door backlash is usually greater. Therefore, it is necessary to come up with some kind of pusher for the button and spring it so as not to break the button with the door. Well, if you’re not too lazy, you can go to the store and buy a magnetic switch (reed switch) (Fig. 3), it is not afraid of dust and dirt.

A limit switch for car alarms is also suitable (Fig. 4). It should be noted that the program is written for a reed switch. At closed door its contact is closed. If you use a car alarm switch, then when the door is closed it will most likely be open, and in the appropriate places in the code you will need to change 0 to 1 and vice versa.

As a siren, I propose to use the PKI-1 IVOLGA audio siren, produced in Belarus (Fig. 5). Supply voltage 9 - 15 V, operating current 20 - 30 mA. This allows it to be used with battery power. At the same time, it “produces” 95 - 105 dB.

With such characteristics, it will sound for several tens of minutes from a Krona battery. I found it on the Internet for 110 rubles. There, a reed switch with a magnet costs about 30 rubles. The car alarm switch was purchased at auto parts for 28 rubles. The KT315 transistor can be taken with any letter or replaced with any modern low-power silicon transistor of appropriate conductivity. If the volume of one siren is not enough (who knows, maybe you want it to be heard from many kilometers away), you can connect several sirens in parallel or take a more powerful one, only in this case the transistor must be replaced with a more powerful one (for example, the familiar transistor assembly ULN2003). As connectors for connecting the reed switch and siren, I used the simplest connectors for audio/video devices - the price on the radio market is 5 rubles. for a couple.

The device body can be glued together from plastic or plywood; if a serious object is being protected, then it is better to make it metal. To increase reliability and safety, it is advisable to place batteries or accumulators inside the case.

To simplify the program code, energy-saving elements were not used, and the batteries do not last long. You can optimize the code, or even better, radically remake it by using interrupt event processing and MK sleep mode. In this case, power from two square batteries connected in series (9 V) should be enough for several months.

Now the code

// constants
const int button = 12; // pin for the button
const int gerkon = 3; // pin for reed switch
const int sirena = 2; // siren control pin
const int led = 13; // indicator pin
// variables
int buttonState = 0; // button state
int gerkonState = 0; // reed switch state
int N = 0; // disarm button counter
void setup() (
// control siren and indicator - output
pinMode(sirena, OUTPUT);
pinMode(led, OUTPUT); // button and reed switch - inputs
pinMode(gerkon, INPUT);
pinMode(button, INPUT);
}
void loop()
digitalWrite(led, HIGH);
while(buttonState= =0)( // wait loop until we press the button
buttonState = digitalRead(button); // to switch to security mode
}
digitalWrite(led, LOW);
buttonState = 0; // reset the button value
while(gerkonState= =0)( // loop until we close the door
}
delay(500); // :-)
digitalWrite(sirena, HIGH); // Code
delay(100); // indications
digitalWrite(sirena, LOW); // enable
delay(70); // mode
digitalWrite(sirena, HIGH); // security
delay(100); // notification
digitalWrite(sirena, LOW); // sound
while(gerkonState= =1)( // wait for the door to open
gerkonState = digitalRead(gerkon);
}
for (int i=0; i<= 5; i++){ // 7,5 секунды на нажатие
buttonState = digitalRead(button); // secret button
if (buttonState = = HIGH) ( // track ours - someone else's
N=N+1;
}
delay(1500); // secret feature :-)))
}
if (N > 0) ( // the most important thing
digitalWrite(sirena, LOW); // don't turn on the siren
}
else(
digitalWrite(sirena, HIGH); // or turn on the siren
}
digitalWrite(led, HIGH); // turn on the indicator N = 0;
buttonState = 0;
delay(15000); // reminder for dummies who like
digitalWrite(led, LOW); // press the buttons without interruption delay (1000);

Over the past decade, car thefts have occupied one of the most significant places in the structure of crimes committed in the world. This is due not so much to the specific gravity of this category of theft relative to total number crimes, how significant the damage caused is due to the high cost of cars. The weak effectiveness of measures taken in the field of combating vehicle theft by the end of the 90s led to the creation of stable groups specializing in committing these crimes and possessing distinctive features organized crime; You've probably heard the term "black auto business." Car park European countries Every year, ≈ 2% of cars that become the subject of criminal attacks are missing. Therefore, I came up with the idea of ​​​​making a GSM alarm for my car on Arduino based Uno.

Let's begin!

What will we collect from?

We need to choose the heart of our system. In my opinion, for such signaling there is nothing better than Arduino Uno. The main criterion is a sufficient number of “pins” and price.


Key Features of Arduino Uno

Microcontroller - ATmega328
Operating voltage - 5 V
Input voltage (recommended) - 7-12 V
Input voltage (limit) - 6-20 V
Digital Inputs/Outputs - 14 (6 of which can be used as PWM outputs)
Analog inputs - 6
DC current through input/output - 40 mA
Constant current for output 3.3V - 50mA
Flash memory - 32 KB (ATmega328) of which 0.5 KB is used for the bootloader
RAM - 2 KB (ATmega328)
EEPROM - 1 KB (ATmega328)
Clock frequency - 16 MHz


Fits!

Now you need to select a GSM module, because our alarm system must be able to notify the car owner. So, you need to “Google”... Here, an excellent sensor - SIM800L, the size is simply wonderful.


I thought and ordered it from China. However, everything turned out to be not so rosy. The sensor simply refused to register the SIM card on the network. Everything possible was tried - the result was zero.
There were kind people who provided me with a cooler thing - Sim900 Shield. Now this is a serious thing. The Shield has both a microphone and headphone jack, making it a full-fledged phone.


Key Features of Sim900 Shield

4 operating frequency standards 850/ 900/ 1800/ 1900 MHz
GPRS multi-slot class 10/8
GPRS mobile station class B
Complies with GSM phase 2/2+
Class 4 (2 W @850/ 900 MHz)
Class 1 (1 W @ 1800/1900MHz)
Control using AT commands (GSM 07.07, 07.05 and SIMCOM extended AT commands)
Low power consumption: 1.5mA(sleep mode)
Operating temperature range: -40°C to +85°C


Fits!

Ok, but you need to take readings from some sensors in order to notify the owner. If the car is towed away, then the position of the car will obviously change in space. Let's take an accelerometer and a gyroscope. Great. Ok, now we are looking for a sensor.

I think that the GY-521 MPU6050 will definitely fit. It turned out that it also has a temperature sensor. We should use it too, there will be such a “killer feature”. Let's assume that the owner of the car parked it under his house and left. The temperature inside the car will change “smoothly”. What happens if an intruder tries to break into the car? For example, he will be able to open the door. The temperature in the car will begin to change rapidly as the air in the cabin begins to mix with the air environment. I think it will work.


Main Features of GY-521 MPU6050

3-axis gyroscope + 3-axis accelerometer GY-521 module on MPU-6050 chip. Allows you to determine the position and movement of an object in space, angular velocity when rotating. It also has a built-in temperature sensor. It is used in various copters and aircraft models; a motion capture system can also be assembled based on these sensors.

Chip - MPU-6050
Supply voltage - from 3.5V to 6V (DC);
Gyro Range - ±250 500 1000 2000°/s
Accelerometer range - ±2±4±8±16g
Communication interface - I2C
Size - 15x20 mm.
Weight - 5 g


Fits!

A vibration sensor will also come in handy. Suddenly they try to open the car with “brute force”, or in the parking lot another car hits your car. Let's take the vibration sensor SW-420 (adjustable).


Main characteristics of SW-420

Supply voltage - 3.3 - 5V
Output signal - digital High/Low (normally closed)
Sensor used - SW-420
The comparator used is LM393
Dimensions - 32x14 mm
Additionally - There is an adjustment resistor.


Fits!

Screw on the SD memory card module. We will also write a log file.


Main characteristics of the SD memory card module

The module allows you to store, read and write to an SD card the data required for the operation of a device based on a microcontroller. The use of the device is relevant when storing files from tens of megabytes to two gigabytes. The board contains an SD card container, a card power stabilizer, and a connector plug for interface and power lines. If you need to work with audio, video or other large-scale data, for example, to log events, sensor data or store web server information, then the SD memory card module for Arduino will make it possible to use an SD card for these purposes. Using the module, you can study the features of the SD card.
Supply voltage - 5 or 3.3 V
SD card memory capacity - up to 2 GB
Dimensions - 46 x 30 mm


Fits!

And let's add a servo drive; when the sensors are triggered, the servo drive with the video recorder will turn and shoot a video of the incident. Let's take the MG996R servo drive.


Main Features of MG996R Servo Drive

Stable and reliable protection against damage
- Metal drive
- Double row ball bearing
- Wire length 300 mm
- Dimensions 40x19x43mm
- Weight 55 g
- Rotation angle: 120 degrees.
- Working speed: 0.17sec/60 degrees (4.8V no load)
- Operating speed: 0.13sec/60 degrees (6V no load)
- Starting torque: 9.4kg/cm at 4.8V power supply
- Starting torque: 11kg/cm with 6V power supply
- Operating voltage: 4.8 - 7.2V
- All drive parts are made of metal


Fits!

We collect

There are a huge number of articles on Google about connecting each sensor. And I have no desire to invent new bicycles, so I will leave links to simple and working options.

In the last article we learned how to use the GSM module SIM800L and made a simple design for controlling the load remotely, today we will make something more interesting, namely a GSM security alarm system on the SIM800L module from Aliexpress and Arduino, which can be used to protect an apartment, cottage, garage, etc. other objects, and when it is triggered, it will notify you with a call or SMS message.

What we need to make a GSM alarm:

  • GSM/GPRS module SIM800L;
  • Arduino Nano, UNO or other Arduino;
  • Buck DC-DC converter;
  • Battery 3.7 V;
  • Resistors for 10 k – 7 pcs;
  • Power unit.

How to make a GSM security alarm using the SIM800L and Arduino module, description of work:

We connect the SIM800L module, Arduino, sensors, etc. according to the diagram below, everything is assembled on breadboard so that you can change something at any time, we place it in any suitable housing and remove the wires from the housing for security sensors and to the power supply. We also place the battery in the case; it is needed so that when the electricity in the house goes out, the device goes into autonomous mode, powered by battery. On the boost converter, we set the output to 4.2 volts, at this voltage the GSM SIM module operates and at the same time the battery is recharged, and this voltage is also enough to operate the Arduino Nano.

You can connect any 5 sensors to the circuit, such as reed switches, humidity, smoke, motion sensors, etc. which support relay operation, since this circuit is configured to trigger an alarm for an open circuit of any of the five sensors, but if desired, the sketch can be converted to a short circuit.

When the first sensor is triggered, a call is made to the specified number, then the call is dropped and a call is made to the second number, this is done if the first number is on at the moment will not be available. When the remaining 4 security sensors are triggered, only an SMS message is sent in which the number or name of the triggered zone is written, and this message will also be sent to two phone numbers.

In the sketch, you can enter phone numbers and give your names to the protected areas, instead of “Alarm! Zone1", "Alarm! Zone2", "Alarm! Zone3”... You can write the name of the object where you installed a specific sensor, for example “Alarm! Window", "Alarm! Dverj”, etc., write zone names only in Latin. Also in the sketch the time for calling back to the owner is set, that is, after how many hours to inform you that the whole system is working and everything is in order, by default it is set to call back every 144 hours.

That's it, we have made a simple GSM security alarm using the SIM800L module and Arduino, the sketch and circuit can be modified, for example, the SIM800L module supports the ability to connect a loudspeaker and microphone to it, which will allow you to listen to the protected premises, as well as output your voice to the loudspeaker.

Download the sketch for Arduino.