Introduction
In my previous article I explained about soil moisture sensor to sense irrigation and in this article I'll show you working with Rain Sensor to sense rain drops and some other applications. The Rain Module Sensor Sense the following conditions based up on the temperature, irrigation, rain drops etc.
There are two main applications for Rain Sensor
- Water Conservation device connected to an automatic irrigation system.
- Protect the interior of an auto-mobile from rain.
Requirements
- Arduino Uno
- Rain Sensor Module
- Bread Board
- Led
Connection
Figure: Rain Sensor
- Analog pin to Arduino A0
- Gnd to Gnd
- Vcc to 5v
Led Connection:
- Anode pin to the Arduino digital pin13
- Cathode pin to the Gnd
Coding:
- int RainSensor=0;
- int Alert=7;
- int led=13;
- int count=0;
- void setup()
- {
-
- Serial.begin(9600);
- pinMode(Alert,OUTPUT);
- pinMode(RainSensor,INPUT);
- pinMode(led,OUTPUT);
- }
- void loop()
- {
- int Sense=analogRead(RainSensor);
- Serial.println(Sense);
- delay(100);
-
- if(count >=44){
- digitalWrite(led,HIGH);
- digitalWrite(Alert,HIGH);
- }
- while(Sense < 400){
- count++;
- }
- do{
- digitalWrite(led,LOW);
- digitalWrite(Alert,LOW);
- count=0;
- }while(Sense > 400);
- delay(1000);
- }
Explanation
Declare the variables
- Rainsensor
- Alert
- led
- Count as integer datatype and Initialize the value to the variables i,e analog pin and digital pin.
Functions
Void setup()
- Set the PinMode as OUTPUT and INPUT
- Set the BaudRate (9600)
Void loop()
The loop function is the one type of the condition function based up on our condition the Rain Sensor will work.
It reads the Analog Pin value i,e Rain sensor value and then print the sense the value that have been sensed by the rain sensor and make the condition to the count value if ( count >=44) the led will ON and the alert will be HIGH while (sense <400) and increment the count value using ++ operator then do the led will goes LOW and alert also LOW while (sense>400) and set the delay time (1000).
Applications
- Condensation Sensing
- Irrigation Control
- Drop Detection
Read more articles on Arduino: