#include<Wire.h>
#include<Adafruit_Sensor.h>
#include<Adafruit_ADXL345_U.h>
#include <DHTesp.h>
#include<LiquidCrystal_I2C.h>
#define SOIL_MOISTURE_PIN A0 // Analog pin for soil moisture sensor
#define THRESHOLD_MOISTURE 500 // Adjust this threshold based on your soil conditions
#define DHT_PIN 2 // Digital pin for DHT sensor
#define LCD_ADDRESS 0x27 // I2C address of the LCD
#define LCD_COLUMNS 16
#define LCD_ROWS 2
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
DHTesp dhtSensor();
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
void setup() {
Serial.begin(115200);
dhtSensor ='DHT_PIN, DHTesp dhtSensor()'
if(!accel.begin())
{
Serial.println("Could not find a valid ADXL345 sensor, check wiring!");
while(1);
}
pinMode(SOIL_MOISTURE_PIN, INPUT);
lcd.begin(LCD_COLUMNS, LCD_ROWS);
lcd.backlight();
lcd.clear();
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
// Read accelerometer data
float acceleration_magnitude = sqrt(event.acceleration.x*event.acceleration.x +
event.acceleration.y*event.acceleration.y +
event.acceleration.z*event.acceleration.z);
// Read soil moisture data
int soil_moisture = analogRead(SOIL_MOISTURE_PIN);
Serial.println("Temp: "+ String(temperature, 2) + "C");
Serial.println("Humidity: "+ String(humidity, 1) + "%");
Serial.println("---");
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print('temperatureRead');
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print('humidity');
lcd.print("%");
// Check for potential mudslide conditions
if (acceleration_magnitude > 2.0 && soil_moisture > THRESHOLD_MOISTURE) {
Serial.println("Potential mudslide detected!");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mudslide Alert!");
lcd.setCursor(0, 1);
lcd.print("Take precautions!");
// Add any additional actions or notifications here
}
delay(1000); // Adjust the delay based on your application's requirements
}
#include <DHT.h>
#define DHT_Pin 4
float temperature;
float humidity;
uint16_t counter;
// Set up the DHT sensor
DHT dht(DHT_Pin, DHT22); // Instantiate a dht element from the DHT object
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Set the baud rate of UART
Serial.println("Hello, DHT22!");
}
void loop() {
// put your main code here, to run repeatedly:
temperature = dht.readTemperature(); //temperature from the dht
humidity = dht.readHumidity(); //humidity from the dht
Serial.println("Data: "+ String(counter));
// Print the values of temperature in Celsus
Serial.print("Temperatue:\t");
Serial.print(dht.readTemperature(false));
Serial.println("C");
// Print the values of temperature in Fahrenheit
Serial.print("Temperatue:\t");
Serial.print(dht.readTemperature(true));
Serial.println("F");
// print Humidity in perscent
Serial.println("Humidity: \t"+String(humidity)+ "%");
// Print the values of the heat Index for both Units
Serial.print("Heat Index In Celsus: ");
Serial.println(dht.computeHeatIndex(temperature, humidity, false));
Serial.print("Heat Index In Fahrenheit: ");
Serial.println(dht.computeHeatIndex(temperature, humidity, true));
Serial.println(" ");
delay(1000); // this speeds up the simulation
counter++;
}
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* server = "api.thingspeak.com";
const char* apiKey = "3IJLOHAFMEYDCMBL";
const char* channelID = "2262786";
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
mpu.initialize();
connectWiFi();
// Check if the MPU6050 is connected
if (mpu.testConnection()) {
Serial.println("MPU6050 connection successful");
} else {
Serial.println("MPU6050 connection failed. Please check your connections.");
while (1);
}
}
void loop() {
// Read raw accelerometer and gyroscope values
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Print the sensor data
Serial.print("Accelerometer: ");
Serial.print("X = "); Serial.print(ax); Serial.print(" | ");
Serial.print("Y = "); Serial.print(ay); Serial.print(" | ");
Serial.print("Z = "); Serial.println(az);
Serial.print("Gyroscope: ");
Serial.print("X = "); Serial.print(gx); Serial.print(" | ");
Serial.print("Y = "); Serial.print(gy); Serial.print(" | ");
Serial.print("Z = "); Serial.println(gz);
Serial.println();
sendToThingSpeak(ax, ay, az, gx, gy, gz);
delay(1000); // Adjust the delay based on your application's requirements
}
void connectWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void sendToThingSpeak(int ax, int ay, int az, int gx, int gy, int gz) {
String url = "/update?api_key=" + String(apiKey) +
"&field4=" + String(ax) +
"&field5=" + String(ay) +
"&field6=" + String(az) +
"&field7=" + String(gx) +
"&field8=" + String(gy) +
"&field9=" + String(gz);
WiFiClient client;
HTTPClient http;
if (http.begin(client, server, 80, url)) {
int httpCode = http.GET();
if (httpCode > 0) {
Serial.println("Data sent to ThingSpeak successfully.");
} else {
Serial.println("Error in sending data to ThingSpeak.");
}
http.end();
} else {
Serial.println("Error in connecting to ThingSpeak.");
}
}
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
lcd.clear();
lcd.setCursor(5,0);
lcd.print("I2C LCD");
lcd.setCursor(5,1);
lcd.print("INTERFACING");
}