LCD 20×4 Water LEVEL MONITOR HC SR04

Water LEVEL MONITOR HC SR04
Hello world! Today i made a Water Level Monitor with arduino and the HC-SR04. It is a pretty basic example on what you can do with the HC-SR04 Ultrasonic Sensor and shows you the centimeters that are left to fill the Water Tank. You can simply change the code and put if statements for certain values to trigger actions when the Water Tank is running out of water, like filling it and stop filling it automatically with a solenoid valve for example by using a relay.

Schematic:
Water LEVEL MONITOR HC SR04
Just wire it up like the schematic! Make sure that you have included these following 3 libraries.

LCD.h
LiquidCrystal_I2C.h
NewPing.h

Parts list:
Arduino uno
HC-SR04 Ultrasonic range Sensor
LCD2004 With I2C
Jumper wire set
Water tank or buckets to test (optional)

Code:

#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
 
#define I2C_ADDR 0x27 // <<- Add your address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
 
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
 
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
 
void setup()
{
 lcd.begin (20,4); // <<-- our LCD is a 20x4, change for your LCD if needed
 
// LCD Backlight ON
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 
 lcd.home (); // go home on LCD
 lcd.setCursor (1,0);
 lcd.print("Water Tank Monitor"); 
}
 
void loop()
{
 unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
 unsigned int cm = sonar.convert_cm(uS); // Convert into centimeters
 
 lcd.setCursor (0,1); 
 lcd.print("Current Water Level:");
 lcd.setCursor (0,2);
 lcd.print("====================");
 lcd.setCursor (3,3); 
 lcd.print("Depth: ");
 lcd.print(cm);
 lcd.print(" cm ");
 
 delay(500);
}
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *