RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

Hello friends, and welcome back to the “SriTu Hobby” blog. Today we will learn how to use the Rain sensor with Arduino UNO board. We can understand the function of using this sensor by its name here. Also, we can easily measure rainfall as well as snowfall through this sensor. For these reasons, this sensor can be used for a variety of purposes in our home. For example, if it rains when we are not at home, it can be used to close windows automatically, and if there are fabrics outside, it can be used to move them automatically inside the house. etc. (These projects depend on your skill)You can see the sensor below.

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

What is a Rain sensor?

This rain sensor is made up of two main parts.

The Sensor Pad

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

It is made up of exposed copper particles on both sides. It acts as a variable resistor. This resistance value varies according to the amount of water falling on it. That resistance value is inversely proportional to the amount of water. Good conductivity occurs when more water flows over the sensor surface. Then there is less resistance. Also, when a small amount of water flows over this surface, it has poor conductivity, thereby increasing the resistance. Because of this concept, we can get an output voltage through this.

The Module

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

The sensor pad presented above should be connected to this. So, we can get the output voltage of the sensor pad as an analog value through this module. Also, the LM393 High Precision Comparator here converts the analog value into a digital value. You can also change the sensitivity of the digital value with the Potentiometer here.

In this module, you can see six PINs. Sensor pads + and – should be connected with the two pins marked above. The other four pins are described below.

  • VCC – This pin must have a potential between 3.3v – 5v.
  • GND – This should attach to the cathode terminal.
  • AO – This pin can be used to get the rainfall value as an analog value.
  • DO – This pin can be used as a digital value for rainfall.

Okay, now we will learn how this sensor works with Arduino. The required components are as follows.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Now connect these components, For that, use the circuit diagram below. In this example, I used an analog pin.

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

Step 3

Then we will create the required program for this. We can see it below. With this program, we can see the rainfall value in the serial monitor. We can get it as an analog value. If the analog value is high we can identify it as low rainfall and if the analog value is low we can identify it as high rainfall. According to this program, if the analog value is less than 300, the LED bulb will turn on.

  • The complete program of this project – Download
/*How to use rain sensor.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creations.
*/
void setup() {
  Serial.begin(9600);//enable serial monitor
  pinMode(4, OUTPUT);//define LED pin
}
void loop() {
  int value = analogRead(A3);//read value
  Serial.print("Value : ");
  Serial.println(value);
  if (value < 300) {//check condition
    digitalWrite(4, HIGH);
    Serial.print("Heavy rain  LED on ");
  } else {
    digitalWrite(4, LOW);
  }
}

Code explanation

In the void setup, the serial monitor is enabled. Also, the LED pin is set as the Output pin.

void setup() {
  Serial.begin(9600);//enable serial monitor
  pinMode(4, OUTPUT);//define LED pin
}

In the VOID LOOP takes the sensor analog value and puts it into a variable of type Integer. It is named “value” and then the value is printed on the serial monitor.

  int value = analogRead(A3);//read value
  Serial.print(“Value : “);
  Serial.println(value);

Finally, the value is checked by an IF condition and if it is less than 300, the LED bulb is turned ON and the “Heavy rain LED on” is printed on the serial monitor. Otherwise, the code is designed to turn OFF the LED bulb.

Step 4

Now, select the board and port. After, click the upload button.

Now, you can test this project. The full video guide is below. So, we hope to see you in the next project or tutorial. Have a good day.

RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno

7 thoughts on “RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno”

    1. /*How to use rain sensor.
      created by the SriTu Hobby team.
      Read the code below and use it for any of your creations.
      */

      #define Buzzerpin 2
      void setup() {
      Serial.begin(9600);//enable serial monitor
      pinMode(4, OUTPUT);//define LED pin
      }

      void loop() {
      int value = analogRead(A3);//read value
      Serial.print(“Value : “);
      Serial.println(value);

      if (value < 300) {//check condition digitalWrite(4, HIGH); digitalWrite(Buzzerpin,HIGH); Serial.print("Heavy rain LED on "); } else { digitalWrite(4, LOW); digitalWrite(Buzzerpin,LOW); } }

  1. Sir can you give a code to connect the rain to a roof…. example ( if the rain is detected roof open, no rain roof closed without using a motor driver

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Select your currency
USD United States (US) dollar
EUR Euro
Scroll to Top