ESP8266 NodeMCU-Based Landslide Detection System with MPU-6050 and Soil Moisture Sensing
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor environmental conditions such as soil moisture and vibrations, potentially for applications like landslide detection or agricultural monitoring. It utilizes an ESP8266 NodeMCU microcontroller to interface with a set of sensors including an MPU-6050 accelerometer/gyroscope, a SparkFun Soil Moisture Sensor, and an SW-420 Vibration Sensor. The microcontroller reads data from the sensors and can send alerts or log events through the Blynk platform when certain thresholds are met, indicating excessive moisture or vibration.
Component List
ESP8266 NodeMCU
- Description: A Wi-Fi enabled microcontroller module with an ESP8266 chip.
- Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
MPU-6050
- Description: A motion tracking device or IMU (Inertial Measurement Unit) that contains an accelerometer and a gyroscope.
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
SparkFun Soil Moisture Sensor
- Description: A sensor that measures the volumetric content of water in soil.
- Pins: VCC, GND, SIG
SW-420 Vibration Sensor
- Description: A sensor that detects vibrations and movements.
- Pins: VCC, Ground, Digital output
Wiring Details
ESP8266 NodeMCU
- D0: Connected to SW-420 Vibration Sensor (Digital output)
- D1: Connected to MPU-6050 (SCL)
- D2: Connected to MPU-6050 (SDA)
- A0: Connected to SparkFun Soil Moisture Sensor (SIG)
- 3V3: Connected to MPU-6050 (VCC) and SW-420 Vibration Sensor (VCC) and SparkFun Soil Moisture Sensor (VCC)
- GND: Common ground connected to MPU-6050 (GND), SW-420 Vibration Sensor (Ground), and SparkFun Soil Moisture Sensor (GND)
MPU-6050
- SCL: Connected to ESP8266 NodeMCU (D1)
- SDA: Connected to ESP8266 NodeMCU (D2)
- VCC: Connected to ESP8266 NodeMCU (3V3)
- GND: Connected to common ground
SparkFun Soil Moisture Sensor
- SIG: Connected to ESP8266 NodeMCU (A0)
- VCC: Connected to ESP8266 NodeMCU (3V3)
- GND: Connected to common ground
SW-420 Vibration Sensor
- Digital output: Connected to ESP8266 NodeMCU (D0)
- VCC: Connected to ESP8266 NodeMCU (3V3)
- Ground: Connected to common ground
Documented Code
#define BLYNK_TEMPLATE_ID "TMPL3fL5zmS2l"
#define BLYNK_TEMPLATE_NAME "\"Landslide\""
#define BLYNK_AUTH_TOKEN "GHB1n-s9rB1gcmPvMtV8mtdeYHSKMTuw"
// Vibration Sensor Pin
#define VIBRATION_SENSOR_PIN D0
// Soil Moisture Pin
#define SOIL_MOISTURE_SENSOR_PIN A0
#include <Wire.h>
#include <MPU6050.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int moistureThreshold = 600;
// Define threshold values for detecting significant motion (you can adjust these)
int16_t accelThreshold = 15000;
// Create an MPU6050 object
MPU6050 mpu;
char ssid[] = "Le Bhikari";
char password[] = "1234567890";
char auth[] = BLYNK_AUTH_TOKEN;
WiFiClient client;
void setup() {
Serial.begin(115200);
pinMode(SOIL_MOISTURE_SENSOR_PIN, INPUT);
pinMode(VIBRATION_SENSOR_PIN, INPUT);
Wire.begin();
Serial.println("Initializing MPU6050...");
mpu.initialize();
if (mpu.testConnection()) {
Serial.println("MPU6050 connected successfully!");
} else {
Serial.println("MPU6050 connection failed. Please check the wiring.");
}
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Blynk.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
}
void loop() {
// Code for Soil Moisture
int sensorValue = analogRead(SOIL_MOISTURE_SENSOR_PIN);
Serial.print("Soil Moisture Level: ");
Serial.println(sensorValue);
if (sensorValue < moistureThreshold) {
Serial.println("ALERT: Soil moisture below threshold! Soil is too wet.");
Blynk.logEvent("warn", "ALERT: Soil moisture below threshold! Soil is too wet.");
} else {
Serial.println("Soil moisture level is acceptable.");
}
// Code for Vibration Sensor
int sensorValue1 = digitalRead(VIBRATION_SENSOR_PIN);
if (sensorValue1 == HIGH) {
Serial.println("Vibration Detected: DANGER!");
Blynk.logEvent("warn", "Vibration Detected: DANGER!");
} else {
Serial.println("No significant vibration.");
}
// Code For MPU6050 Gyro Sensor
int16_t ax, ay, az;
int16_t gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("Accel X: ");
Serial.print(ax);
Serial.print(" | Y: ");
Serial.print(ay);
Serial.print(" | Z: ");
Serial.println(az);
if (abs(ax) > accelThreshold || abs(ay) > accelThreshold || abs(az) > accelThreshold) {
Serial.println("DANGER: Significant ground movement detected!");
Blynk.logEvent("warn", "DANGER: Significant ground movement detected!");
} else {
Serial.println("Ground is stable.");
}
Blynk.virtualWrite(V0, sensorValue);
Blynk.virtualWrite(V1, sensorValue1);
delay(500);
Blynk.run();
}
This code is designed to run on the ESP8266 NodeMCU. It initializes the MPU6050 sensor and checks for a successful connection. It connects to a Wi-Fi network and then to the Blynk platform using the provided authentication token. In the main loop, it reads the soil moisture level and vibration sensor status, logs the data to the Blynk platform, and prints it to the serial monitor. It also reads the accelerometer data from the MPU6050 and logs significant movements.