#include #define RAIN_SENSOR_PIN A0 // Analog pin for rain sensor #define SERVO_PIN 9 // Digital pin for servo motor Servo servoMotor; // Create a servo object void setup() { pinMode(RAIN_SENSOR_PIN, INPUT); servoMotor.attach(SERVO_PIN); Serial.begin(9600); // Initialize serial communication } void loop() { int rainValue = analogRead(RAIN_SENSOR_PIN); // Read analog value from rain sensor int servoAngle; // Variable to store servo angle // Convert sensor reading to servo angle (adjust as needed based on sensor characteristics) servoAngle = map(rainValue, 0, 1023, 0, 180); // Limit servo angle to prevent damage to the roof system servoAngle = constrain(servoAngle, 0, 180); // Control servo motor based on rain intensity if (rainValue < 500) { // If rain intensity is low (adjust thresholds as needed) servoMotor.write(0); // Close the roof Serial.println("Roof Closed"); } else { // If rain intensity is high servoMotor.write(servoAngle); // Adjust the roof angle based on rain intensity Serial.print("Roof Adjusted, Angle: "); Serial.println(servoAngle); } delay(1000); // Delay for stability }