The rain sensor module (Product code: SN-RAIN-MOD) is used to detect the amount of water present on the sensor and with a controller, it can further control output. The rain sensor module consist of two parts, that is the sensor probes and the module board. If you are interested with the specification of the sensor, you can download the getting started guide.
In this tutorial, I am going to show you how to make a simple rain alert system using the rain sensor module.
The sensor board is exposed in open space where not roof blocking the rain. When the sensor detect water droplets on it, it will changes the analog voltage that is being read by the controller, in this case the Arduino. Arduino will further activate the buzzer to alert that there is rain. In addition, the sensor can be digital (present or absence of water droplets) or analog(how much water droplets on the sensor).
Basically, the connection is looks like this.
* Buzzer can connect directly to Arduino output pin.
* Remember that if you want to have PWM output (almost like analog output), the buzzer should connect only to either pin 3, 5, 6, 10, or 11.
* More water will result in lower analog voltage.
[sourcecode language=”cpp” wraplines=”true”]
int sensorpin=A0; //setting the sensor pin
int outputpin=3; //setting the output pin
int water; //the variable to control
Serial.begin(9600); //must begin to use serial monitor
pinMode(sensorpin,INPUT); //setting sensor pin to be input
pinMode(outputpin,OUTPUT); //setting output pin to be output
water=analogRead(sensorpin); //read the value from sensor pin
Serial.println(water); //show the value receive in serial monitor
loudness=((1023-water)/1023)*255; //the range of sensor value is from 0-1023
//the range of Arduino output pin is from 0-255
//by this formula, more water, buzzer louder
Do check out the working concept of rain sensor: