Water Level Indicator

54K14431

Intro: Water Level Indicator

The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328 (Arduino Nano 3.x). It has more or less the same functionality of the Arduino Duemilanove, but in a different package.

This is a project which is based on the Arduino Nano and it's interfacing with other sensors. In this Instructable, I'll show you how to make a Water Level Indicator that measures the level of water in the tank and Displays it on an LCD screen.

So in this project I'll be using the HC-SR04 Ultrasonic Module to measure the Water Level and an I2C LCD to see the water level in cm.

STEP 1: Tools and Components

For this project you'll need:

  • Arduino Nano
  • HC-SR04 Ultrasonic Module
  • LCD Display
  • LCD i2c
  • Bread Board
  • Hook-Up Wires
  • A container to hold water

STEP 2: Getting Started With HC-SR04

HC-SR04 or an ultra sonic sensor is a electronic device that works on the principle of transmission and reflection.This sensor has two pins named as TRIG and ECHO pin.

The function of ECHO pin is to emit the waves to the channel.These waves travel through the medium as a wave and reflects back when ever it hits an object or an obstacle ahead of its propagation.The time taken taken for the emission and reflection is calculated and using this value we decide the distance of the obstacle approaching us.

The ultrasonic sensor are connected to the nano as follows :

  • The TRIG pin is connected to the digital pin 9 of nano.
  • The ECHO pin is connected to the digital pin 10 of nano.
  • The VCC pin is connected to the positive railing of the breadboard.
  • The GND pin is connected to the negative of the breadboard.

STEP 3: Connection of LCD:

The 16x2 LCD of Arduino is first soldered to I2C. I'm using an I2C driver this just to eliminate the messy and large number of jumper wire making a way to connect more sensors and output devices.The I2c got 4 pin to get the function of LCD done,where as the traditional LCD is having 12 pins.The brief description of the I2C pins are

Data line(SDA):This line or the transmission line of the I2C is used to transmit data from transmitter to the receiver.The character needed to be displayed on the LCD are transmitted through this line.

Clock line(SCL): This is a control line of the I2C which decides the rate at which the characters are transmitted just like the clock pulse in traditional flip flops.

I2C are connected as follows:

  • SDA pin is connected to the analog pin A5.
  • SCL pin is connected to the analog pin A4.
  • VCC pin is connected to the positive railing of the breadboard.
  • GND pin is connected to the negative railing of the breadboard.

we are done with the hardware, let's now get started with the Coding.

STEP 4: Coding

The code is quite simple and is quite similar to that as shown in the step 3 of this project, in addition we are now adding some more libraries to get the I2C LCD working. You can download the libraries form here. Make sure you have entered the right I2C address in the code, the default address of the I2C is 0x3f.


Copy and paste the below code into the arduino IDE and select the arduino nano and the right port and then hit upload.

#include "Wire.h" // For I2C
#include "LCD.h" // For LCD #include "LiquidCrystal_I2C.h" // Added library* //Set the pins on the I2C chip used for LCD connections //ADDR,EN,R/W,RS,D4,D5,D6,D7 LiquidCrystal_I2C lcd(0x3f,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article

#define echoPin 3 // Echo Pin (OUTPUT pin in RB URF02) #define trigPin 2 // Trigger Pin (INPUT pin in RB URF02)

int led = 5; int maximumRange = 350; // Maximum range needed int minimumRange = 0; // Minimum range needed long duration, distance; // Duration used to calculate distance int brightness;

void setup() { lcd.begin (16,2); // 16 x 2 LCD module lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL lcd.setBacklight(HIGH); Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); }

void loop() { // The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration/58.2; //Calculate the distance (in cm) based on the speed of sound. lcd.home (); // Set cursor to 0,0 lcd.print("The Water Level is"); lcd.setCursor (0,1); lcd.print(distance); // Custom text lcd.print("cm"); Serial.println(distance); // distance in cm brightness= map(distance,1,100,0,255); analogWrite(led, brightness); delay(1000); //Delay 50 ms }

STEP 5: Output :

And after you have completed the project you should see the arduino display the water level on the LCD. You can an additional buzzer to let you know then the the water level reaches after certain threshold.

15 Comments

How to install the I2C library?
The Arduino IDE displays an error, "LiquidCrystal_I2C.h: No such file or directory".

1/ Download the I2C library here:
https://github.com/cyberang3l/NewLiquidCrystal

2/ Some mistakes:
Echo Pin on D3
Trigger Pin on D2,
SDA on A4
SCL on A5

3/ This code is working for me:

#include "Wire.h" // For I2C
#include "LCD.h" // For LCD
#include "LiquidCrystal_I2C.h" // Added library*
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,16,2); // 0x27 is the default I2C bus address of the backpack-see article

#define echoPin 3 // Echo Pin (OUTPUT pin in RB URF02)
#define trigPin 2 // Trigger Pin (INPUT pin in RB URF02)

int led = 5;
int maximumRange = 350; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
int brightness;

void setup() {
lcd.begin (16,2); // 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH);
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
}

void loop() {
// The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it.
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2; //Calculate the distance (in cm) based on the speed of sound.
lcd.home (); // Set cursor to 0,0
lcd.print("The Water Level is");
lcd.setCursor (0,1);
lcd.print(distance); // Custom text
lcd.print("cm");
Serial.println(distance); // distance in cm
brightness= map(distance,1,100,0,255);
analogWrite(led, brightness);
delay(1000); //Delay 50 ms
}

Have a good day ;-)
i need my shower water tank level meter, i have 4 pcs, capasitive touchless level sensor to input if one have ON water level have this point. but i not know can me orden E-ink display to arduino how use ? or better use old i2c 1602 lcd display only. indicate level to bar. not percent or numbers not readaple, tank picture and inside level bar have best, how made at display.
Hi Everyone, I've changed the LCD by oled display (128X64), and this is the code, if the display don't turn on, remember that you need the OLED I2C library.

#include "Wire.h" // para oLED
#include "Adafruit_GFX.h" // para OLED
#include "Adafruit_SSD1306.h" // Libreria agregada*
#define ANCHO 128
#define ALTO 64
#define OLED_RESET 4
Adafruit_SSD1306 oled(ANCHO, ALTO, &Wire, OLED_RESET) ;
#define echoPin 3 // Echo Pin (OUTPUT pin in RB URF02)
#define trigPin 2 // Trigger Pin (INPUT pin in RB URF02)
int led = 5;
int maximumRange = 350; // Rango maximo requerido
int minimumRange = 0; // Rango minimo requerido
long duration, distance; // Duración utilizada para calcular la distancia
int brightness;
void setup() {
Wire.begin (); // OLED module
oled.begin(SSD1306_SWITCHCAPVCC, 0x3c);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
}
void loop() {
// The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it.
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2; //Calcula la distancia (en cm) basado en la velocidad del sonido.
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setCursor(0, 0); // poner el cursor 0,0
oled.setTextSize(1);
oled.print("El nivel del agua es:");
oled.setCursor (10, 30);
oled.setTextSize(2);
oled.print(distance); //texto personalizado
oled.print("cm");
Serial.println(distance); // distancia en cm
brightness= map(distance,1,100,0,255);
analogWrite(led, brightness);
oled.display();
delay(1000); //retardo 50 ms
}

Regards
hi,great work
I want to use this in method in building a sensor for a PID control system,as you know the noise on sensor is very destructive in feedback path So i have to minimize it.Could you please show me a way to do it?my controller is Arduino Mega
Hi. Great article. I am trying to find an ultrasonic sensor that I can attach externally to the bottom of my RV tank so I can measure the water in the tank. It has to have the ability to go through 1/4-3/8” ABS plastic. I don’t want to cut a hole in the tank for a sensor. Will this one send the pulse through plastic?

The code contains an error on the LCD pin definitions.

This is the correct LCD pin definition.

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

same problem, how to resolve it ?

kia ap ny baqi project assamble kr lia hy
hi .kia ye project complet kaha sy mila ga ,plz contact me 03076541877
Where are the files? I have tried to compile this but the compiler keep crashing with a variety of errors.
I have tried a variety of things to no avail. Please direct me to the necessary library and program files.

Thanks

Very nice, this can be implemented mostly anywhere where level monitoring is essential. However do not forget that temperature/vapor and or airborne particles can skew the echo delay.

Nice, thanks for sharing.
Will this work on dust collection bin to detect the wood shavings level?, adding a buzzer or strobe light is a must in my application.
Thanks