Home ARDUINO How to Build Rain Detector Using Arduino

How to Build Rain Detector Using Arduino

In this tutorial switched acoustic sounders as rain alarms after a predetermined period of time. However, it may be used for some other applications. Needless to say, this is a simple experiment for Arduino beginners, but if the result is unique, it would be happier to try an experiment.

How to Build Rain Detector Using Arduino

Project Goal

The goal is to use pre-wired rain sensor modules with Arduino. Rain sensor module based on LM393 chip specifications are as follows:

  • Working voltage: 5V
  • Indicators: power indicator and output indicator
  • User Control: On-board sensitivity adjustment potentiometer
  • Output: Digital (DO) and Analog (AO)

Here, the analog output (AO) of the Rainfall Sensor Module is connected to an analog input (A0) of the Arduino so that the microcontroller can read an analog voltage between 0 and 5 volts to handle a number between 0 and 1023, Where 0 is 0 volts and 1023 is 5 volts.

How Sensor Work?

If the rain sensor module’s rain sensor board is dry, the module’s analog output (AO) is 5V. In the rain sensor plate elements are bridged by rain and so the analog output gradually changes from 5 volts to 0 volts based on the humidity level between the sensor pads.

In this way, the sensor reports the presence or absence of rainwater in an analog way and helps us determine whether the rain is bright or intense by analyzing the output analog signals.

The approximation is handled by a simple Arduino sketch. Another function is to delay the generation of alarms; the Arduino will not sound an alarm until it detects a certain threshold of rainfall over a predefined time interval.

This extra feature helps reduce the number of false positives to a certain extent. In a given sketch, the rainfall threshold is 300 and the time delay is 30 seconds.

Let’s Get Started to Build Rain Detector Using Arduino

A quick and easy getting started guide to using and exploring the Rainfall Sensor Module is sometimes referred to as the “Raindrop Sensor Module” with the Arduino.

Since I recently wrote a tutorial on flame sensors, I think a water sensor might just be a good equalizer.

Collect Hardware

  • Rain sensor (with analog output) (Buy Amazon )
  • 3x male to female jumper
  • 2 x female to female jumper
  • An Arduino, Any Model Buy Here
  • The source of water

Sensor Detail

How to Build Rain Detector Using Arduino

Usages of Sensor
Rain sensors are used to detect moisture levels that moisture sensors can detect.

How Sensor get the data with Water

Rain sensor detects the circuit on the printed circuit board of the sensor board. The sensor board acts as a variable resistor, changing from 100k ohms wet to 2M ohms dry. In short, the damper the board, the more current it will carry.


Module Pins

A0………. Analog output

D0……… Digital output

GND….. Ground

VCC…… Positive voltage (input: 5v for analog 3.3v for Digital.)

Loop Pins:

  • ………. Sensor board hookup A


  • ………. Sensor board hookup B

Let’s test

How to Build Rain Detector Using Arduino

To test the rain sensor and make sure it works, connect VCC to the 5v power supply and GND. Try placing a few drops of water on the Rain sensor test board and the D0-LED should light up.


If the D0-LED is not on, check the following:

  1. Is the module connected correctly?
  2. Sometimes salinity is a problem for these devices, which work well in filtered bottled water but in some cases, you may need to add a little salt to increase water conduction.
  3. This can be a bit trickier, but for some reason, two different types of welding technology from two different manufacturers are flawed. Make sure all the small SMDs and connectors are properly soldered. IE – Is the solder joint actually soldered?
  4. If the D0-LED did not illuminate before, your sensor may be defective.

Arduino Connectivity

To connect the rain sensor to the Arduino for simulation, simply connect the following devices as shown below:

Rain Sensor …………….. Arduino

VCC…………………………….. 5v

GND………………………….. GND

A0……………………………. Analog in 0

Rain Sensor ……………. Sensor Board

+……………………………… +

-………………………………. –

Note: if you are beginner in Arduino then please have a look at my previous article “Beginner guide for Arduino

Upload Source Code

/* Flame Sensor analog example.


Code By Ammar

For use with a Rain Sensor with an analog out!

To test view the output, point a serial monitor such as Putty at your Arduino.

  – If the Sensor Board is completely soaked; “case 0″ will be activated and ” Flood ” will be sent to the serial monitor.

  – If the Sensor Board has water droplets on it; “case 1″ will be activated and ” Rain Warning ” will be sent to the serial monitor.

  – If the Sensor Board is dry; “case 2″ will be activated and ” Not Raining ” will be sent to the serial monitor.




// lowest and highest sensor readings:

const int sensorMin = 0;     // sensor minimum

const int sensorMax = 1024;  // sensor maximum


void setup() {

  // initialize serial communication @ 9600 baud:



void loop() {

  // read the sensor on analog A0:

                int sensorReading = analogRead(A0);

  // map the sensor range (four options):

  // ex: ‘long int map(long int, long int, long int, long int, long int)’

                int range = map(sensorReading, sensorMin, sensorMax, 0, 3);


  // range value:

  switch (range) {

 case 0:    // Sensor getting wet



 case 1:    // Sensor getting wet

    Serial.println(“Rain Warning”);


 case 2:    // Sensor dry – To shut this up delete the ” Serial.println(“Not Raining”); ” below.

    Serial.println(“Not Raining”);



  delay(1);  // delay between reads


How to Build Rain Detector Using Arduino

When I used this code in production, I ignored the output of this example, except for alerts of “rain warnings” and “floods.”

To view the output, indicate on your Arduino a serial monitor such as Putty.

This code is constantly updated to provide real-time feedback from the rain sensor.

NOTE If you face any problem regarding this project then please write comment below

Visit similar projects tutorials on Raspberry Pi and Arduino

How to Build your own Super Computer with Raspberry Pi 3 Cluster

Build Super Computer with 5$ Raspberry pi zero using Cluster HAT

How to make a Raspberry Pi bitcoin mining rig

Convert Any Printer into a Wireless Printer with a Raspberry Pi zero (10$ Cost)
Build AYI Google Voice Home with Raspberry Pi Under 35$

Best Raspberry Pi Alternatives ( Updated 2018 List)

Control your PC with hand Gesture using Arduino and Ultrasonic Sensors