Arduino-Based Motion Detection System with MPU-6050 and SIM800L for SMS Alerts
View and Edit Project In Cirkit Designer
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
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
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
LED: Two Pin (red)
- Description: A standard red LED with two pins: anode and cathode.
- Pins: cathode, anode
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
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
- 3.3V connected to 3.3V of LoRa Ra-02 SX1278
- 5V connected to VCC of MPU-6050 and SIM800L
- GND connected to GND of MPU-6050, SIM800L, LoRa Ra-02 SX1278, and anode of LED
- A4 connected to SDA of MPU-6050
- A5 connected to SCL of MPU-6050
- D13 connected to SCK of LoRa Ra-02 SX1278 and cathode of LED
- D12 connected to MISO of LoRa Ra-02 SX1278
- D11 connected to MOSI of LoRa Ra-02 SX1278
- D10 connected to NSS of LoRa Ra-02 SX1278
- D9 connected to RST of LoRa Ra-02 SX1278
- D8 connected to DI00 of LoRa Ra-02 SX1278
- D4 connected to RST of SIM800L
- D3 connected to RXD of SIM800L
- D2 connected to TXD of SIM800L
MPU-6050
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
- SDA connected to A4 of Arduino UNO
- SCL connected to A5 of Arduino UNO
LED: Two Pin (red)
- anode connected to GND of Arduino UNO
- cathode connected to D13 of Arduino UNO
LoRa Ra-02 SX1278
- 3.3V connected to 3.3V of Arduino UNO
- GND connected to GND of Arduino UNO
- SCK connected to D13 of Arduino UNO
- MISO connected to D12 of Arduino UNO
- MOSI connected to D11 of Arduino UNO
- NSS connected to D10 of Arduino UNO
- RST connected to D9 of Arduino UNO
- DI00 connected to D8 of Arduino UNO
SIM800L
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
- RST connected to D4 of Arduino UNO
- RXD connected to D3 of Arduino UNO
- TXD connected to D2 of Arduino UNO
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.