Landslide Tilt Warning Prototype with MPU6050 and LoRa (Learning Build)
Build a learning prototype that detects tilt with an MPU6050 on an ESP32 and sends alerts over LoRa to a gateway. Wiring, code, testing and limits.
On this page
Every monsoon, landslides affect roads and villages across hilly Nepal. Monitoring slopes is serious engineering work done by geologists, engineers and disaster-management authorities. As a student, you can still learn the core ideas behind such systems by building a small prototype: a sensor node that notices when a pole tilts, and a radio link that carries the alert to a "gateway" some distance away.
Please read this first: this is a learning prototype, not a certified warning system. Do not install it on a real slope and tell people they are safe because of it. Real early-warning systems use many sensor types, expert analysis, tested hardware and official alert channels. Present it in your report as a demonstration of sensing and wireless communication.
What you need
Scroll sideways to see all columns.
| Item | Qty | Notes |
|---|---|---|
| ESP32 dev board | 2 | One sensor node, one gateway |
| MPU6050 module (GY-521) | 1 | Accelerometer + gyro over I2C |
| LoRa module (SX1276/SX1278 based, e.g. RFM95 or Ra-02) | 2 | 3.3 V only; both on the same frequency band |
| Antennas for the LoRa modules | 2 | Matched to the module's band |
| Active buzzer + LED (220 Ω) | 1 each | Alarm at the gateway |
| Regulated 5 V USB supply or power bank | 2 | Power each ESP32 through its USB port |
| NPN transistor + 1 kΩ base resistor | 1 each | Low-side driver for the active buzzer |
| Wooden or PVC stick, small board | 1 | To mount the node for tabletop tests |
| Breadboards, jumper wires, soldering kit | 1 set | LoRa modules often need header pins soldered |
We use the ESP32 because LoRa modules run on 3.3 V logic. Connecting them to a 5 V Uno without level shifting can damage them.
How it works
- The MPU6050 measures the direction of gravity on three axes. From that we calculate the tilt angle of the stick it is mounted on.
- At start-up the node records a baseline angle. Afterwards it watches the change from that baseline.
- A brief wobble from wind or a passing animal should not trigger an alarm. So the node raises an alert only if the change stays above a threshold (for example 5°) for a set time (for example 10 seconds).
- The node sends a tiny text message over LoRa, a low-power radio that carries small packets over much longer distances than Wi-Fi. It also sends a "heartbeat" every minute so the gateway knows the node is alive.
- The gateway ESP32 receives packets, sounds the buzzer on an alert, and warns if heartbeats stop.
LoRa range depends heavily on terrain, antenna height, trees and buildings. Hills between the two nodes can block the signal completely. Do not quote a range number you have not tested yourself.
Frequency rules: LoRa modules are sold for different bands (commonly 433 MHz or 868/915 MHz). Which bands you may use, and at what power, is decided by national regulations. Check the current rules in Nepal before transmitting outdoors, and always connect the antenna before powering the module.
Connection table: sensor node
Scroll sideways to see all columns.
| Module pin | ESP32 pin |
|---|---|
| MPU6050 VCC | 3.3V |
| MPU6050 GND | GND |
| MPU6050 SDA | GPIO21 |
| MPU6050 SCL | GPIO22 |
| LoRa 3.3V | 3.3V |
| LoRa GND | GND |
| LoRa SCK | GPIO18 |
| LoRa MISO | GPIO19 |
| LoRa MOSI | GPIO23 |
| LoRa NSS (CS) | GPIO4 |
| LoRa RESET | GPIO14 |
| LoRa DIO0 | GPIO26 |
The gateway uses the same LoRa wiring. Connect GPIO27 through 220 Ω and the LED to GND. Drive a 5 V active buzzer with an NPN transistor: GPIO25 through 1 kΩ to the base, emitter to GND, collector to buzzer − and buzzer + to regulated 5 V. Share grounds. For an inductive buzzer, fit a flyback diode across it with the cathode at +5 V.
GPIO4 avoids GPIO5, a strapping pin sampled at reset.
Code: sensor node
// Tilt sensor node (learning prototype) - not compiled yet
#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
const int MPU = 0x68;
const long LORA_FREQ = 433E6; // must match your module and local rules
const float THRESHOLD_DEG = 5.0; // change from baseline that counts as tilt
const unsigned long HOLD_MS = 10000; // tilt must last this long
const unsigned long HEARTBEAT_MS = 60000;
float baseline = 0;
unsigned long tiltStart = 0;
unsigned long lastBeat = 0;
bool alerted = false;
float readTiltDeg() {
Wire.beginTransmission(MPU);
Wire.write(0x3B); // ACCEL_XOUT_H
Wire.endTransmission(false);
Wire.requestFrom(MPU, 6, true);
int16_t ax = Wire.read() << 8 | Wire.read();
int16_t ay = Wire.read() << 8 | Wire.read();
int16_t az = Wire.read() << 8 | Wire.read();
// tilt of the stick from vertical, using all three axes
float horiz = sqrt((float)ax * ax + (float)ay * ay);
return atan2(horiz, (float)az) * 180.0 / PI;
}
float averageTilt(int n) {
float sum = 0;
for (int i = 0; i < n; i++) { sum += readTiltDeg(); delay(10); }
return sum / n;
}
void sendMsg(String msg) {
LoRa.beginPacket();
LoRa.print(msg);
LoRa.endPacket();
Serial.println("Sent: " + msg);
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1
Wire.write(0); // wake the sensor
Wire.endTransmission(true);
LoRa.setPins(4, 14, 26); // NSS, RESET, DIO0
if (!LoRa.begin(LORA_FREQ)) {
Serial.println("LoRa init failed");
while (true) delay(1000);
}
delay(2000); // let the stick settle
baseline = averageTilt(100);
sendMsg("N1,START," + String(baseline, 1));
}
void loop() {
float change = fabs(averageTilt(20) - baseline);
if (change > THRESHOLD_DEG) {
if (tiltStart == 0) tiltStart = millis();
if (!alerted && millis() - tiltStart > HOLD_MS) {
sendMsg("N1,ALERT," + String(change, 1));
alerted = true;
}
} else {
tiltStart = 0;
alerted = false; // back to normal, allow a new alert
}
if (millis() - lastBeat > HEARTBEAT_MS) {
sendMsg("N1,OK," + String(change, 1));
lastBeat = millis();
}
delay(500);
}
Code: gateway
// LoRa gateway with buzzer - not compiled yet
#include <SPI.h>
#include <LoRa.h>
const int BUZZER = 25;
const int LED = 27;
const unsigned long SILENT_MS = 180000; // 3 missed heartbeats
unsigned long lastHeard = 0;
void setup() {
Serial.begin(115200);
pinMode(BUZZER, OUTPUT);
pinMode(LED, OUTPUT);
LoRa.setPins(4, 14, 26);
if (!LoRa.begin(433E6)) {
Serial.println("LoRa init failed");
while (true) delay(1000);
}
lastHeard = millis();
}
void loop() {
int size = LoRa.parsePacket();
if (size) {
String msg = LoRa.readString();
lastHeard = millis();
Serial.print(msg);
Serial.print(" RSSI ");
Serial.println(LoRa.packetRssi());
if (msg.indexOf("ALERT") > 0) {
digitalWrite(LED, HIGH);
for (int i = 0; i < 10; i++) {
digitalWrite(BUZZER, HIGH); delay(200);
digitalWrite(BUZZER, LOW); delay(200);
}
}
}
if (millis() - lastHeard > SILENT_MS) {
Serial.println("WARNING: node silent - check battery or link");
lastHeard = millis();
}
}
The RSSI value (received signal strength, in dBm) helps when testing range: values closer to zero mean a stronger signal.
Testing on a tabletop slope
- Mount the sensor node on a stick pushed into a tray of soil or sand.
- Power both nodes. The gateway should print
N1,START,...and then a heartbeat every minute. - Tap the stick and let it spring back. Nothing should trigger, which proves the time filter works.
- Slowly lean the stick about 10° and hold it. After about 10 seconds the gateway should beep.
- Move the gateway to another room, then outside, and note the RSSI at each spot. Record real numbers in your report.
- Unplug the sensor node and check that the gateway warns about silence after three minutes.
Power for a field-style node
A real node far from sockets would run from a small solar panel and a battery, and spend most of its time asleep: wake, read, send, sleep. The ESP32's deep sleep mode makes this possible. Measure the average current with a multimeter before you estimate battery life, and remember a LoRa transmission draws far more current than sleeping.
Troubleshooting
Scroll sideways to see all columns.
| Symptom | Likely cause | Fix |
|---|---|---|
| "LoRa init failed" | Wrong pins, loose SPI wire, no 3.3 V | Check NSS/RESET/DIO0 and power; resolder headers |
| Gateway receives nothing | Different frequency or no antenna | Same LoRa.begin frequency on both; fit antennas |
| Tilt reads 0 or nonsense | MPU6050 not on the I2C bus | Run an I2C scanner; check SDA 21 / SCL 22 |
| Alerts on every tap | Threshold too low or HOLD_MS too short | Raise THRESHOLD_DEG or HOLD_MS |
| Never alerts | Baseline taken while already tilted | Restart with the stick upright |
| Range much shorter outdoors | Hills, trees, antenna near the ground | Raise the antenna; test line of sight |
FAQ
Can this predict a landslide?
No. It only shows that a stick tilted. Real slope monitoring combines rainfall, soil moisture, ground movement and expert judgement. Keep the "learning prototype" label in your report and your demo.
Is this a good final-year project?
It can be, with honest framing: sensor fusion, filtering, wireless links and power budgeting. Our final year project ideas for electronics and computer engineering and how to choose and plan your project guides help you scope it. Check your department's format for the report.
Why LoRa and not Wi-Fi?
Wi-Fi needs a router nearby. LoRa carries small messages much farther at low power, which suits remote sensors. It cannot carry large data like images.
Can I add more sensors?
Yes. Give each node its own ID (N1, N2, ...) and the gateway can tell them apart. For more ESP32 ideas see our ESP32 IoT project ideas.