top of page

Water Depth
Indicator

A water level indicator using a water level sensor while displaying real-time information on a 16x2 LCD is an easy and effective way to gather information on how full or empty a small sized contained water source is. The LCD screen is connected to the Arduino Uno via multiple pins, and the water level sensor measures the water level based on conductivity. This project is ideal for understanding how water levels are monitored in tanks or reservoirs for domestic, agricultural, or industrial applications.

​

How It Works:

The water level sensor operates on the principle of conductivity, detecting the presence of water at various levels. As water comes into contact with the sensor's probes, it completes an electrical circuit, allowing current to flow. The sensor outputs an analog signal proportional to the water level, which the Arduino reads via its analog input pin. The Arduino then processes this signal and displays the corresponding water level on the 16x2 LCD screen in real-time.

Materials Anchor

Materials

To measure the level of water with an Arduino Uno, you'll need the following materials:

Components:

​

1) Arduino Uno

  • A microcontroller board based on the ATmega328P. The Arduino Uno serves as the central processing unit, interpreting signals from the water level sensor and controlling the LCD display.

​

2) Water Level Sensor

  • A sensor that measures water level based on conductivity.

  • Features:

    • + (VCC): Supplies power to the sensor.

    • - (GND): Connects to ground.

    • S (Signal): Outputs an analog signal proportional to the water level.

​

3) 16x2 LCD Screen

  • Displays the analog results of the water level indicator.

  • Can have button module or standard 16x2 stand-alone display​

  • If using the stand-alone 16x2 LCD, a 220Ω resistor will be needed for pin 15 to Power (+) of the Arduino

​

4) Jumper Wires

  • Flexible wires used for connecting components to the Arduino. Male-to-male wires are commonly used for breadboards and sensors.

​

5) Breadboard (Optional)

  • A prototyping board for connecting components without soldering, providing an easy way to organize and test circuits.

​

6) USB Cable (Type A to B)

  • Connects the Arduino Uno to the computer for power and programming.​

​

Setup Anchor

Basic Setup

breadboard_GREY.png
schematic_GREY.png

1) Water Level Sensor to Arduino Uno:

  • Connect the + (VCC) pin of the sensor to the Arduino’s 5V pin.

  • Connect the - (GND) pin of the sensor to the Arduino’s GND pin.

  • Connect the S (Signal) pin of the sensor to the Arduino’s A0 pin (analog input).

​

IF USING THE 16x2 SHIELD, WIRE IT AS FOLLOWS:
2) Connect the LCD to the Arduino:

  • The LCD Shield has a 5V pin and a GND pin (Located Right of the buttons) these must be connected to the Arduinos 5V and GND pin respectively.

​​
The LCD has 16 pins. Wire them as follows:

  • Pin 1 (VSS): (GND '-') Leave unconnected, this is pre-routed via the Shields' board.

  • Pin 2 (VDD): (5V '+') Leave unconnected, this is pre-routed via the Shields' board.

  • Pin 3 (V0): (GND '+') Leave unconnected, this is pre-routed via the Shields' board.

  • Pin 4 (RS): Connect to Arduino digital Pin 12.

  • Pin 5 (RW): (GND '+') Leave unconnected, this is pre-routed via the Shields' board.

  • Pin 6 (E): Connect to Arduino digital Pin 11.

  • Pins 7-10 (D0-D3): Leave unconnected (for 4-bit mode).

  • Pins 11-14 (D4-D7): Connect to Arduino digital Pins 5, 4, 3, and 2 respectively.

  • Pin 15 (Backlight +): (5V '+') Leave unconnected, this is pre-routed via the Shields' board.

  • Pin 16 (Backlight -): (GND '-') Connect to common Arduino GND.

​​

IF USING THE 16x2 STAND-ALONE LCD DISPLAY:

2) The LCD has 16 pins. Wire them as follows:

  • Pin 1 (VSS): (GND '-') Connect to Arduino's common ground pin.

  • Pin 2 (VDD): (5V '+') Connect to the 5V line of the Arduino.

  • Pin 3 (V0): (GND '+') Connect to the 5V line of the Arduino.

  • Pin 4 (RS): Connect to Arduino digital Pin 12.

  • Pin 5 (RW): (GND '-') This pin dictates if the LCD will read/write. Connect to Arduino's common ground pin for write mode.

  • Pin 6 (E): Connect to Arduino digital Pin 11.

  • Pins 7-10 (D0-D3): Leave unconnected (for 4-bit mode).

  • Pins 11-14 (D4-D7): Connect to Arduino digital Pins 5, 4, 3, and 2 respectively.

  • Pin 15 (Backlight +): (5V '+') Connect to the 5V line of the Arduino through a 220Ω resistor.

  • Pin 16 (Backlight -): (GND '-') Connect to Arduino's common ground pin.

​

Code
Code Part 2.png
code part 1.png

CODE BREAK-DOWN

Code Break Down

#include <LiquidCrystal.h>
Includes the LiquidCrystal library, which provides functions to control a 16x2 LCD.

​

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

  • Creates an lcd object and initializes it with the pin connections:

    • RS: Pin 12

    • E: Pin 11

    • D4: Pin 5

    • D5: Pin 4

    • D6: Pin 3

    • D7: Pin 2

​

const int waterSensorPin = A0;

  • Defines the waterSensorPin constant and assigns it to analog pin A0, where the water level sensor's signal is connected.

​

const int sensorMin = 0;

  • Defines the sensorMin constant as 0, representing the analog reading of the sensor when it is dry.

​

const int sensorMax = 1023;

  • Defines the sensorMax constant as 1023, representing the analog reading of the sensor when it is fully submerged.

​

void setup() {

  • Begins the setup function, which is executed once when the Arduino starts.

​

Serial.begin(9600);

  • Initializes serial communication at a baud rate of 9600 for debugging and monitoring sensor values.

​

lcd.begin(16, 2);

  • Initializes the lcd object with a 16-column by 2-row configuration.

​

lcd.print("Water Level:");

  • Displays the text "Water Level:" on the first row of the LCD.

​

void loop() {

  • Begins the loop function, which repeatedly executes the code inside it.

​

int sensorValue = analogRead(waterSensorPin);

  • Reads the analog signal from the water level sensor connected to A0 and stores it in the variable sensorValue.

​

int waterLevel = map(sensorValue, sensorMin, sensorMax, 0, 100);

  • Maps the sensorValue from the range sensorMin–sensorMax to a percentage range 0–100% and stores the result in the variable waterLevel.

​

waterLevel = constrain(waterLevel, 0, 100);

  • Ensures the waterLevel value is constrained within 0% to 100%, discarding any out-of-range values.

​

lcd.setCursor(0, 1);

  • Sets the cursor to the first column (0) and the second row (1) on the LCD.

​

lcd.print("Level: ");

  • Displays the text "Level: " on the second row of the LCD.

​

lcd.print(waterLevel);

  • Displays the current waterLevel percentage on the second row, next to the text "Level: ".

​

lcd.print("% ");

  • Displays the percentage symbol "% " after the water level value and adds spaces to clear any old values from the display.

​

Serial.print("Sensor Value: ");

  • Prints the text "Sensor Value: " to the Serial Monitor for debugging.

​

Serial.print(sensorValue);

  • Prints the raw analog reading from the sensor (stored in sensorValue) to the Serial Monitor.

​

Serial.print(" -> Water Level: ");

  • Prints the text " -> Water Level: " to the Serial Monitor, followed by the mapped water level percentage.

​

Serial.print(waterLevel);

  • Prints the water level percentage (stored in waterLevel) to the Serial Monitor.

​

Serial.println("%");

  • Prints the percentage symbol "%" and moves to the next line in the Serial Monitor for the next set of readings.

​

delay(1000);

  • Pauses the execution for 1000 milliseconds (1 second) before the next reading, allowing for a stable update rate.

bottom of page