Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface an Arduino UNO with an HC-SR04 Ultrasonic Sensor, a SIM800L GSM module, a 48V to 5V converter, and an LED. The Arduino UNO acts as the central processing unit, controlling the ultrasonic sensor to measure distance and using the SIM800L module to send an alert via a GSM network when a certain distance threshold is met. The 48V to 5V converter steps down the voltage to power the SIM800L module and the ultrasonic sensor. The LED serves as an indicator for motion detection.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
HC-SR04 Ultrasonic Sensor
- An ultrasonic distance sensor capable of measuring distances from 2cm to 400cm.
- It has four pins: VCC, TRIG, ECHO, and GND.
SIM800L GSM Module
- A compact GSM/GPRS module for mobile communication.
- It includes pins for power supply, serial communication, and speaker/microphone functionality.
48V to 5V Converter
- A DC-DC converter module that steps down 48V to a regulated 5V output.
- It has four pins: in+, in--, out+, and out--.
LED: Two Pin (red)
- A basic red LED with an anode and cathode for indicating power or status.
Wiring Details
Arduino UNO
- 5V connected to HC-SR04 VCC
- GND connected to HC-SR04 GND, 48V to 5V in--, and LED cathode
- Vin connected to 48V to 5V in+
- D13 connected to LED anode
- D9 connected to HC-SR04 ECHO
- D8 connected to HC-SR04 TRIG
- D3 connected to SIM800L TXD
- D2 connected to SIM800L RXD
HC-SR04 Ultrasonic Sensor
- VCC connected to Arduino UNO 5V
- TRIG connected to Arduino UNO D8
- ECHO connected to Arduino UNO D9
- GND connected to Arduino UNO GND
SIM800L GSM Module
- VCC connected to 48V to 5V out+
- RXD connected to Arduino UNO D2
- TXD connected to Arduino UNO D3
- GND connected to 48V to 5V out--
48V to 5V Converter
- in+ connected to Arduino UNO Vin
- in-- connected to Arduino UNO GND
- out+ connected to SIM800L VCC
- out-- connected to SIM800L GND
LED: Two Pin (red)
- anode connected to Arduino UNO D13
- cathode connected to Arduino UNO GND
Documented Code
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX
#define trigPin 8
#define echoPin 9
int redled = 13;
void setup() {
randomSeed(analogRead(0));
Serial.begin(9600);
mySerial.begin(9600); // Set baud rate for SIM900A
Serial.println("Logging time completed!");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redled, OUTPUT);
digitalWrite(redled, LOW);
delay(100);
}
void loop() {
long time_duration, distance_in_cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time_duration = pulseIn(echoPin, HIGH);
distance_in_cm = time_duration / 29 / 2;
Serial.print(distance_in_cm);
Serial.println(" cm");
if (distance_in_cm >= 10) {
digitalWrite(redled, HIGH);
Serial.println("Motion detected!");
Serial.println("Calling...");
mySerial.println("AT"); // Handshake with SIM module
updateSerial();
mySerial.println("ATD+251712973006;"); // Dial number
updateSerial();
delay(30000); // Wait for 30 seconds
mySerial.println("ATH"); // Hang up
updateSerial();
delay(3000);
} else {
digitalWrite(redled, LOW);
}
}
void updateSerial() {
delay(500);
while (Serial.available()) {
mySerial.write(Serial.read()); // Forward Serial to Software Serial
}
while (mySerial.available()) {
Serial.write(mySerial.read()); // Forward Software Serial to Serial
}
}
This code is designed to run on the Arduino UNO. It initializes the HC-SR04 sensor and the SIM800L module, then continuously measures the distance using the ultrasonic sensor. If the distance exceeds 10 cm, the LED is turned on, and the SIM800L module is used to make a call to a predefined number. The updateSerial function is used to pass data between the Arduino's hardware serial and the software serial connected to the SIM800L.