Water level detector using ultrasonic Sensor

Arduino with ultrasonic sensor HC-SR04

Welcome to the Quanta project. in this project, we will measure the water level using the ultrasonic sensor and the Arduino Uno r3. by using this project you measure water level, the fuel level in any container. only you have to put the ultrasonic sensor at the top side of the container. so, it can measure the distance between the ultrasonic sensor and the water inside the container. you can use this project at your overhead tank and in your bike fuel tank. if your overhead tank full then it will notify you or you can just turn off the water pump. you can use this for many applications as per your requirement.

How it’s work?

there is an ultrasonic sensor which works on the ultrasonic waves. it has two main components inside the sensor one is transmitter and another is a receiver. we connect the transmitter to the output pin of the Arduino and the receiver pin is to be connected to the input pin so we can receive the data as the input.

so the wave transmitted by the transmitter comes back after the incident on any object and in this projects the waves incident on the water. and then we calculate the distance by the time duration to comes back the waves.

so this is the basic principle of the project. at this principle, w measure the distance between the ultrasonic sensor and the water inside the container

Components Require to make water level detector:-

  •  Arduino Uno
  • Ultrasonic sensor
  • LCD display
  • Wires
  • Switch

Circuit diagram for water level detector:


Code for Water level detector :

#include <LiquidCrystal.h>#include<SoftwareSerial.h>

SoftwareSerial mybt(2,3);

int s,q,p,z;

const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int duration_front=0;

long distance_front=0;

void setup() {

lcd.begin(16, 2);



pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(A1, INPUT);




void loop()


digitalWrite(4, HIGH);


digitalWrite(4, LOW);


duration_front= pulseIn(5,HIGH);


int s = map(distance_front, 0, 12 , 0,  120);

int p =  map(s, 120, 0 , 0,  1200);




lcd.print(“Water level =”);



int q= analogRead(A1);

if(q >= 800)


digitalWrite(6, HIGH);

digitalWrite(7, HIGH);


lcd.print(“water pump ON”);




digitalWrite(6, LOW);

digitalWrite(7, LOW);


lcd.print(“water pump OFF”);



Upload the given code into the Arduino with the IDE

What do you think?

1 point
Upvote Downvote

Written by shahid

Leave a Reply

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

Single Axis Solar Tracker using Arduino

Pravid 2019 – National Level Science Exhibition