Categories

Arduino with the rain drop sensor

Arduino in combination with rain sensor YL-83

This short tutorial shows how to handle the rain sensor using the Arduino.

 

In this example we used the following elements:

 

Connection

The module works directly with the Arduino, so no need for an external source of energy. Pins connected according to the table:

 

Pin ArduinoPin Sensor
5 VVCC
GNDGND
pin A0A0
pin 2D0

 

The remaining two pins from the sensor module connected to the measurement probe using the supplied cable as shown in the following figure:

 

Wiring diagram of the rain sensor.

 

Service

The output D0 is in digital form. By default, in high condition, and upon detection of the precipitation goes into a low state. The sensitivity can be regulated with the built-in potentiometer. And the output of A0 generates an analog signal and reduces the voltage value along with the increase in precipitation (inversely proportional to the intensity of the rain). In the example we will use a simple program that on a regular basis will show on the serial monitor the values read from A0 and D0.

 

int sensor_A0 = A0; // A0 for connection from the sensor to A0 on Arduino 
sensor_D0 int = 2; // connect D0 on the sensor to pin 2 of Arduino 
wartosc_A0 int; // variable for the value of A0 
wartosc_D0 int; // variable for the value of A0 

void setup() { 
 Serial.begin(9600); // start the monitor serial port 
 pinMode(2, INPUT); // set pin 2 as input 

} 

void loop() { 

 wartosc_A0 = analogRead(sensor_A0); // load the values for A0 
 wartosc_D0 = digitalRead(sensor_D0); // load values D0 

 Serial.print("D0: "); // display on serial monitor 
 Serial.print(wartosc_D0); 
 Serial.print(" -- A0: "); 
 Serial.println(wartosc_A0); 
 delay(200); // delay between consecutive readings 
 } 

 

The results of the program you can see in the following screenshot:

 

 

A screenshot of the serial monitor.