Introduction
This experiment shows how to use a rain detection sensor with an Arduino to detect rainfall.

Components Needed
- Rain Detection Sensor
- Arduino (e.g., Uno, Nano)
- LED
- 220-ohm Resistor
- Jumper wires
Circuit Setup
- Connect the rain sensor's output pin to a digital input pin on the Arduino (e.g., D2).
- Connect the LED to a digital output pin using a 220-ohm resistor in series.
The LED will light up when the rain sensor detects water droplets.

Code for Rain Detection Sensor
Upload the following code to your Arduino to detect rain:
const int rainPin = 2;
const int ledPin = 13;
void setup() {
pinMode(rainPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(rainPin) == HIGH) {
digitalWrite(ledPin, HIGH); // LED on when rain is detected
} else {
digitalWrite(ledPin, LOW); // LED off when no rain
}
}
Explanation
The rain sensor detects water droplets on its surface and sends a HIGH signal to the Arduino when it detects rain. This triggers the LED to light up.
Troubleshooting
- If the sensor does not detect rain, check the sensor's connection and calibration.
- If the LED remains on, ensure that the sensor is dry when testing it.