#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int raindropPin = A0; // Analog pin for the simulated raindrop 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
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows); // Change the address if needed
const int rainThreshold = 400; // Adjust the raindrop value
void setup() {
Serial.begin(9600);
lcd.begin(lcdColumns, lcdRows); // Initialize the LCD screen
lcd.print("Display Rain Details");
delay(2000);
lcd.clear();
umbrellaServo.attach(3); // Attach the servo to the specified pin
umbrellaServo.write(0); // Set the initial position of the servo (closed)
}
void loop() {
int raindropValue = analogRead(raindropPin);
lcd.setCursor(0, 0);
if (raindropValue > 0) {
lcd.print("Yes Raining ");
} else {
lcd.print("No Rain ");
}
Serial.print("Raindrop: ");
Serial.println(raindropValue);
if (raindropValue == 0) {
Serial.println("No Rain!");
lcd.setCursor(0, 1);
lcd.print("Umbrella: Closed ");
umbrellaServo.write(0); // Close the umbrella (0 degrees)
} else if (raindropValue < rainThreshold) {
Serial.println("Moderate Rain!");
lcd.setCursor(0, 1);
lcd.print("Umbrella: Open ");
umbrellaServo.write(90); // Open the umbrella (90 degrees)
} else {
Serial.println("Heavy Rain!");
lcd.setCursor(0, 1);
lcd.print("Umbrella: Open ");
umbrellaServo.write(90); // Open the umbrella (90 degrees)
}
delay(1000); // Adjust delay based on your needs
}