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

Arduino-Based Motion Detection System with MPU-6050 and SIM800L for SMS Alerts

View and Edit Project In Cirkit DesignerImage of Arduino-Based Motion Detection System with MPU-6050 and SIM800L for SMS Alerts

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that integrates an Arduino UNO microcontroller with an MPU-6050 accelerometer, a SIM800L GSM module, a LoRa Ra-02 SX1278 module, and a red LED. The circuit is designed to detect movement using the MPU-6050 and send an SMS alert via the SIM800L module when movement is detected. The LoRa module is included for potential long-range communication, and the LED provides a visual indication of detected movement.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. MPU-6050

    • Description: A 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
    • Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
  3. LED: Two Pin (red)

    • Description: A standard red LED with two pins: anode and cathode.
    • Pins: cathode, anode
  4. LoRa Ra-02 SX1278

    • Description: A long-range transceiver module based on the SX1278 chip.
    • Pins: GND, NSS, MOSI, MISO, SCK, D105, DI04, 3.3V, RST, DI00, DI01, D102, DI03
  5. SIM800L

    • Description: A GSM/GPRS module that allows for SMS, voice, and data communication.
    • Pins: NFT, RING, VCC, DTR, RST, MIC +, RXD, MIC-, TXD, SPK+, GND, SPK-

Wiring Details

Arduino UNO

MPU-6050

LED: Two Pin (red)

LoRa Ra-02 SX1278

SIM800L

Code Documentation

#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=\"+919025056163\"\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 initializes the MPU-6050 and SIM800L modules, checks their connections, and sends an SMS alert when movement is detected. The LED blinks to provide a visual indication of detected movement.