Home IoT Hub Series · 15
[Part 15] Do not leave windows open in the rain - rain-sensor node
Detect rainwater with a rain sensor module and send a wet/dry value to the hub.
This part detects rainwater with a simple rain sensor plate. It is useful for windows, laundry, balcony plants, and outdoor alerts.
The sensor plate can face the rain, but the controller board should stay inside a protected box.
![[Part 15] Do not leave windows open in the rain - rain-sensor node hero image](/iot-lab/assets/rain-sensor-hero.png)
This article is part of the Home IoT Hub system connected to the central NodeMCU server built in Part 2: Building the Brain. The rain sensor reports rain contact for window, laundry, and outdoor-node protection decisions. The collected data is sent over the local
IoT_Hub_Net network and updates slot 18 for rain detection on the central server (/set?no18=value), becoming part of the decision pipeline for the 20-channel smart-home controller.Parts and cost
| Part | Qty | Unit price |
|---|---|---|
| Wemos D1 Mini | 1 pc | $1.50 |
| rain sensor module | 1 pc | $0.70 |
| Jumper wires 3 pc | — | — |
| Total | $2.20 |
Pin wiring
| Sensor / module | Board pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| AOUT | A0 |
Full code
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> const char* ssid = "IoT_Hub_Net"; const char* password = "iothub1234"; const char* hubURL = "http://192.168.1.1"; #define RAIN_PIN A0 #define SLOT_NO 18 #define THRESHOLD 500 // 500 or lower = raining #define INTERVAL 10000 void setup() { Serial.begin(115200); pinMode(RAIN_PIN, INPUT); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connecting to IoT_Hub_Net"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected!"); } void loop() { int raw = analogRead(RAIN_PIN); int rain = (raw < THRESHOLD) ? 1 : 0; Serial.print("Rain: "); Serial.print(raw); Serial.print(" -> "); Serial.println(rain ? "RAINING" : "DRY"); WiFiClient client; HTTPClient http; String url = String(hubURL) + "/set?no" + String(SLOT_NO) + "=" + String(rain); http.begin(client, url); http.GET(); http.end(); Serial.println("HTTP -> " + url); delay(INTERVAL); }
Upload and check
Connect the Wemos D1 Mini to the PC with a USB data cable, select the ESP8266 board and port in the Arduino IDE, upload the sketch, then open Tools → Serial Monitor and set the baud rate to 115200.
Serial Monitor
After uploading, open Tools → Serial Monitor in the Arduino IDE and set the baud rate to 115200. The following is an example Serial Monitor flow for checking normal operation. This is not a real screenshot. It shows intermittent sensor-board power used to reduce electrode corrosion.
[BOOT] Home IoT Node #15 - Rain sensor [POWER] rain board VCC=ON for 800 ms [SENSOR] rain_raw=736 threshold=500 rain=NO [POWER] rain board VCC=OFF to prevent corrosion [HTTP] GET /set?no18=0 [HUB] 200 OK - slot no18=DRY [LOOP] next rain check in 300000 ms
- If
Connectedorconnectedappears, the Wi-Fi step passed. - If
HTTP 200or200 OKappears, the value reached the brain server. - If the value does not update, check both the slot number in the URL and the sensor wiring.
Build notes
- Touch the plate with a wet finger or a few water drops and confirm the hub changes the Rain slot.
- Power on the hub brain first so the node can join
IoT_Hub_Net. - Use the same slot number written in the source code.
- Open the serial monitor at 115200 baud and confirm
HTTP 200. - If the value does not appear on the hub, recheck wiring, GPIO number, and Wi-Fi connection.
Putting the Rain Sensor to Work
A rain sensor reports Clear/Raining the moment drops hit its sensing plate. Simple as it is, it makes a great trigger for everyday automation. Wired into your Home IoT Hub, it shines in these situations.
Ways to Use It
- Laundry, window and balcony alerts: Get a phone notification when rain starts while you are out, so you remember the laundry on the line or the open window.
- Automatic awnings and smart plugs: With a hub rule, a Raining signal can retract a motorized awning or cut power to an outdoor smart plug, reducing shock and short-circuit risk.
- Smart plant watering: Skip the watering pump on rainy days to avoid wasting water and over-soaking. Perfect for balcony gardens and small plots.
- Camping and car camping: Placed on a tarp or tent, it warns you of pre-dawn rain so you can prepare in time.
Recommended Placement
- Put it where the sky is open and rain lands directly. Avoid spots shielded by eaves or awnings.
- Always mount the plate at a 15-30 degree tilt so water runs off instead of pooling. Laid flat, it keeps reporting 'Raining' long after the rain stops.
- Keep it away from air-conditioner units and drain hoses: condensation and drip water get mistaken for rain. Stay out of lawn sprinkler range too.
Troubleshooting checkpoints
The node code can look short, but real home installation is affected by placement, power, Wi-Fi quality, and sensor noise. Check these points before letting the node become a decision input for the brain server.
| Symptom | Likely cause | Field fix |
|---|---|---|
| The electrodes corrode within days | Continuous 5V across wet electrodes causes electrolysis | Power VCC from a digital pin only during measurement, then set it LOW to reduce corrosion. |
| It still says rain after the rain stops | Water film or dirt keeps surface resistance low | Mount the board at a slight angle and clear the rain state only after continuous dry readings. |
| Dew or fog is detected as rain | The board senses wetness, not actual rainfall amount | Lower sensitivity and interpret it together with outdoor temperature/humidity and time conditions. |
| Readings are unstable in winter | Ice or frost remains across electrodes | Use it as a reference in winter or replace it with a waterproof optical rain sensor if control accuracy matters. |
Practical Tips and Cautions
- Cleaning schedule: The plate's copper traces collect dust, fine dust and oxidation over time, dulling sensitivity. Wipe it every month or two with a dry brush or an alcohol swab.
- Threshold tuning: Read the analog value, not just the digital output, to tell drizzle from a downpour. Use the module's trimmer to raise or lower the threshold for your environment.
- Dew and frost false alarms: Morning condensation and frost are water too, so they read as rain. Add a 'only if it persists for several minutes' condition to your alert rule to cut false positives sharply.
- Waterproofing and wiring: The plate may get wet, but never let the board or connectors flood. House the controller in a waterproof box, and add a downward U-shaped drip loop in the cable so water cannot track back into the enclosure.
FAQ
Q. It still shows 'Raining' after the rain stopped.
Water is lingering on the plate. Tilt it more steeply and nudge the analog threshold up so it returns to Clear as soon as the film of water thins out.
Q. Does it detect snow?
Dry snow is hard to catch; it only reacts once snow melts into water on the plate. Treat winter precipitation detection as a rough backup only.
Q. How long does the plate last?
Outdoors, sensitivity drops from corrosion after about 6 months to a year. The plate is cheap to replace on its own, so swap it when response gets sluggish.
This article is part of the 20-channel Home IoT system built from the Part 2 central brain server and the distributed edge nodes in Parts 3-19. Use this map to check the slot and sensor flow across the series.
[Part 1] Home IoT Hub overview[Part 2] Central brain server · slots 1-20[Part 3] Stop guessing room comfort · slots 1/2[Part 4] Did I close the door? · slots 9[Part 5] Is the fridge really cooling? · slots 12[Part 6] Should I open the window? · slots 3[Part 7] Stop bathroom mold before it starts · slots 19[Part 8] Is the boiler actually running? · slots 5/17[Part 9] Did I leave the gas stove on? · slots 6[Part 10] Get warned before gas smell becomes obvious · slots 7[Part 11] Catch flame signs while away from home · slots 8[Part 12] Is bad air making you foggy? · slots 13/14[Part 13] Why is the power bill so high? · slots 15[Part 14] Is water leaking, and how much are we using? · slots 16[Part 15] Do not leave windows open in the rain · slots 18[Part 16] Are the lights off and the door locked? · slots 11/10[Part 17] Control the air conditioner from the IoT hub · slots 4[Part 18] Is the dog bowl empty? · slots 20[Part 19] Cool the room only when someone is there · slots 1/4[Part 20] The house finally fits on one screen · slots all