Exercise 13 - Connecting a water level sensor
1. INTRODUCTION
Level sensor detects the level of liquids and other fluids, which has vertical
probes that change the resistor in function of liquid level variation.
You can test this sensor helping yourself with a water glass.
2. HOW TO CONNECT?
Materials:
· Arduino UNO board
· Some wire Jumpers
· Water level sensor
These sensor connections are very simple 5v, GND go to 5V and GND pins on Arduino board and OUT go A0.
EXERCISE_A |
![]()
|
3. PROGRAMMING
EXERCISE_A
//This program obtains level sensor value through analog pin read
const int read = A0; //Sensor AOUT pin to Arduino pin A0
int value;
void setup()
{
//Begin serial communication
Serial.begin(9600);
}
void loop()
{
value = analogRead(read); //Read data from sensor and write it in
if (value<=480){
Serial.println("level: 0mm");
}
else if (value>480 && value<=530){
Serial.println("level: 0mm to 5mm");
}
else if (value>530 && value<=615){
Serial.println("level: 5mm to 10mm");
}
else if (value>615 && value<=660){
Serial.println("level: 10mm to 15mm");
}
else if (value>660 && value<=680){
Serial.println("level: 15mm to 20mm");
}
else if (value>680 && value<=690){
Serial.println("level: 20mm to 25mm");
}
else if (value>690 && value<=700){
Serial.println("level: 25mm to 30mm");
}
else if (value>700 && value<=705){
Serial.println("level: 30mm to 35mm");
}
else if (value>705){
Serial.println("level: 35mm to 40mm");
}
delay(2000);
}