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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const int sensorMin = 0;
-
- const int sensorMax = 1024;
-
-
- void setup()
- {
-
- Serial.begin(9600);
- }
- void loop()
- {
-
- int sensorReading = analogRead(A0);
-
-
- int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
-
- switch (range)
- {
- case 0:
-
- Serial.println("Flood");
- break;
-
- case 1:
-
- Serial.println("Touched");
- break;
-
- case 2:
-
- " below.
- Serial.println("Not touched");
- break;
- }
- delay(1);
-
- }
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.
Read more articles on Arduino: