A rain detector is an essential automation tool that alerts users about rainfall, enabling proactive responses like closing windows or protecting outdoor equipment or even getting the clothes which were dried outside. In this project we use an Arduino (an open-source microcontroller platform) and a low-cost rain sensor to create a reliable, real-time rain detection system. When raindrops hit the sensor, the Arduino triggers a buzzer, providing immediate alerts. Ideal for beginners, this guide ensures 100% working results with minimal components.
Table of Contents
How the Rain Sensor Works
The rain sensor employs an intelligent two-board design that transforms precipitation into actionable electronic signals. At its core lies the Rain Board (sensing pad), featuring intricately spaced parallel copper traces etched onto a fiberglass substrate.

Under dry conditions, these isolated traces maintain extremely high electrical resistance (≈1 MΩ), allowing the board’s output voltage to remain near its maximum 5V supply level. When rain contacts the surface, water molecules bridge the copper pathways, creating conductive channels that dramatically lower resistance – a direct relationship where increased wetness proportionally reduces resistance. This resistance drop fundamentally alters voltage behavior: output voltage decreases linearly as moisture accumulates, governed by Ohm’s Law (V = I × R). For example, moderate dampness (≈300kΩ) yields ~2-3V, while saturation (≈50kΩ) drives voltage below 1V. This analog voltage signal exits the Rain Board via two signal output pins (SIG+ and GND) that connect seamlessly to the Control Board.
The companion Control Board serves as the system’s brain, equipped with an LM393 comparator chip that interprets the Rain Board’s voltage fluctuations. Here, the analog signal undergoes critical processing: noise-filtering circuits stabilize readings before the comparator contrasts the voltage against a user-defined threshold (adjustable via a blue potentiometer). This triggers two distinct outputs – the Analog Output (AO) delivers raw voltage (0-5V) for measuring rainfall intensity, while the Digital Output (DO) snaps to LOW when moisture surpasses the threshold, enabling simple rain detection.
- Light drizzle (≈300kΩ) might yield 3V → Arduino reads ≈614
- Moderate rain (≈150kΩ) generates 1.5V → Arduino reads ≈307
- Heavy downpour (≤50kΩ) drives voltage toward 0V → Arduino reads ≤10
The mathematical conversion is governed by:
ADC Value = (Analog Voltage × 1023) / 5
Example: At 3V output → (3 × 1023)/5 = 613.8 (rounded to 614)
Dual LEDs provide visual diagnostics: red confirms power, while green illuminates during rain detection. This sophisticated separation of sensing and processing allows field-replaceable Rain Boards in corrosive environments while keeping electronics protected – a pivotal design innovation for durable outdoor deployment in Arduino weather stations, smart farms, or leak detection systems.
Required components
| Product Name | Quantity | ||
|---|---|---|---|
| Arduino Nano or UNO | 1 | https://amzn.to/3jVNZON | https://amzn.to/3KpUQry |
| Rain sensor | 1 | https://amzn.to/4sZsbAA | https://amzn.to/4vg675Z |
| Buzzer | 1 | https://amzn.to/3vAHi8L | https://amzn.to/4bWA9nV |
| 5V power supply (Micro USB or External). | 1 | https://amzn.to/3s1a8g3 | https://amzn.to/364yInH |
| Few Connecting Wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
Circuit diagram interfacing Rain sensor with Arduino
Now connect all the required components according to the below circuit diagram to build the rain detection system.

From the above circuit diagram we can see the rain sensor is powered using 5v and GND pins of Arduino, Digital output pin DO of sensor is connected to one of the Digital pins of Arduino D2( To use measure the rain intensity connect analog Output AO sensor pin to A0 of Arduino). Buzzer is +ve pin is connected to a digital pin of Arduino D3 and -ve pin is connected to GND.
Make Your Arduino Rain Detector Project Professional with PCBWay
Building a Rain Detector using Arduino and a Rain Sensor is a fun and practical project—but why stop at a prototype? Turn your DIY setup into a professional-grade device with PCBWay’s custom PCB manufacturing and 3D printing services.
Instead of messy jumper wires and fragile breadboards, you can design a custom PCB where your Arduino, rain sensor module, relays, LEDs, and other components are neatly soldered onto a single board. This ensures a compact, durable, and reliable circuit, ready for real-world use in gardens, rooftops, and smart irrigation systems.
PCBWay offers affordable PCB fabrication starting at just $5, with options for SMT assembly, so you receive ready-to-use boards with high-quality soldering and precise finishing.
To make your Rain Detector weatherproof and installation-friendly, you can also use PCBWay’s professional 3D printing services. Design a custom enclosure to protect your electronics from moisture, rain, and dust—giving your project a polished and market-ready look.
Why PCBWay?
- High-quality custom PCBs with fast turnaround
- SMT Assembly for professional soldering
- 3D Printed enclosures for durability and aesthetics
- One-stop solution from design to final product
Take your Arduino Rain Detector project from a prototype to a fully functional product with PCBWay.
Start today at www.pcbway.com.
Waterproofing:
Only Rainboard is waterproof apply silicon at signal output pins after connecting them to control board. Control board is not waterproof use any enclosure or 3D printed case to pack it and apply silicon at joints and wire passthroughs.
Also refer our Related project: Live Weather Station using NodeMCU
Program code for Arduino IDE
After connecting all the components according to the circuit diagram, its time to upload the code. To upload the code install Arduino IDE on PC and open it. Copy the below code and paste in the Arduino IDE workspace and from tools menu select board as Arduino NANO or UNO which ever you are using and select correct port and Hit upload button. It first compiles the code by checking errors and then uploads it to your Arduino board.
/*
* Rain Detection System CircuitSchools
* Arduino Nano with Rain Sensor and Buzzer
*
* Connections:
* - Rain Sensor VCC -> Arduino 5V
* - Rain Sensor GND -> Arduino GND
* - Rain Sensor DO -> Arduino D2 (Digital Output)
* - Buzzer +ve -> Arduino D3
* - Buzzer -ve -> Arduino GND
*/
// Pin definitions
const int RAIN_DIGITAL_PIN = 2; // Digital output from rain sensor
const int BUZZER_PIN = 3; // Buzzer control pin
// Variables
int digitalValue = 0; // Digital reading from sensor
bool rainDetected = false; // Rain detection flag
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pin modes
pinMode(RAIN_DIGITAL_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Initialize buzzer to OFF
digitalWrite(BUZZER_PIN, LOW);
Serial.println("Rain Detection System Initialized");
Serial.println("================================");
}
void loop() {
// Read digital value from rain sensor
digitalValue = digitalRead(RAIN_DIGITAL_PIN);
// Check if rain is detected (digital pin goes LOW when rain is detected)
if (digitalValue == LOW) {
rainDetected = true;
// Activate buzzer
digitalWrite(BUZZER_PIN, HIGH);
// Print rain detection info
Serial.println("*** RAIN DETECTED! ***");
Serial.print("Digital Value: ");
Serial.println(digitalValue);
Serial.println("Buzzer: ON");
Serial.println("------------------------");
} else {
rainDetected = false;
// Turn off buzzer
digitalWrite(BUZZER_PIN, LOW);
// Print no rain status (every 5 seconds to avoid spam)
static unsigned long lastPrint = 0;
if (millis() - lastPrint > 5000) {
Serial.println("No rain detected");
Serial.println("Buzzer: OFF");
Serial.println("------------------------");
lastPrint = millis();
}
}
// Small delay to prevent excessive readings
delay(500);
}
After uploading your Arduino rain detector code, power the system and verify operation through these steps:
- Confirm the power LED illuminates on the sensor board;
- Check the serial monitor displays “System ready – No rain detected”;
- Sprinkle water on the sensing pad – within 2 seconds the buzzer should sound, your alert LED should light, and the serial monitor should show “RAIN DETECTED!”;
- Wipe the pad dry – within 5 seconds all alerts should deactivate and serial output returns to standby status.
For reliability testing: spray water from 30cm height (simulating light rain), validate instant alerts, then adjust the sensor’s blue potentiometer clockwise to reduce sensitivity (requiring more water to trigger) or counterclockwise for higher sensitivity. Ensure no false triggers occur during humidity changes or when touching nearby components.
Pro Tip: Mount the sensor at 20° angle during testing to validate proper water runoff and alert cancellation.
Advanced Rain Detection Program code:
/*
* Advanced Rain Detection System
* Arduino Nano with Rain Sensor and Buzzer
*
* Connections:
* - Rain Sensor VCC -> Arduino 5V
* - Rain Sensor GND -> Arduino GND
* - Rain Sensor DO -> Arduino D2 (Digital Output)
* - Rain Sensor AO -> Arduino A0 (Analog Output)
* - Buzzer +ve -> Arduino D3
* - Buzzer -ve -> Arduino GND
*/
// Pin definitions
const int RAIN_DIGITAL_PIN = 2; // Digital output from rain sensor
const int RAIN_ANALOG_PIN = A0; // Analog output from rain sensor
const int BUZZER_PIN = 3; // Buzzer control pin
// Variables
int digitalValue = 0; // Digital reading from sensor
int analogValue = 0; // Analog reading from sensor
bool rainDetected = false; // Rain detection flag
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pin modes
pinMode(RAIN_DIGITAL_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Initialize buzzer to OFF
digitalWrite(BUZZER_PIN, LOW);
Serial.println("Rain Detection System Initialized");
Serial.println("================================");
}
void loop() {
// Read digital value from rain sensor
digitalValue = digitalRead(RAIN_DIGITAL_PIN);
// Read analog value from rain sensor (0-1023)
analogValue = analogRead(RAIN_ANALOG_PIN);
// Check if rain is detected (digital pin goes LOW when rain is detected)
if (digitalValue == LOW) {
rainDetected = true;
// Activate buzzer
digitalWrite(BUZZER_PIN, HIGH);
// Print rain detection info
Serial.println("*** RAIN DETECTED! ***");
Serial.print("Digital Value: ");
Serial.println(digitalValue);
Serial.print("Analog Value: ");
Serial.println(analogValue);
// Determine rain intensity based on analog value
if (analogValue > 700) {
Serial.println("Rain Intensity: Light");
} else if (analogValue > 400) {
Serial.println("Rain Intensity: Moderate");
} else {
Serial.println("Rain Intensity: Heavy");
}
Serial.println("Buzzer: ON");
Serial.println("------------------------");
} else {
rainDetected = false;
// Turn off buzzer
digitalWrite(BUZZER_PIN, LOW);
// Print no rain status (every 5 seconds to avoid spam)
static unsigned long lastPrint = 0;
if (millis() - lastPrint > 5000) {
Serial.println("No rain detected");
Serial.print("Analog Value: ");
Serial.println(analogValue);
Serial.println("Buzzer: OFF");
Serial.println("------------------------");
lastPrint = millis();
}
}
// Small delay to prevent excessive readings
delay(500);
}
Here’s a short explanation of the rain detection code:
Setup:
- Defines pins: D2 for rain sensor digital output, A0 for analog intensity, D3 for buzzer
- Initializes serial communication and sets pin modes
Main Loop:
- Reads digital value from rain sensor (LOW = rain detected)
- Reads analog value for rain intensity (0-1023 scale)
Rain Detection Logic:
- When digital pin is LOW (rain detected):
- Turns buzzer ON
- Prints “RAIN DETECTED” message
- Shows rain intensity based on analog value:
- 700 = Light rain
- 400-700 = Moderate rain
- <400 = Heavy rain
No Rain:
- When digital pin is HIGH (no rain):
- Turns buzzer OFF
- Prints status every 5 seconds to avoid spam
Output on serial monitor
Rain Detection System Initialized ================================ No rain detected Analog Value: 1023 Buzzer: OFF ------------------------ No rain detected Analog Value: 1018 Buzzer: OFF ------------------------ //Light Rain Detected// *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 750 Rain Intensity: Light Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 715 Rain Intensity: Light Buzzer: ON ------------------------ //Rain Intensity Increases (Moderate)// *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 650 Rain Intensity: Moderate Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 520 Rain Intensity: Moderate Buzzer: ON ------------------------ //Heavy Rain// *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 380 Rain Intensity: Heavy Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 320 Rain Intensity: Heavy Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 280 Rain Intensity: Heavy Buzzer: ON ------------------------ //Rain Gradually Stops// *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 450 Rain Intensity: Moderate Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 680 Rain Intensity: Light Buzzer: ON ------------------------ *** RAIN DETECTED! *** Digital Value: 0 Analog Value: 820 Rain Intensity: Light Buzzer: ON ------------------------ Rain Stops Completely No rain detected Analog Value: 950 Buzzer: OFF ------------------------ ///No rain detected// Analog Value: 1010 Buzzer: OFF ------------------------ No rain detected Analog Value: 1023 Buzzer: OFF ------------------------ No rain detected Analog Value: 1023 Buzzer: OFF ------------------------
Practical Applications
- Smart Home Automation:
- Auto-close windows via servo motors
- Retract motorized awnings/sunshades
- Agricultural Optimization:
- Pause irrigation systems during rain
- Protect crops with automated greenhouse roofs
- Vehicle Safety Systems:
- Activate windshield wipers
- Close sunroofs automatically
- Flood Early-Warning:
- SMS alerts via GSM module (SIM800L)
- Siren activation in flood-prone areas
- Weather Stations:
- Rainfall intensity logging (using AO pin)
- Historical data analysis with SD cards
FAQs: Expert Troubleshooting
Q1. Why does my sensor trigger falsely?
A: Adjust potentiometer, clean traces with alcohol, or move away from EMI sources.
Q2. Can I measure rainfall intensity?
A: Yes! Use AO pin + analogRead(A0). Values 200–300 = light rain; <100 = heavy downpour.*
Q3. How to make the sensor last longer outdoors?
A: Apply silicone conformal coating, tilt at 20°, and use controlled power (as in our circuit).
Q4. What’s the difference between active and passive buzzers?
A: Active buzzers have built-in oscillators (use with digitalWrite). Passive buzzers need PWM frequencies.
Q5. Can I add a 12V actuator?
A: Yes! Connect a 5V relay module to Digital Pin 5, then wire the actuator through the relay.
Conclusion
This rain detector project demonstrates a cost-effective, reliable solution for rainfall monitoring using Arduino and a rain sensor. With real-time alerts via buzzer/LED, it’s perfect for hobbyists, educators, and DIY smart home enthusiasts. By expanding this system with IoT capabilities or automated actuators, you can transform it into a professional-grade tool. Build it today and never get caught off-guard by sudden downpours again!

After a couple of months you will find that the rain detection circuit board has corroded due to electrolysis!