Water Sensor
Water sensor is designed for water detection, which can be widely used in sensing rainfall, water level, and even liquid leakage.
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, the level, the 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 read LOW when water is detected.
In this chapter, we will connect the water sensor to Digital Pin 8 on Arduino, and will enlist the very handy LED to help identify when the water sensor comes into contact with a source of water.
Components Required
You will need the following components −
- 1 × Breadboard
- 1 × Arduino Uno R3
- 1 × Water Sensor
- 1 × led
- 1 × 330 ohm resistor
water sensor connection with arduino -
code for water level sensor -
/* Arduino Tutorial - Watel Level Sensor 40mm
More info: */
const int read = A0; //Sensor AO pin to Arduino pin A0
int value; //Variable to store the incomming data
void setup()
{
//Begin serial communication
Serial.begin(9600);
}
void loop()
{
value = analogRead(read); //Read data from analog pin and store it to value variable
if (value<=480){
Serial.println("Water level: 0mm - Empty!");
}
else if (value>480 && value<=530){
Serial.println("Water level: 0mm to 5mm");
}
else if (value>530 && value<=615){
Serial.println("Water level: 5mm to 10mm");
}
else if (value>615 && value<=660){
Serial.println("Water level: 10mm to 15mm");
}
else if (value>660 && value<=680){
Serial.println("Water level: 15mm to 20mm");
}
else if (value>680 && value<=690){
Serial.println("Water level: 20mm to 25mm");
}
else if (value>690 && value<=700){
Serial.println("Water level: 25mm to 30mm");
}
else if (value>700 && value<=705){
Serial.println("Water level: 30mm to 35mm");
}
else if (value>705){
Serial.println("Water level: 35mm to 40mm");
}
delay(5000); // Check for new value every 5 sec
}