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.3V
5V
connected to SIM800L VCC
and MPU-6050 VCC
GND
pins connected to SIM800L GND
, MPU-6050 GND
, LED anode
, and LoRa Ra-02 SX1278 GND
A4
(SDA) connected to MPU-6050 SDA
A5
(SCL) connected to MPU-6050 SCL
D13
connected to LED cathode
and LoRa Ra-02 SX1278 SCK
D12
connected to LoRa Ra-02 SX1278 MISO
D11
connected to LoRa Ra-02 SX1278 MOSI
D10
connected to LoRa Ra-02 SX1278 NSS
D9
connected to LoRa Ra-02 SX1278 RST
D8
connected to LoRa Ra-02 SX1278 DI00
D4
connected to SIM800L RST
D3
connected to SIM800L RXD
D2
connected to SIM800L TXD
VCC
connected to Arduino UNO 5V
GND
connected to Arduino UNO GND
SCL
connected to Arduino UNO A5
SDA
connected to Arduino UNO A4
anode
connected to Arduino UNO GND
cathode
connected to Arduino UNO D13
3.3V
connected to Arduino UNO 3.3V
GND
connected to Arduino UNO GND
SCK
connected to Arduino UNO D13
MISO
connected to Arduino UNO D12
MOSI
connected to Arduino UNO D11
NSS
connected to Arduino UNO D10
RST
connected to Arduino UNO D9
DI00
connected to Arduino UNO D8
VCC
connected to Arduino UNO 5V
GND
connected to Arduino UNO GND
RST
connected to Arduino UNO D4
RXD
connected to Arduino UNO D3
TXD
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.