Create a GSM Remote Alarm System
GSM Remote Alarm System is an experimental implementation of a broader idea of how one can build a home alarm system. This post shows my attempts to remotely control an alarm system using SIM800L GSM module which is connected to a ESP32 microcontroller.
My challenge was particularly on the code side on how to communicate and control the GSM module to send/receive SMS messages, and then using those messages in order to activate alarm mode or even control external devices such as a relay.
If you are interested in home automation and security, no doubt that the open source Home assistant, running on Raspberry Pi, is a better approach to follow, and this repository is only for educational purpose.
Main features
- Activate/deactivate alarm status
- Red LED blinking
- Buzzing constantly
- Raise an error when the modem is not responding or the signal is poor
- Turn on the yellow LED
- Buzzing every 10 seconds
- Arm/Disarm SMS command
- Push-button “ON”/”OFF” SMS command
- Display messages on a 0.96 inch OLED display
What does it?
This module can be set in alarm mode by receiving an SMS command (e.g. “ALARM”). Also can reply an “ON” and “OFF” SMS command to the predefined contact number by pressing a push-button for 5 and 10 seconds, respectively.
Prerequisites
- Hardware:
- Software:
- Arduino IDE with ESP32 Add-on
- Adafruit TFT display driver library
Wiring
The wiring ESP32 is as follows:
- SIM800L GSM module:
- RXD ➡ G16
- TXD ➡ G17
- VCC ➡ 4.0V (this must be provided by the LM2596S power module)
- OLED display (I2C):
- SCL ➡ G23
- SDA ➡ RXD
- Vin ➡ 3V3 (3.2V)
- LEDs pin:
- Yellow ➡ G4
- Red ➡ G5
- Buzzer pin ➡ G15
- Push button ➡ G2
A large electrolytic capacitor (470 or 1000 uF) is certainly required in order to stabilize the GSM module with its current spike. It should be connected to the GND and VCC pins and as close as possible to the module.
Esp32 T-Call series with on-board SIM800 GSM module are also alternative hardware options for this project.
More details can be found here.
Code adjustment
SMS commands and Recipient contact number have to adjusted based on your needs.
// SMS commands
#define ALARM_SMS "ALARM"
#define ARM_SMS "ON"
#define DISARM_SMS "OFF"
// GSM contact recipent
#define RECIPIENT "+123456789"
Other parameters work just fine with their default values but they can be also adjusted.
// General parameters
#define GSM_TX_PIN 17 // pin
#define GSM_RX_PIN 16 // pin
#define BUZZER_PIN 15 // pin
#define STATUS_LED 4 // pin
#define ALARM_LED 5 // pin
#define PUSH_BUTTON 2 // pin
#define BUZZER_FRQ 2000 // Hz
#define ALARM_TIMER 1800000 // ms
#define ARM_BTN_DLY 8000 // ms
#define DISARM_BTN_DLY 4000 // ms
#define BUZZER_CHANNEL 0 // PWM channel
#define BUFFER_LEN 128 // size
// OLD display
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // reset pin # (or -1 if sharing Arduino reset pin)
For more details and the sketch (C++ source code) please see https://github.com/hghcomphys/remote-alarm-system
References
Some useful links that part of this work is based on them are as follows: