Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

Rain sensor with Arduino Uno — rain levels without a corroded plate

Wire a rain sensor plate and LM393 board to an Arduino Uno R3, power it from D7 only while reading to stop corrosion, and grade dry, drizzle and heavy rain.

Arduino C++Verified — core avr 1.8.8, 3 Nov 2026Compile-only

Community draft — report a mistake

A rain sensor is a plate of interleaved copper tracks plus a small LM393 comparator board. Water bridging the tracks lowers the resistance, so the analog output falls as the plate gets wetter. It is used for rain alarms, to close a window, or to skip a garden-watering cycle in the monsoon.

The Uno has one easy trick for this sensor. Instead of wiring VCC to 5V, wire it to D7 and turn that pin on only while reading. The plate then carries current for a few milliseconds every few seconds instead of all the time, and it lasts far longer. The board needs only a few mA, well inside what a Uno pin can give.

The sketch reads the analog value on A0 and the comparator output on D2 every 5 seconds, and grades the result from dry to heavy rain.

Wiring

Arduino Uno R3Only the pins used are shown · 5 V logicRain sensor (FC-37 / YL-83)GNDA0D2D7VCCGNDDOAO
Every connection
Arduino Uno R3Rain sensor (FC-37 / YL-83)WireNotes
D7VCCredPowered from a pin set HIGH only while reading. The board draws well under the pin’s 20 mA.
GNDGNDblack
A0AOyellow
D2DOgreenOptional on/off output. Set the threshold with the blue pot.

3.3–5 V part, 5 V board. AO and DO swing up to VCC. Power the module from 3.3 V on ESP32/Pico so AO stays within the ADC range.

Board quirks

  • With constant DC on the plate, electrolysis eats the tracks in a few weeks of monsoon. Powering it from D7 for 20 ms every 5 s cuts that to almost nothing.
  • The comparator board isn’t waterproof. Mount only the plate outside, tilted so water runs off, and keep the small board in a box indoors.
  • AO is about 1000 when dry and drops towards 200–300 under heavy rain. The thresholds in the sketch are a starting point — check yours with a few drops of water.
  • Mud and dust on the plate make it read “wet” for hours after the rain stops. Wipe it now and then.

Code

rain-uno.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// Rain sensor (plate + LM393 comparator board) on an Arduino Uno R3.
// VCC → D7 (powered only while reading, so the plate doesn't corrode), GND → GND,
// AO → A0, DO → D2. AO falls as the plate gets wetter.
const uint8_t POWER_PIN = 7, AO_PIN = A0, DO_PIN = 2;

void setup() {
  pinMode(POWER_PIN, OUTPUT);
  digitalWrite(POWER_PIN, LOW);
  pinMode(DO_PIN, INPUT);
  Serial.begin(9600);
  Serial.println(F("Rain sensor - one reading every 5 s"));
}

void loop() {
  digitalWrite(POWER_PIN, HIGH);
  delay(20);  // let the comparator settle
  int wet = analogRead(AO_PIN);
  bool rainDO = digitalRead(DO_PIN) == LOW;  // DO goes LOW past the pot threshold
  digitalWrite(POWER_PIN, LOW);

  Serial.print(F("AO "));
  Serial.print(wet);
  Serial.print(F("  DO "));
  Serial.print(rainDO ? F("wet") : F("dry"));
  Serial.print(F("  -> "));
  if (wet > 900) Serial.println(F("Dry"));
  else if (wet > 600) Serial.println(F("Drizzle"));
  else if (wet > 350) Serial.println(F("Rain"));
  else Serial.println(F("Heavy rain"));
  delay(5000);
}

Expected serial output

Serial Monitor · 9600Output
Rain sensor - one reading every 5 s
AO 1012  DO dry  -> Dry
AO 720  DO wet  -> Drizzle
AO 310  DO wet  -> Heavy rain

Common errors

Always reads about 1023

The plate isn’t connected to the comparator board, or VCC isn’t switching. Check the two-wire plate cable and that D7 goes HIGH.

Reads wet long after the rain stopped

The plate is flat and holds water. Tilt it 30–45°.

DO never changes

Turn the blue pot until the DO LED just goes out when dry. DO only works while the board is powered, which is during the reading.

↑↓ to move · Enter to open