Connecting a water sensor to an Arduino is a great way to detect a leak, spill, flood, rain etc. It can be used to detect the presence, level, volume and/or the absence of water. While this could be used to remind you to water your plants, there is a better Grove sensor for that. The sensor has an array of exposed traces which will read LOW when water is detected. In this tutorial, we will connect the Water Sensor to Digital Pin 8 on the Arduino, and will enlist the very handy Grove Piezo buzzer and an LED to help identify when the Water sensor comes into contact with a source of water.
Parts Required:
- Arduino UNO or compatible board
- Grove Base Shield
- Grove Water Sensor
- Grove Piezo Buzzer
- Grove Universal 4 pin 20cm cables (x 2)
- RED LED
- Battery Holder
- Water
Putting it together
If you have a Grove Base Shield, you just have to connect the Grove Water Sensor to D8 on the shield, and the Buzzer to D12 on the Shield. My Grove base shield obstructs the onboard LED, so I will attach an LED to Digital pin 13. If you do not have a Grove base shield, then you should connect the Sensors as described in the tables below:
Arduino Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/*
Grove Water Sensor sketch
Written by ScottC 5th August 2014
Arduino IDE version 1.0.5
Website: http://arduinobasics.blogspot.com
Description: Use Grove Water Sensor to detect leaks, floods, spills, rain etc.
Credits: This sketch was inspired by this website:
http://www.seeedstudio.com/wiki/Grove_-_Water_Sensor
------------------------------------------------------------- */
#define Grove_Water_Sensor 8 //Attach Water sensor to Arduino Digital Pin 8
#define Grove_Piezo_Buzzer 12 //Attach Piezo Buzzer to Arduino Digital Pin 12
#define LED 13 //Attach an LED to Digital Pin 13 (or use onboard LED)
void setup(){
pinMode(Grove_Water_Sensor, INPUT); //The Water Sensor is an Input
pinMode(Grove_Piezo_Buzzer, OUTPUT); //The Piezo Buzzer is an Output
pinMode(LED, OUTPUT); //The LED is an Output
}
void loop(){
/* The water sensor will switch LOW when water is detected.
Get the Arduino to illuminate the LED and activate the buzzer
when water is detected, and switch both off when no water is present */
if(digitalRead(Grove_Water_Sensor) == LOW){
digitalWrite(LED,HIGH);
digitalWrite(Grove_Piezo_Buzzer, HIGH);
delay(2);
digitalWrite(Grove_Piezo_Buzzer, LOW);
delay(40);
}else{
digitalWrite(Grove_Piezo_Buzzer, LOW);
digitalWrite(LED,LOW);
}
}
|
The Video
If you liked this tutorial - please show your support :



Good ..before nothing congratulate you on the web, I have learned many things in it. I would like to make an inquiry could utilzar the same skech but add a Grove Relay and this will activate when the water sensor is put into HIGH and when the sensor is put on LOW the relay is disconnected.
ReplyDeleteThat code would have to add, if someone could help me I would appreciate very much. I am new to this arduino and programming. I've tried many ways and nothing.
Thank you
I have a Grove Relay tutorial that may help you:
Deletehttp://arduinobasics.blogspot.com.au/2014/09/relay-module.html
does this thing actually work?
ReplyDeleteYes it does. Have a look at the video.
Deletenice project! it worked with no problems
ReplyDeleteGreat to hear Syed ! Thanks for your feedback.
DeleteI possible to use this sensor to detect water content in the soil? I want to build simple watering device based on soil moisture. Here is an example of the device: http://daisy.si/
ReplyDeleteNo - this will not tell you the water content in the soil. The water bridges the contacts on the sensor and it will detect it. So any amount of water large or small, that bridges the gap, will trigger this sensor. I think there are other sensors that will do what you are looking to do. For example: this one.
DeleteCan I use grove water sensor without the grove base shield?
ReplyDeleteYes - of course. The Base shield just simplifies the connection. But you could just use female-to-male jumper wires.
DeleteThank you so mmuch for the wonderful tutorial with visual and programming details, thanks a alot.. appreciate your efforts!
ReplyDeleteI have been hunting for an arduino compatible sensor which would trigger a signal ONLY IF there are consistent bubbles in water reservoir, else the water sensor will not trigger any signal. Is there any Grove Sensor available which would satisfy my purpose?
I don't think so.
DeleteYou may have to develop one.
Hi Scott, Thank you for this tutorial. Quick question: Can this sensor detect presence of mineral oil on water(like in oil spillage on sea) or is there a different sensor that can do that in a simpler way? Thank you!
ReplyDeleteHi P0773R,
DeleteNo this sensor is not suitable for your purpose. This only detects when the circuit is closed or not. It cannot differentiate between water and any other substance that may conduct electricity.