Introduction: Water Level Indicator

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: I'm a tech and food enthusiast and also a Soccer Player. I love…

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.

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017