No. 18 – Drop sensor

Task: We want to detect a drop of water and display the read out value on the serial monitor.

Required equipment: Arduino / drop sensor / cables / (piezo and breadboard for the extension of the sketch)

The drop sensor, or liquid sensor, is able to detect liquid on its surface. A little drop would already be enough to get a clear measurement.

Dro1

One example of the usage can be a rain detector. If the drop sensor measures a rain drop,
the Arduino board could e.g. close the blinds, set off an alarm or turn on windshield wipers.

The way of functioning again is quite simple. On the long contacts that are running trough the surface of the drop sensor a voltage is applied (+ or -). As soon as a liquid e.g. in form of a drop touches the surface of the sensor, a small current flows from one contact to another. The sensor converts this value into an analog signal and transfers it to the microcontroller. The microcontroller, as mentioned in other tutorials, isn’t able to read out a voltage and has to convert the analog signal into a numerical value. 0V to 12V corresponds to a numerical value from 0 to 1023 (That are 1024 numbers, since the zero is counted as the first numerical value).

If the drop sensor is completely dry the value would be “0”. Whenever a drop of water touches the contacts of the sensor the value would be at about “480”. The more drops
are touching the surface of the sensor, the higher the value would get.

Setup:

See image below (The two cables on the top (black and red) and the piezo speaker on the breadboard will be needed later on).

The programming of the moisture sensor isn’t that complicated and is very similar to the programming of the potentiometer or the moisture sensor, because there is just an analog value read out.

Code:


int measurement=0; //Variable for the measurement with 0 as starting value

void setup()

{ //The setup begins here

Serial.begin(9600); //Starting the serial communication to show the sensor values on the serial monitor //later on

}

void loop()

{ //The loop part starts here

measurement=analogRead(A0); //The voltage on the drop sensor gets read out and gets saved under //“measurement”

Serial.print(Moisture measurement:“); //Show the words “Moisture measurement:” on serial monitor and …

Serial.println(measurement); //…show the read out moisture sensor value

delay(500); //Short break to avoid to many confusing values on serial monitor

}


Extension of the code:

Now we want a piezo speaker to beep as soon as a rain drop touches the sensor. As limit we are going to use the sensor value 400, because if a drop touches the sensor we are expecting a value at about 480.

Setup:

DRO2

Code:


int measurement=0;

int beep=6; //”beep” stands for the pin 6, which gets connected with the piezo

void setup()

{

Serial.begin(9600);

pinMode (6,OUTPUT); //The pin 6 gets defined as an output

}

void loop()

{

measurement=analogRead(A0);

Serial.print(Moisture measurement:“);

Serial.println(measurement);

delay(500);

if (measurement >400) //Starting IF command: If the sensor value gets higher than400”…

{

digitalWrite(beep, HIGH); //…the piezo should beep…

}

else //..if not…

{

digitalWrite(beep, LOW); //…the piezo should be quiet

}

}