Index
Introduction
The Raindrop Sensor is used to detect rainfall using a rain-sensing board and a control module.
The sensor provides both analog and digital outputs, which the ESP32 can read to determine rain intensity or presence.
It is commonly used in automatic wiper systems, agricultural irrigation, and home automation for smart weather response.
Required Components
- ESP32 Board
- Rain Drop Sensor
- Jumper wires
- Breadboard
Pinout

Circuit Diagram / Wiring
- Rain Sensor VCC → VIN (ESP32)
- Rain Sensor GND → GND (ESP32)
- Rain Sensor DO → 14 (ESP32)
- Rain Sensor AO → 34 (ESP32)

Code / Programming
/*
Filename: esp32_raindrop_sensor.ino
Description: Reads analog and digital values from a raindrop sensor using ESP32.
Digital pin reports rain detection. Analog pin gives intensity.
Author: www.oceanlabz.in
Modification Date: 1/4/2025
*/
// Define sensor pins
const int analogPin = 34; // Use an ADC1-compatible analog pin on ESP32
const int digitalPin = 14; // Digital output pin from the sensor
void setup() {
Serial.begin(115200); // Start serial communication at 115200 baud
pinMode(digitalPin, INPUT); // Set digital pin as input
Serial.println("Raindrop Sensor Initialized");
}
void loop() {
int analogValue = analogRead(analogPin); // Read analog value
int digitalValue = digitalRead(digitalPin); // Read digital output
Serial.print("Analog Value: ");
Serial.print(analogValue);
Serial.print(" | Digital Value: ");
Serial.println(digitalValue == LOW ? "Rain Detected" : "No Rain");
delay(1000); // Delay before next reading
}
Explanation
- The sensor detects the presence and intensity of rain using a conductive surface that changes resistance when wet.
- The analog pin on ESP32 measures moisture level, while the digital pin detects rain presence (HIGH = dry, LOW = wet).
- This setup is ideal for automating actions like alerts, wipers, or irrigation during rainfall.
Troubleshooting
- If analog values stay constant, clean the rain board and ensure good wire connections.
- If digital value never changes, try adjusting the onboard potentiometer to set the correct rain threshold.
- Use GPIO 32–39 only for analog readings to avoid issues with ESP32’s ADC functionality.
Project 1: ESP32 Rain Drop Detection System with OLED Display
Introduction
This project uses an ESP32 and a rain drop sensor to detect rainfall in real-time. When rain is detected, the OLED display shows a visual warning message. It’s a simple yet effective solution for smart weather monitoring or automated outdoor systems. Ideal for DIY home automation, smart irrigation, and IoT-based weather stations.
Required Components
- ESP32 Board
- Rain Drop Sensor
- OLED Display
- Jumper wires
- Breadboard
Circuit Diagram / Wiring
- Rain Sensor VCC → VIN/5V (ESP32)
- Rain Sensor GND → GND (ESP32)
- Rain Sensor AO → 34 (ESP32)
- OLED VCC → 3.3 V (ESP32)
- OLED GND → GND (ESP32)
- OLED SDA → GPIO 21 (ESP32)
- OLED SCK → GPIO 22 (ESP32)

Code / Programming
/*
Filename: esp32_raindrop_oled.ino
Description: Displays rain detection status on OLED using ESP32 and rain sensor.
Author: www.oceanlabz.in
Modification: 1/4/2025
*/
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED display configuration
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Define GPIO pin for rainDrop sensor (ESP32 input-only pin)
const int rainDropPin = 34; // Use GPIO34 (analog input capable)
void setup() {
Serial.begin(115200); // Higher baud rate for ESP32
// Initialize rain sensor pin
pinMode(rainDropPin, INPUT);
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println(F("Initializing..."));
display.display();
delay(2000);
}
void loop() {
int rainDropState = digitalRead(rainDropPin); // Read digital signal from sensor
Serial.println(rainDropState);
display.clearDisplay();
display.setTextSize(2);
if (rainDropState == LOW) { // Adjust if sensor gives LOW when rain is detected
display.setCursor(15, 15);
display.println(F("Rain Drop"));
display.setCursor(15, 45);
display.println(F("Detected."));
} else {
display.setCursor(50, 0);
display.println(F("NO"));
display.setCursor(15, 20);
display.println(F("Rain Drop"));
display.setCursor(15, 45);
display.println(F("Detected."));
}
display.display();
delay(100);
}
Explanation
- Uses a rain drop sensor connected to ESP32 to detect presence of rain through analog input.
- Displays real-time rain status (“Rain Drop Detected” / “No Rain Drop Detected”) on a 128×64 OLED screen.
- Continuously monitors and updates output every 100ms for responsive weather feedback.
Troubleshooting
- OLED Not Displaying: Ensure correct I2C address (
0x3C
) and proper wiring (SDA to GPIO 21, SCL to GPIO 22 by default). - No Sensor Response: Verify sensor power (3.3V/5V), check analog pin configuration, and ensure rainDrop pin is correctly connected.
- Unstable Readings: Use a short delay (100–200ms) and consider using
analogRead()
with threshold logic for better sensitivity.