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