Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Rain Sensor Controlled Automatic Cover with Solar-Powered Battery Backup

View and Edit Project In Cirkit DesignerImage of Arduino UNO Rain Sensor Controlled Automatic Cover with Solar-Powered Battery Backup

Circuit Documentation

Summary

This circuit is designed to monitor a rain sensor and control two servos to manage a cover. When rain is detected, one servo pulls the cover to close it, and when no rain is detected, the other servo rolls the cover back. The system is powered by a solar panel and a battery, with the solar panel charging the battery when there is sunlight. The circuit also includes an LED and a buzzer to provide visual and auditory alerts when rain is detected.

Component List

  1. RAIN SENSOR

    • Pins: AO, DO, GRD, VCC
    • Description: Detects rain and provides both analog and digital outputs.
  2. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller used to control the servos, read the rain sensor, and manage the LED and buzzer.
  3. Solar Panel

    • Pins: +, -
    • Description: Provides power to the system by charging the battery.
  4. LM2596

    • Pins: IN, OUT
    • Description: Voltage regulator used to step down the voltage from the solar panel to a suitable level for the battery and other components.
  5. 18650 in holder

    • Pins: GND, VCC
    • Description: Rechargeable battery used to power the system when there is no sunlight.
  6. LED: Two Pin (orange)

    • Pins: Cathode, Anode
    • Description: Provides a visual indication when rain is detected.
  7. Resistor (200 Ohms)

    • Pins: Pin1, Pin2
    • Description: Limits current to the LED and buzzer.
  8. Buzzer

    • Pins: POSITIVE, NEGATIVE
    • Description: Provides an auditory indication when rain is detected.
  9. MG996R Servo

    • Pins: GND, VCC, SIG
    • Description: Controls the movement of the cover.

Wiring Details

RAIN SENSOR

Arduino UNO

Solar Panel

LM2596

18650 in holder

LED: Two Pin (orange)

Resistor (200 Ohms)

Buzzer

MG996R Servo

Code Documentation

/*
 * This sketch monitors a rain sensor and controls two servos to manage a cover.
 * When rain is detected, Servo 2 pulls the cover to close it.
 * When no rain is detected, Servo 1 rolls the cover back.
 * The solar panel charges the battery when there is sunlight.
 * The system runs on battery power when there is no sunlight.
 */

#include <Servo.h>

// Pin definitions
const int rainSensorDigitalPin = 2;
const int rainSensorAnalogPin = A0;
const int ledPin = 3;
const int buzzerPin = 4;
const int servo1Pin = 5;
const int servo2Pin = 6;

// Servo objects
Servo servo1;
Servo servo2;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(rainSensorDigitalPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  // Attach servos to their respective pins
  servo1.attach(servo1Pin);
  servo2.attach(servo2Pin);

  // Initial positions for servos
  servo1.write(0); // Servo 1 starts at 0 degrees
  servo2.write(0); // Servo 2 starts at 0 degrees
}

void loop() {
  // Read the digital value from the rain sensor
  int rainDetected = digitalRead(rainSensorDigitalPin);

  // Read the analog value from the rain sensor
  int rainAnalogValue = analogRead(rainSensorAnalogPin);

  // Print the analog value to the serial monitor
  Serial.print("Rain Sensor Analog Value: ");
  Serial.println(rainAnalogValue);

  if (rainDetected == HIGH) {
    // Rain detected
    digitalWrite(ledPin, HIGH); // Turn on LED
    digitalWrite(buzzerPin, HIGH); // Turn on Buzzer
    servo2.write(90); // Move Servo 2 to 90 degrees to pull the cover
    delay(1000); // Wait for 1 second
  } else {
    // No rain detected
    digitalWrite(ledPin, LOW); // Turn off LED
    digitalWrite(buzzerPin, LOW); // Turn off Buzzer
    servo1.write(90); // Move Servo 1 to 90 degrees to roll back the cover
    delay(1000); // Wait for 1 second
  }

  delay(1000); // Wait for 1 second before next loop
}

This code initializes the rain sensor, LED, buzzer, and servos. It continuously monitors the rain sensor and controls the servos, LED, and buzzer based on the presence of rain. The solar panel charges the battery, which powers the system when there is no sunlight.