

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.
3.3V connected to LoRa Ra-02 SX1278 3.3V5V connected to SIM800L VCC and MPU-6050 VCCGND pins connected to SIM800L GND, MPU-6050 GND, LED anode, and LoRa Ra-02 SX1278 GNDA4 (SDA) connected to MPU-6050 SDAA5 (SCL) connected to MPU-6050 SCLD13 connected to LED cathode and LoRa Ra-02 SX1278 SCKD12 connected to LoRa Ra-02 SX1278 MISOD11 connected to LoRa Ra-02 SX1278 MOSID10 connected to LoRa Ra-02 SX1278 NSSD9 connected to LoRa Ra-02 SX1278 RSTD8 connected to LoRa Ra-02 SX1278 DI00D4 connected to SIM800L RSTD3 connected to SIM800L RXDD2 connected to SIM800L TXDVCC connected to Arduino UNO 5VGND connected to Arduino UNO GNDSCL connected to Arduino UNO A5SDA connected to Arduino UNO A4anode connected to Arduino UNO GNDcathode connected to Arduino UNO D133.3V connected to Arduino UNO 3.3VGND connected to Arduino UNO GNDSCK connected to Arduino UNO D13MISO connected to Arduino UNO D12MOSI connected to Arduino UNO D11NSS connected to Arduino UNO D10RST connected to Arduino UNO D9DI00 connected to Arduino UNO D8VCC connected to Arduino UNO 5VGND connected to Arduino UNO GNDRST connected to Arduino UNO D4RXD connected to Arduino UNO D3TXD connected to Arduino UNO D2#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.