Rain Sensor Tutorial
Hello friends, and welcome back to the “SriTu Hobby” blog. Today we will learn about the rain sensor. 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 knowledge)Below you can see this sensor.

What is a Rain sensor?
This rain sensor is made up of two main parts.
The Sensor Pad

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

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 also 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.
- Arduino UNO board x 1 — Amazon / Our Store
- Rain sensor x 1 — Amazon / Our Store
- Breadboard x 1 — Amazon / Our Store
- LED bulb x 1 — Amazon / Our Store
- Jumper wires — Amazon / Our Store
Ok, let’s learn this project step by step.
Step 1
Let’s identify these components.
Arduino UNO board

Rain sensor

Breadboard

LED bulb

Jumper wires

Step 2
Now connect these components, For that, using the circuit diagram below. In this example, only the Analog PIN is used.

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
First, the serial monitor of the VOID SETUP is enabled. Also, the PIN connected to the LED bulb is converted to an OUTPUT PIN.
void setup() {
Serial.begin(9600);//enable serial monitor
pinMode(4, OUTPUT);//define LED pin
}
Next, we get the Sensor analog value in the VOID LOOP and put it in an Integer type variable. It is named as “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.
if (value < 300) {//check condition
digitalWrite(4, HIGH);
Serial.print(“Heavy rain LED on “);
} else {
digitalWrite(4, LOW);
}
Step 4
Well, now we will upload this program to the Arduino board. After selecting the correct board and port, upload it.



You can watch the video guide here on my SriTu Tech channel. The full video guide is given below. We will meet in the next article.
RAIN SENSOR Tutorial | RAIN SENSOR with Arduino Uno
What is the code for replacing led with a buzzer…Pls share it…
/*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); } }
COM 1 OPTION IS NOT DISPLAYING IN MY SOFTWARE
It depends on your computer. Otherwise, please install COM port drivers.
what if using a battery 9v or 3v as power supply? how is the connection?
You can use a 9v battery for that.
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