Interface Rain Drop Detection Sensor With ESP32

Here’s the code and wiring instructions to interface a Rain Drop Detection Sensor with an ESP32. The LED will glow when rain is detected.

Hardware Required:

  • ESP32 Development Board
  • Rain Drop Detection Sensor
  • LED
  • Resistor (220Ω for LED)
  • Breadboard & Jumper Wires

Wiring Connections:

  1. Rain Drop Sensor:
    • VCC (Red wire) → 3.3V (ESP32)
    • GND (Black wire) → GND (ESP32)
    • DO (Digital Output, usually white) → GPIO 23 (ESP32)
  2. LED:
    • Anode (+, longer leg) → GPIO 21 (ESP32)
    • Cathode (-, shorter leg) → 220Ω Resistor → GND

Arduino Code:

#define RAIN_SENSOR_PIN 23  // Digital pin connected to the rain sensor
#define LED_PIN 21          // Digital pin connected to the LED

void setup() {
  pinMode(RAIN_SENSOR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  int rainDetected = digitalRead(RAIN_SENSOR_PIN);

  if (rainDetected == LOW) {  // LOW means rain is detected
    digitalWrite(LED_PIN, HIGH); // Turn LED on
    Serial.println("Rain Detected!");
  } else {
    digitalWrite(LED_PIN, LOW);  // Turn LED off
    Serial.println("No Rain");
  }
  delay(500); // Check every 500 ms
}

Explanation:

  • Rain Sensor: Outputs LOW when rain is detected because it works like a switch (closed when wet).
  • LED: Glows when rain is detected (when the sensor output is LOW).
  • Serial Monitor: Shows status messages (“Rain Detected!” or “No Rain”).

Troubleshooting Tips:

  1. Ensure proper grounding between ESP32, sensor, and LED.
  2. Adjust the delay if you want faster or slower response times.
  3. Test the sensor by dripping water directly on it.