photo arduino water level indicator

Arduino Water Level Indicator + Controller

Here is a tested Arduino project that uses 3 sensor probes as water level indicator with 3 leds and one LCD display + a simple controller that turns on a motor when the water has reached the desired level (the highest in our case). You can use only the leds if you want, the lcd is optional.

Check out the schematic, prototype and video below

The Arduino sketch code is pretty simple even though I spent almost 1 hour to test it. You can download it using the link below and then extract the files.

Related Products: Flow Sensor Photoelectric Sensor

Water Level Sensor Code

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte sensorPin[] = {8, 9, 10};
byte ledPin[] = {11, 12, 13}; // number of leds = numbers of sensors
const byte sensors = 3;
int level = 0; 
int motor = A4;

void setup() {
  for(int i = 0; i < sensors; i++) {
     pinMode(sensorPin[i], INPUT); 
     pinMode(ledPin[i], OUTPUT);
  pinMode(motor, OUTPUT);
  lcd.begin(16, 2);   

void loop() {
  level = 0; 
  for(int i = 0; i < sensors; i++) {
     if(digitalRead(sensorPin[i]) == LOW) {
        digitalWrite(ledPin[i], HIGH);
        level = sensors - i;
     } else {
       digitalWrite(ledPin[i], LOW);       
  lcd.print("Water level");
  switch(level) {
     case 1:
      digitalWrite(motor, HIGH);
     case 2:
       digitalWrite(motor, LOW);
     case 3:
       digitalWrite(motor, LOW);
      lcd.print("NO WATER"); 
      digitalWrite(motor, LOW);   

On line 2 we have included the LiquidCrystal.h header and then on line 3 the pins where to connect the LCD display. On line 4 we use sensorPin array to set the sensor pins, on line 5 ledPin is where we connect the 3 leds. We connected the motor on pin A4 so we use this in our motor variable.

Inside the setup() function we set the sensor pins as INPUT and led pins and motor as OUTPUT. In the loop() we check to see if the water level has reached any sensor and if so then turn an the corresponding led. We also use the LCD to display HIGH if the water has reached the highest poing, AVERAGE for half-filled water tank, LOW when there is little water and NO WATER when the container is empty or the water has not reached the LOW point yet.

We also used a motor (or you can use an electric water valve) that is turning ON when the water level is HIGH. This can be useful when you want to empty the tank once it is full or to stop the water flow to the water tank.


Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?