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

Arduino UNO-Based Movement Detection and Alert System with MPU-6050, SIM800L, and LoRa Communication

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Movement Detection and Alert System with MPU-6050, SIM800L, and LoRa Communication

Circuit Documentation

Summary

The circuit in question is designed around an Arduino UNO microcontroller and includes several peripheral components: an MPU-6050 accelerometer/gyroscope module, a SIM800L GSM module, a two-pin red LED, and a LoRa Ra-02 SX1278 module. The Arduino UNO serves as the central processing unit, interfacing with the MPU-6050 for motion detection, controlling the LED as an indicator, communicating with the SIM800L module for sending SMS messages, and handling LoRa communication through the SX1278 module.

Component List

Arduino UNO

MPU-6050

LED: Two Pin (red)

LoRa Ra-02 SX1278

SIM800L

Wiring Details

Arduino UNO

MPU-6050

LED: Two Pin (red)

LoRa Ra-02 SX1278

SIM800L

Documented Code

#include <Wire.h>
#include <MPU6050.h>
#include <SoftwareSerial.h>

MPU6050 mpu;
SoftwareSerial sim800(2, 3); // RX, TX
const int ledPin = 13;
const int threshold = 1000; // Adjust this threshold as needed

void setup() {
  pinMode(ledPin, OUTPUT);
  Wire.begin();
  Serial.begin(9600);
  sim800.begin(9600);
  mpu.initialize();
  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed");
    while (1);
  }
  Serial.println("MPU6050 connection successful");

  // Check SIM800L initialization
  sim800.print("AT\r");
  delay(100);
  if (sim800.available()) {
    String response = sim800.readString();
    if (response.indexOf("OK") == -1) {
      Serial.println("SIM800L initialization failed");
      while (1);
    }
  } else {
    Serial.println("SIM800L not responding");
    while (1);
  }

  sendSMS("System Initialized");
}

void loop() {
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);
  int magnitude = sqrt(ax * ax + ay * ay + az * az);
  if (magnitude > threshold) {
    blinkLED();
    sendSMS("Movement detected!");
    delay(5000); // Wait 5 seconds before checking again
  }
  delay(100);
}

void blinkLED() {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

void sendSMS(const char* message) {
  sim800.print("AT+CMGF=1\r");
  delay(100);
  sim800.print("AT+CMGS=\"+1234567890\"\r"); // Replace with your phone number
  delay(100);
  sim800.print(message);
  delay(100);
  sim800.write(26); // ASCII code for CTRL+Z
  delay(1000); // Increased delay to ensure message is sent

  // Check if the message was sent successfully
  if (sim800.available()) {
    String response = sim800.readString();
    if (response.indexOf("OK") == -1) {
      Serial.println("Failed to send SMS");
    } else {
      Serial.println("SMS sent successfully");
    }
  } else {
    Serial.println("No response from SIM800L");
  }
}

This code is designed to run on the Arduino UNO and interfaces with the MPU-6050 to detect motion, controls an LED as an indicator, communicates with the SIM800L module to send SMS messages, and sets up the initial state of the LoRa SX1278 module. The code includes initialization checks for both the MPU-6050 and SIM800L to ensure proper startup and functionality.