automatic rain cloth collector working model – Arduino Code

#include <Servo.h>

Servo clothServo;

const int rainSensorPin = 2;  // Digital output of rain sensor
const int servoPin = 9;       // Servo signal wire

void setup() {
  pinMode(rainSensorPin, INPUT);
  clothServo.attach(servoPin);

  clothServo.write(90);       // Start with cover open
  Serial.begin(9600);
}

void loop() {
  int rainState = digitalRead(rainSensorPin);

  // Most rain sensor modules output LOW when wet
  if (rainState == LOW) {
    clothServo.write(0);      // Rain: close cover
    Serial.println(“Rain detected – Cover CLOSED”);
  } else {
    clothServo.write(90);     // No rain: open cover
    Serial.println(“No rain – Cover OPEN”);
  }

  delay(500);
}

Leave a Comment