Rain Sensor

Z2M Part: EMS-00024-A

Detect rain or water droplets.

Circuit Diagram
Circuit diagram for Rain Sensor
Wire Connections & Pin Configuration

Wire Color Connections:

Yellow → Analog Pin A1 to Rain sensor (code uses A1), Pin 2 to Digital
Red → 5V to Rain sensor VCC
Black → GND to Rain sensor GND

Pin Configuration:

Arduino Analog Pin A0 → Rain sensor A0 (or Digital D0)
Arduino 5V → Rain sensor VCC
Arduino GND → Rain sensor GND
Arduino Code
Edit
const int Digvalue = 2;  // Digital output pin from rain sensor
const int Analogval = A1; // Analog output pin from rain sensor

int val_analog; // Variable to store analog reading

void setup() {
  pinMode(Digvalue, INPUT);
  pinMode(Analogval, INPUT);
  Serial.begin(9600); // Initialize Serial Monitor at 9600 baud
}

void loop() {
  // Check digital rain detection status
  if (digitalRead(Digvalue) == LOW) {
    Serial.println(\"Digital value : wet\");  // When sensor detects water
    delay(12);
  } else {
    Serial.println(\"Digital value : dry\");  // When sensor detects no water
    delay(12);
  }

  // Read analog value from rain sensor
  val_analog = analogRead(Analogval);
  Serial.print(\"Analog value : \");
  Serial.println(val_analog);  // Display analog moisture value
  Serial.println(\"\");

  delay(1000); // Wait for 1 second before next reading
}

Instruction Details

Wiring: Connect rain sensor VCC to 5V, GND to GND. Connect digital OUT to Digital Pin 2, analog OUT to Analog Pin A1.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Open Serial Monitor (Tools → Serial Monitor) at 9600 baud. Wet/dry status and analog value display. Add water to sensor to test.

How to Use

  1. Connect the required components as per the Pin Configuration above
  2. Open Arduino IDE and create a new sketch
  3. Copy and paste the code above
  4. Select your Arduino board and COM port from Tools menu
  5. Click the Upload button to upload the code to your Arduino
  6. Open Serial Monitor (if applicable) to see the output

Components Required

  • Arduino Uno
  • Rain Sensor Module (YL-83 or similar)
  • Breadboard
  • Jumper Wires

Category: Sensors