Rain Sensor with Arduino UNO

Rain Sensor with Arduino UNO
Atribot team

Written by

Atribot team

Last updated

June 18, 2026

Introduction

The Rain Sensor is a simple and effective sensor used to detect the presence and intensity of rain. It is commonly used in weather monitoring systems, automatic wiper systems, smart irrigation projects, and home automation applications.

In this tutorial, you will learn how to interface a Rain Sensor with an Arduino UNO, upload the code, and monitor rain detection status using the Serial Monitor. By the end of this guide, you'll understand how to detect rainfall and moisture on the sensor plate using Arduino.

Components Required

Swipe right to view full table
Item NameQtyAction
1
Rain Sensor
1
USB Cable
1
Breadboard
1
Jumper Wires
5

Tools Required

Swipe right to view full table
Item NameAction
Soldering Iron
Screwdriver

Software Required

Swipe right to view full table
Item NameAction
Arduio IDE

Circuit Diagram

Rain Sensor with Arduino UNO
Rain Sensor with Arduino UNO

Source Code

Rain_Sensor_with_Arduino_UNO.inocpp
const int rainSensorPin = 2;

void setup()
{
  pinMode(rainSensorPin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  int rainState = digitalRead(rainSensorPin);

  if(rainState == LOW)
  {
    Serial.println("Rain Detected");
  }
  else
  {
    Serial.println("No Rain");
  }

  delay(1000);
}

Step by Step Instructions

Step 1: Connect the Rain Sensor

Make the following connections:

Swipe right to view full table

Rain Sensor

Arduino UNO

VCC

5V

GND

GND

DO

D2

Step 2: Open Arduino IDE

  1. Launch Arduino IDE.

  2. Connect Arduino UNO using USB.

  3. Select:

    • Board → Arduino UNO

    • Port → Correct COM Port

Step 3: Create a New Sketch

Create a new Arduino sketch and paste the provided code.

Step 4: Verify the Code

Click the Verify button to check for syntax errors.

Step 5: Upload the Code

Click Upload and wait until the upload process completes successfully.

Step 6: Open Serial Monitor

  1. Open Serial Monitor.

  2. Set the baud rate to 9600.

  3. Touch the sensor plate with a wet finger or sprinkle a few drops of water on it.

  4. Observe the detection messages.

The Serial Monitor will display the rain detection status.

Expected Output

When the sensor is dry:

No Rain
No Rain
No Rain

When water is detected:

Rain Detected
Rain Detected
Rain Detected

Conclusion

In this tutorial, you learned how to interface a Rain Sensor with Arduino UNO and detect the presence of water using digital input. This setup can be used in weather monitoring stations, automatic irrigation systems, rain alarm projects, and various environmental monitoring applications.