#include <OneWire.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int raindropPin = A0;
const int servoPin = 3;
const int lcdColumns = 20;
const int lcdRows = 4;
Servo umbrellaServo;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
const int rainThreshold = 200;
bool isUmbrellaOpen = false;
void setup() {
Serial.begin(9600);
lcd.begin(lcdColumns, lcdRows);
lcd.print("Display Rain Fall Details");
delay(2000);
lcd.clear();
}
void loop() {
int raindropValue = analogRead(raindropPin);
lcd.setCursor(0, 0);
lcd.print("Raindrop: ");
if (raindropValue < rainThreshold){
lcd.print("Yes");
}
else {lcd.print("No");}
Serial.print("Raindrop: ");
Serial.println(raindropValue);
if ((raindropValue < rainThreshold) && !isUmbrellaOpen) {
Serial.println("Opening the umbrella!");
lcd.print("Umbrella: Open ");
openUmbrella();
lcd.setCursor(0, 1);
}
else if (raindropValue >= rainThreshold && isUmbrellaOpen) {
Serial.println("Closing the umbrella!");
lcd.print("Umbrella: Closed");
closeUmbrella();
lcd.setCursor(0, 1);
}
delay(1000);
}
void openUmbrella() {
umbrellaServo.write(180);
delay(1000);
isUmbrellaOpen = true;
}
void closeUmbrella() {
umbrellaServo.write(0);
delay(1000);
isUmbrellaOpen = false;
}