Finding Weather Conditions Using Rain Sensor With Arduino Mega 2560

Introduction

In this article I will explain about finding weather conditions using Rain Sensor with Arduino Mega 2560. It can be very easy to find the weather conditions at any place.

Parts Of List
  • Arduino Mega 2560
  • Rain sensor
  • Bread Board
Rain Sensor


            Figure 1: Rain Sensor
  • The Raindrop Detection Sensor module is an easy-to-use and low cost drop recognition sensor.

  • The sensor works through a series of exposures.

  • Parallel traces on board produce electrical variations when drops or water volume changes.

  • By using microcontrollers or ADC ICs (Arduino and PIC) its fairly easy to convert the analog output from the sensor to digital values.

  • This can be directly read by an Arduino or a comparator circuit if you wish to use it as a rain detection alarm. It can be used to monitor a variety of weather conditions.
Connection
  • VCC: positive power supply (3-5V)
  • GND: power supply is negative
  • DO: TTL switching signal output
  • AO: analog signal output.
Programming
  1. /* Flame Sensor analog example.   
  2. Code by Reichenstein7 (thejamerson.com)   
  3.    
  4. For use with a Rain Sensor with an analog out!   
  5.    
  6. To test view the output, point a serial monitor such as Putty at your Arduino.    
  7.    
  8.     
  9.  - If the Sensor Board is completely soaked;   
  10.  "case 0" will be activated and " Flood " will be sent to the serial monitor.   
  11.   - If the Sensor Board has water droplets on it;    
  12. "case 1" will be activated and " Touched " will be sent to the serial monitor.   
  13.   - If the Sensor Board is dry;    
  14. "case 2" will be activated and " Not Touched " will be sent to the serial monitor.    
  15.    
  16.    
  17. */    
  18.     
  19. // lowest and highest sensor readings:      
  20.     
  21. const int sensorMin = 0;    
  22.     
  23. // sensor minimum      
  24.     
  25. const int sensorMax = 1024;    
  26.     
  27. // sensor maximum      
  28.     
  29. void setup()    
  30. {    
  31.     // initialize serial communication @ 9600 baud:      
  32.     Serial.begin(9600);    
  33. }    
  34. void loop()    
  35. {    
  36.     // read the sensor on analog A0:     
  37.      
  38.     int sensorReading = analogRead(A0);    
  39.     
  40.     // map the sensor range (four options):      
  41.     // ex: 'long int map(long int, long int, long int, long int, long int)'      
  42.     
  43.     int range = map(sensorReading, sensorMin, sensorMax, 0, 3);    
  44.     
  45.     // range value:      
  46.     switch (range)    
  47.     {    
  48.         case 0:    
  49.     
  50.             // Sensor getting wet      
  51.             Serial.println("Flood");    
  52.             break;    
  53.     
  54.         case 1:    
  55.     
  56.             // Sensor getting wet      
  57.             Serial.println("Touched");    
  58.             break;    
  59.     
  60.         case 2:    
  61.     
  62.             // Sensor dry - To shut this up delete the " Serial.println("Not Raining");       
  63.             " below.      
  64.             Serial.println("Not touched");    
  65.             break;    
  66.     }    
  67.     
  68.     delay(1);    
  69.     // delay between reads      
  70. }  
Explanation
  • If the Sensor Board is completely soaked; "case 0" will be activated and "Flood" will be sent to the serial monitor.

  • If the Sensor Board has water droplets on it; "case 1" will be activated and "Touched" will be sent to the serial monitor.

  • If the Sensor Board is dry; "case 2" will be activated and "Not touched" will be sent to the serial monitor.

  • The output in "case 2", "Not Raining" is just for this demonstration.

  • When I used this code in production I omitted the output for this case and just had the alert.
Output


                                       Figure 2:Output
 
Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all