Projects / Balcony garden rain cover

Balcony garden rain cover

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP32RAIN

    Find the rain level

    Print the analog value dry and with a few drops and set WET_BELOW.

  2. ESP3259°

    Wire the servo

    Add the capacitor and check it swings between the two angles.

  3. ESP32

    Fit the limit switches

    Mount one at each end of the cover's travel.

  4. ESP32

    Test the logic

    Drip water on the plate and watch the cover close after ten seconds.

  5. ESP32

    Test the override

    Press the button to open and close by hand.

  6. ESP32

    Mount outside

    Put the controller under shelter and tilt the plate.

In short

How do you build a balcony garden rain cover?

A motorised cover closes over plants when rain starts and opens when it stops, with a manual button. You need ESP32 DevKit V1, Rain drop sensor module, SG90 Micro Servo, Limit switch (micro switch with lever) × 2, Tactile push button 6 mm, Electrolytic capacitor 1000 µF and 5 V 2 A USB adapter. It takes 6 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
5 V USB adapter +Servo red, rain module VCC and ESP32 VINPower
5 V USB adapter -Servo brown, rain module GND, switch GND and ESP32 GNDCommon ground
1000 µF capacitorAcross the servo power wires, + to 5 VAbsorbs servo surges
Rain sensor board AOESP32 GPIO34Wetness level
Servo signalESP32 GPIO18Cover drive
Limit switch (cover open)ESP32 GPIO25 and GNDLow when the cover is fully open
Limit switch (cover closed)ESP32 GPIO26 and GNDLow when the cover is fully closed
Manual buttonESP32 GPIO27 and GNDToggle open or closed

Code

Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". Install "ESP32Servo". The servo is only strong enough to move a light cover or roller, so mount the limit switches where the cover ends its travel. The rain plate's analog output drops when wet; print it to find your own WET_BELOW value. Mount the electronics under a small roof, keep the plate sloped so water runs off, and keep cables dry. Check the cover regularly so it never traps a plant or finger.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <ESP32Servo.h>

Servo drive;
const byte RAIN = 34, SW_OPEN = 25, SW_CLOSED = 26, BTN = 27;
const int OPEN_ANGLE = 10, CLOSED_ANGLE = 100;
const int WET_BELOW = 2200;                          // the analog value falls when the plate gets wet
const unsigned long DRY_WAIT = 15UL * 60000UL;       // open again after 15 dry minutes
unsigned long lastWet = 0, wetSince = 0, moveStart = 0;
bool wantClosed = false, moving = false;

void command(bool close) {
  wantClosed = close; moving = true; moveStart = millis();
  if (!drive.attached()) drive.attach(18);
  drive.write(close ? CLOSED_ANGLE : OPEN_ANGLE);
}

void setup() {
  pinMode(SW_OPEN, INPUT_PULLUP); pinMode(SW_CLOSED, INPUT_PULLUP); pinMode(BTN, INPUT_PULLUP);
  analogSetPinAttenuation(RAIN, ADC_11db);
  command(false);
}

void loop() {
  bool wet = analogRead(RAIN) < WET_BELOW;
  if (wet) { if (wetSince == 0) wetSince = millis(); lastWet = millis(); } else wetSince = 0;

  if (!wantClosed && wetSince != 0 && millis() - wetSince > 10000) command(true);          // wet for 10 s: close
  if (wantClosed && !wet && millis() - lastWet > DRY_WAIT) command(false);                 // dry for 15 min: open
  if (!digitalRead(BTN)) { command(!wantClosed); delay(400); }                             // manual override

  bool arrived = wantClosed ? !digitalRead(SW_CLOSED) : !digitalRead(SW_OPEN);
  if (moving && (arrived || millis() - moveStart > 8000)) {                                // stop at the limit switch, or give up
    moving = false;
    delay(300);
    drive.detach();                                                                        // no holding current once there
  }
  delay(100);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
DryCover open
Water on the plate for 10 sCover closes and stops at the closed switch
Dry for 15 minutesCover opens again
Press the buttonToggles the cover

If it does not work

Cover never closes

Adjust WET_BELOW and check the plate wiring.

Servo hums at the end

The limit switch did not trigger. Move it or reduce the angle.

Servo twitches

Add the capacitor and a proper 5 V supply.

Cover opens too soon

Increase the dry wait.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the balcony garden rain cover?

ESP32 DevKit V1, Rain drop sensor module, SG90 Micro Servo, Limit switch (micro switch with lever) × 2, Tactile push button 6 mm, Electrolytic capacitor 1000 µF and 5 V 2 A USB adapter.

How long does the balcony garden rain cover take to build?

About 150 minutes for a intermediate maker, in 6 steps.

How do I know the balcony garden rain cover works?

Dry: Cover open. Water on the plate for 10 s: Cover closes and stops at the closed switch. Dry for 15 minutes: Cover opens again.

Cover never closes: what should I check?

Adjust WET_BELOW and check the plate wiring.

Servo hums at the end: what should I check?

The limit switch did not trigger. Move it or reduce the angle.

Servo twitches: what should I check?

Add the capacitor and a proper 5 V supply.

Cover opens too soon: what should I check?

Increase the dry wait.