Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Ultrasonic Security System with SIM800L GSM Module

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

HC-SR04 Ultrasonic Sensor

SIM800L GSM Module

48V to 5V Converter

LED: Two Pin (red)

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

SIM800L GSM Module

48V to 5V Converter

LED: Two Pin (red)

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.