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.  - If the Sensor Board is completely soaked;    
  9.  "case 0" will be activated and " Flood " will be sent to the serial monitor.    
  10.   - If the Sensor Board has water droplets on it;     
  11. "case 1" will be activated and " Touched " will be sent to the serial monitor.    
  12.   - If the Sensor Board is dry;     
  13. "case 2" will be activated and " Not Touched " will be sent to the serial monitor.     
  14.    
  15. */  
  16.   
  17. // lowest and highest sensor readings:        
  18. const int sensorMin = 0;  
  19. // sensor minimum        
  20. const int sensorMax = 1024;  
  21. // sensor maximum       
  22.   
  23. void setup()   
  24. {  
  25.     // initialize serial communication @ 9600 baud:        
  26.     Serial.begin(9600);  
  27. }  
  28. void loop()   
  29. {  
  30.     // read the sensor on analog A0:       
  31.     int sensorReading = analogRead(A0);  
  32.     // map the sensor range (four options):        
  33.     // ex: 'long int map(long int, long int, long int, long int, long int)'        
  34.     int range = map(sensorReading, sensorMin, sensorMax, 0, 3);  
  35.     // range value:        
  36.     switch (range)   
  37.     {  
  38.     case 0:  
  39.         // Sensor getting wet        
  40.         Serial.println("Flood");  
  41.         break;  
  42.   
  43.     case 1:  
  44.         // Sensor getting wet        
  45.         Serial.println("Touched");  
  46.         break;  
  47.   
  48.     case 2:  
  49.         // Sensor dry - To shut this up delete the " Serial.println("Not Raining");         
  50.         " below.        
  51.         Serial.println("Not touched");  
  52.         break;  
  53.     }  
  54.     delay(1);  
  55.     // delay between reads        

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
 
 
Figure2:Output
 
Read more articles on Arduino: