Read a raindrop sensor with an Arduino

FunduinoPublished on

Flüssigkeit erkennen und bei Regen Alarm schlagen

Der Tropfensensor ist so einfach gebaut, wie ein Sensor nur sein kann: zwei ineinandergreifende Leiterbahnen, zwischen denen Wasser eine Brücke bildet. Schon ein einzelner Tropfen genügt für einen eindeutigen Messwert.

In dieser Anleitung liest du den Sensor aus und baust daraus einen Regenmelder, der bei den ersten Tropfen ein Signal gibt – die Grundlage für eine Markise, die sich von selbst einrollt.

Narrow circuit board with interlocking comb-shaped traces
The water drop sensor with its long contact strips
Drop sensor with three wires for a microcontroller
Wiring: Plus to 5V, minus to GND, S to A0
1 / 2

You need this

Water level sensor - analog output, 3.3-5 V Water level sensor - analog output, 3.3-5 V 1,05 € *Item no. F23107273About the product — Water level sensor - analog output, 3.3-5 V
5 V buzzer - electromagnetic sounder, 2400 Hz 5 V buzzer - electromagnetic sounder, 2400 Hz 0,90 € *Item no. F23108736About the product — 5 V buzzer - electromagnetic sounder, 2400 Hz
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm

All 6 parts together 19,45 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Material

For this project, you need:

  • 1× microcontroller with a suitable USB cable
  • 1× raindrop sensor
  • 1× breadboard
  • Male-to-male and male-to-female jumper wires

For the expansion in the final step, add:

  • 1× piezo buzzer

How the sensor works

Two long, comb-shaped, interlocking conductive tracks run across the sensor. One is connected to positive, the other to negative. When they’re dry, no current flows - as soon as a drop connects both tracks, a small current flows from one to the other.

The module conditions this current and outputs it as a voltage to an analog input. The Arduino can’t measure voltage directly, so it converts it into a numerical value: 0 to 5 volts corresponds to values from 0 to 1023.

When dry, the value is close to 0. A single drop of water raises it to about 480, and it increases further with more water.

As a rain sensor, it can be used for all sorts of things: retracting an awning, closing blinds, triggering an alarm, or starting a windshield wiper.

Narrow circuit board with interlocking comb-shaped traces
The water drop sensor with its long contact strips

Structure

The sensor has three connections:

  • + → 5V
  • − → GND
  • S → analog input A0

Important for continuous operation: If voltage is constantly applied to the contact tracks while they are wet, electrolysis will corrode the sensor. In our tests in water, damage occurred after just around 24 hours.

So don't measure every second; measure no more than every 15 minutes. Better still, power the sensor through a digital pin instead of 5V, and switch it on only when taking a measurement.

Drop sensor with three wires for a microcontroller
Wiring: Plus to 5V, minus to GND, S to A0

Read measurement value

Programming is very simple and works just like reading a potentiometer: only one analog value is read and output.

Upload the sketch and open the Serial Monitor at 9600 baud. Dab a little water onto the sensor and watch the value rise.

To test it, you can briefly set the delay in the sketch to 500 milliseconds. But remember to increase it again for continuous operation—otherwise, the sensor will be worn out after a day.

Sketch 1: Display the measured value in the serial monitor
int messwert = 0;  // Unter "messwert" wird der Messwert des Sensors gespeichert.

void setup()
{
  // Die Kommunikation mit dem seriellen Port wird gestartet.
  // Das braucht man, um den ausgelesenen Wert im Seriellen Monitor zu sehen.
  Serial.begin(9600);
}

void loop()
{
  // Die Spannung am Sensor wird ausgelesen und gespeichert.
  messwert = analogRead(A0);

  Serial.print("Feuchtigkeits-Messwert: ");
  Serial.println(messwert);

  // Lange Pause bis zur naechsten Messung.
  // 15 Minuten = 15 * 60 * 1000 Millisekunden.
  // Zum schnellen Ausprobieren kannst du hier voruebergehend 500 einsetzen -
  // fuer den Dauerbetrieb sollte die Pause aber lang bleiben.
  delay(900000);
}

Extension: Rain sensor alarm

A signal should sound as soon as a drop hits the sensor. To do this, connect the piezo buzzer: positive to pin 6, and the other terminal to GND.

We'll use 400 as the threshold, because a single drop gives a reading of about 480. If the reading is higher, the buzzer sounds; if it drops below that, it goes quiet again.

An active buzzer produces a tone with a simple digitalWrite. A passive piezo, on the other hand, needs an alternating signal and remains silent with digitalWrite - that's why this sketch uses tone(). This works with both types.

Raindrop sensor and piezo buzzer on a microcontroller
Extended setup with piezo buzzer on pin 6
Sketch 2: Rain Drop Alarm
int messwert = 0;
int PIEPS = 6;   // Mit dem Namen "PIEPS" wird jetzt Pin 6 bezeichnet, an dem der Summer haengt.

void setup()
{
  Serial.begin(9600);
  pinMode(PIEPS, OUTPUT);  // Pin 6 wird als Ausgang festgelegt.
}

void loop()
{
  messwert = analogRead(A0);
  Serial.print("Feuchtigkeits-Messwert: ");
  Serial.println(messwert);

  // Abfrage: Wenn der Sensorwert groesser als 400 ist ...
  if (messwert > 400)
  {
    tone(PIEPS, 1000);  // ... soll der Summer einen Ton ausgeben.
  }
  else                  // ... ansonsten ...
  {
    noTone(PIEPS);      // ... bleibt es still.
  }

  // Auch hier gilt: im Dauerbetrieb lange Pausen setzen, sonst
  // zerstoert die Elektrolyse den Sensor innerhalb eines Tages.
  delay(900000);
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.