#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int raindropPin = A0; // Analog pin for the simulated raindrop sensor
const int dhtPin = 2; // Digital pin for the DHT22 sensor
const int servoPin = 3; // Digital pin for the servo motor
const int lcdColumns = 20; // Number of columns in your LCD
const int lcdRows = 4; // Number of rows in your LCD
Servo umbrellaServo; // Create a servo object for the umbrella
DHT dht(dhtPin, DHT22); // Create a DHT object for the DHT22 sensor
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows); // Change the address if needed
const int rainThreshold = 400; // Adjust the rain threshold based on your observation
const int temperatureThreshold = 30; // Adjust the temperature threshold based on your needs
bool isUmbrellaOpen = false;
void setup() {
Serial.begin(9600);
umbrellaServo.attach(servoPin); // Attach the servo motor to the specified pin
dht.begin(); // Initialize the DHT22 sensor
lcd.begin(lcdColumns, lcdRows); // Initialize the LCD screen
lcd.print("Welcome to the Smart umbrella System ");
delay(2000);
lcd.clear();
}
void loop() {
int raindropValue = analogRead(raindropPin);
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
lcd.setCursor(0, 0);
lcd.print("Raindrop: ");
if (raindropValue < rainThreshold){
lcd.print("Yes");
}
else {lcd.print("No");}
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.print(temperatureC);
lcd.print(" C");
Serial.print("Raindrop: ");
Serial.println(raindropValue);
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println("°C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
if ((raindropValue < rainThreshold || temperatureC > temperatureThreshold) && !isUmbrellaOpen) {
Serial.println("Opening the umbrella!");
openUmbrella();
lcd.setCursor(0, 1);
lcd.print("Umbrella: Open ");
} else if (raindropValue >= rainThreshold && temperatureC <= temperatureThreshold && isUmbrellaOpen) {
Serial.println("Closing the umbrella!");
closeUmbrella();
lcd.setCursor(0, 1);
lcd.print("Umbrella: Closed");
}
delay(1000); // Adjust delay based on your needs
}
void openUmbrella() {
// Simulate the umbrella opening
umbrellaServo.write(180); // Turn the servo to 180 degrees (clockwise)
delay(1000);
isUmbrellaOpen = true;
}
void closeUmbrella() {
// Simulate the umbrella closing
umbrellaServo.write(0); // Turn the servo to 0 degrees (counter-clockwise)
delay(1000);
isUmbrellaOpen = false;
}