Advertisement
arduino rain sensor

Arduino & Rain Sensor Experiment

arduino rain sensor

The experiment is for switching an acoustic sounder as a rain alarm after a predetermine time. It may, however, be tinkered for a number of other applications. Needless to say, this is a simple experiment for Arduino beginners, but trying an experiment is even more pleasant when the result is something unique.

The goal is now to use a pre-wired rain sensor module with an Arduino. Specification of the LM393 chip- based rain sensor module is given below:

  • Working Voltage: 5V
  • Indicators: Power indicator & Output indicator LEDs
  • User Control: Onboard sensitivity adjustment potentiometer
  • Output: Digital (DO) & Analog (AO)

Here, the analog output (AO) of the rain sensor module is linked to one analog input (A0) of the Arduino, so that the microcontroller can read an analog voltage between 0 and 5 volts to process a number between 0 and 1023, where 0 representing 0 volt, and 1023 representing 5 volt.

rain sensor module

(rain sensor module)

If the rain sensor plate of the rain sensor module is in dry state, analog output (AO) from the module is 5V. During rain, the sensor plate elements are bridged by the rain water and hence this analog output gradually changes from 5V to 0V, based on the moisture level between the sensor pads. By this way, the sensor reports the absence and presence of the rain in an analog way, help us to determine whether the rain is light or strong by analyzing the outputted analog signal. The approximation is handled by a simple Arduino sketch. An additional function is delaying of the alert generation; Arduino raises an alert only when raining with a certain threshold is detected, within a pre-defined time interval. This extra feature helps in reducing false alarm counts to some extent. In the given sketch, rain threshold is 300, and the time delay is 30 sec.

/*
* Arduino Rain Sensor Alarm
* Realized using a pre-wired rain sensor module
* Author: T.K.Hareendran
* Prototyped &Tested at Technode Protolabz /1:04 AM 7/26/2015
* Source: http://www.electroschematics.com
*/
int rainSensePin= 0; // analog pin 0 - sensor i/p
int alertPin= 8; // digital pin 8 - alert o/p
int curCounter= 0; // current counter - goes up by 1 every second while sensing

void setup(){
   Serial.begin(9600);
   pinMode(alertPin, OUTPUT);
   pinMode(rainSensePin, INPUT);
}
void loop(){
   int rainSenseReading = analogRead(rainSensePin);
   Serial.println(rainSenseReading); // use this for serial monitoring if available
   delay(250);  // relax
   // check to see how long it is raining at the threshold level
   // rain strength value from 0 - 1023
   // heavy rain -to- no rain.
   if (curCounter >= 30){ // end of the time delay
      digitalWrite(alertPin, HIGH);  //raise an alert after x time
   }

   // If raining is continuing for x amount of time raise an alert
   // When raining is no longer detected, reset the counter
   if (rainSenseReading <300){ // while raining at threshold level - see text
      curCounter++; // increment sensing counter
   }
   else if (rainSenseReading >300) { // if not raining at threshold level
      digitalWrite(alertPin, LOW); // don't raise an alert
      curCounter = 0; // reset the counter to 0
   }
   delay(1000);
}

When it’s raining (and Arduino detects it) D8 output of the Arduino board goes to “High” level. This D8 output can be used to energise an acoustic sounder (piezo buzzer) or an electric switch ( electromagnetic relay). Refer the hook up diagram to proceed with your experiment.

hook up diagram

(hook up diagram)

As usual, power up the Arduino from an external 9V DC power supply unit. The buzzer/relay driver circuit may be used for voltages in the range 5-12V. However the Vcc must be adapted to the exact voltage and current demand of the connected buzzer/relay.

from authors lab

(from author’s lab)

21 Comments

Join the conversation!

Error! Please fill all fields.
  • Arjun Babu.

    Hello sir’my name is arjun 8std I am trying to make this but the code didn’t work

  • B. Madhusudan

    Mr. Hareendran you are doing great job in popularising the electronics and its applications. we have learnt many fundamental practical things regarding applications, normally which are not available in high level books.

    • T.K.Hareendran

      B. Madhusudan: Happy to note your keen interest in my articles. Further, I thank you for the open comment you left here. Greetings!

  • volthauslab

    Hello Jack,
    The Arduino Uno is a great first choice.
    David@volthauslab. Com

  • Jack Wilborn

    I find these types of fun with computers very enjoyable, but have looked for one of these to experiment with. I am retired, and was a hardware/software specialist and have built many items to add to my computers at home. When I look for one of these Arduino processors, I see many variations between just the processor itself.

    I guess I’m asking if you could direct me (us) to where this might be explained, so I feel good about purchase of the right processor / board.

    Thanks

    Jack

    Peoria, Arizona

  • volthauslab

    I would be very interested in adding this sensor to my 433MHz remote weather station. It currently only sends the outside temp to be displayed on the receivers LCD. I have the sensor but not the comparator (ebay.

    • David Connolly

      Yes T.K. I have the exact sensor you posted in the replay to my post. Thanks.

    • T.K.HAREENDRAN

      & if you want to go through this way,let me know. Analogue output values given by two circuits are different. For example,lm339-based gives 0v when raining (0),but non-lm339 type gives near 5v (1023)at that situation.

    • T.K.Hareendran

      I think you have a “rain sensor-without comparator” module bought from ebay (refer the attached image). Usually such sensors (with a small transistor & two resistors soldered on board) give an analog output (AO) which can be directly used for this project. Just connect its output to your Arduino’s analog input (for example A0).

      On the other hand, if your sensor is a type without the transistor and associated resistors, then try the LM393 comparator shown in the project (see my first comment for article link) & replace the existing sensor with your rain sensor probe.

  • T.K.Hareendran

    @Martin

    Welcome! Hope this will help you to build your own rain sensor. Feel free to revert with your comments/suggestions regarding this project.

  • Martin

    Regarding my previous question:
    What is the coating of the actual metal sensor pad, silver, copper, etc., to prevent it from eventually corrode? Or is that impossible to prevent corrosion over time?

    Thanks.

  • T.K.Hareendran

    Economical modules are available at eBay. I bought two of them from eBay India. Search for “rain/moisture sensor arduino”…

  • Martin

    Hello, maybe I’m missing something, but what is the small circuit board (that houses the LM393 I presume) in between the Arduino and the sensor pad?

    Thanks.

  • Martin

    What is the coating of the actual metal sensor pad, silver, copper, etc., to prevent it from eventually corrode? Or is that impossible to prevent corrosion over time?

    Thanks.

    • Cenk

      One more thing. I really beivele that there are lots of travel insurance websites of reliable companies that let you enter your trip details to get you the rates. You can also purchase your international holiday insurance policy on-line by using your current credit card. All that you should do is usually to enter your travel specifics and you can begin to see the plans side-by-side. You only need to find the system that suits your financial allowance and needs and use your credit card to buy that. Travel insurance on the internet is a good way to search for a respected company pertaining to international travel insurance. Thanks for expressing your ideas.

    • Martin

      Great, thanks for your prompt replies and the links you provided.
      Thanks.

    • T.K.Hareendran

      It seems like a plated pcb. I regret,I have no idea about the coating technique. Hope this link helps you.Thanks!

      http://henrysbench.capnfatz.com/henrys-bench/arduino-rain-sensor-module-guide-and-tutorial/

Looking for the latest from TI?