Introduction: Water Level Monitoring System

About: Electronics hobbyist

This Instructables shows you how to build a Water level Monitoring and Management System. It is a simple and reliable system. Its key features are:

>Real time water level monitoring.

>Automatic turn on/off.

>Emergency turn on/off switch.

>Detection of Sensor and Connectivity ERROR.

NOTE: This project is working and still in Demo phase. Longtime working is yet to be tested.

Step 1: Supplies:

1. Electronics Components

a. Modules and ICs:

Arduino Pro mini

HC-SR04 ultrasonic sensor

MAX485 module

LCD i2c module

LCD 1602 :

ATTINY45/85 :

LM7805 :

b. Transistors and Diodes:

NPN transistor(2n3904) :

N-channel MOSFET(IRFD024PBF) :

Diode (1N4007) :

c. Connectors and Terminals:

5 pin Connector :

4 pin Connector:

2 pin Connector:

2 pin Screw terminals(Blue) (x2):

2 pin Screw terminals(Green) :

DC jack female(x2):

1/4 inch Audio Jack male and female(x2).

d. Resistors and Capacitors :

1K ohm :

10K ohm(x3) :

100nF(x3) :

100uF :

e. Switches and Relays :

Push button(small) :

DIP switches(SPST 2)(x2) :

Push button(large) :

Toggle Switch :

12VDC Relay :

Relay Contactor( 230VAC coil and capable of driving the pump to be connected).:

f. Power Supplies:

5VDC Power Adapter(>200 mA)

12VDC Power Adapter(>500 mA).

2. Other Supplies:

Project enclosure boxes of fitting size(2).

M3 Bolts (long) and washers(See Images for reference)

Step 2: Sensor/Transmitter


This part measures the water level and sends the data to the main controller. It has two sensors to measure the Water Level. One of them is HC-SR04 ultrasonic distance sensor and the other one is two long screws projecting outwards as show in the images.

Mechanical Construction:

These sensors can be easily mounted on to the top cover of the enclosure box. You can follow these steps to make the assembly simpler.

>First place the ultrasonic sensor in inverted position on the front side of the cover near the top and mark the two holes for the ultrasonic transmitter and receiver (those two small cylinders).

>Then cut the holes for the same carefully and hot glue the sensor in the place firmly.

>Next drill two 3 mm holes with 2-3 cm gap in between at center of the cover.

>Insert the Long M3 bolts with a wire terminal sandwiched between two washers from the backside of the cover and tighten in with M3 nuts on the other side.(See images for reference).

Step 3: Sensor/Transmitter

Brief Working:

Sensor or Transmitter board uses ATTINY45 as the main micro-controller.As mentioned earlier it uses HC-SR04 to measure the water level. It works by measuring the distance from top of the tank. So that the water level will be Low if the distance is nearer to the depth of the tank. The water level be High when the distance is very low. When the water level is full it makes contact with both of the M3 bolts which turns on the transistor and makes the output of the transistor to go LOW. The micro-controller takes reading from both of these sensors and sends the data through UART communication. This data is then received by the Arduino pro mini at the receiver/controller end.

At first I wanted to send the data through HC-12 RF modules. But the range of these module were not good enough for reliable connection. So I went with RS-485 wired communication. I used MAX485 TTL to RS485 converter module and made a little adapter PCB for the same to replace it in place of HC-12 modules.


The main circuit of the sensor module is as shown in the image. Link to the schematic and PCB is at the end so that you can either choose to build it on a dot PCB or get a printed board from a manufacturer.

HC-SR04 to Main Circuit:

Vcc <---------------------> 5v(CN1).

trig <----------------------> trigPin(CN1).



M3 Bolts to Main Circuit:

Bolt 1<--------------------> 5v(CN1).

Bolt 2<-------------------->100(CN1).

MAX485 module(TX) connections:

VCC<--------------------->5V(HC-12 connector on main circuit)

A<------------------------->1/4 inch audio jack.

B<------------------------->1/4 inch audio jack.

GND<--------------------->GND(HC-12 connector on main circuit)

R0<------------------------>RX(HC-12 connector on main circuit)

RE<------------------------>VCC(MAX485) or 5V.

DE<------------------------>RE(short both RE and DE).

DI<------------------------->TX(HC-12 connector on main circuit).

DC jack to Main Circuit(P1 screw terminal connector):



NOTE:The pins(1/4 inch audio jack) to which you connect A and B of the MAX485 module(TX) doesn't matter, as long as it is connected to the A and B of the MAX485 module(RX) at the receiver.

Step 4: Receiver/Controller:

Brief Working:

The working of the controller is straight forward. Arduino Pro mini is used as the main micro-controller. It receives the sensor data sent from transmitter board through max485 module. It has 1602 LCD which displays the current water level and motor status. It uses a 12V relay as a switch turn on the relay contactor. It has two switches one for LCD back-light and one more for emergency turn on/off of the motor.

Wiring and Circuit:

The link to the schematic diagram and PCB designs for both the transmitter and receiver is here.

The PCB can be ordered from a manufacturer or you can build the circuit on a dot PCB.

The LCD i2c module is directly soldered on to the 1602 LCD. The back-light jumper on the i2c module is connected to a toggle switch to turn it on/off when required. The emergency push button(large) is connected to the main circuit through connector P4(refer Schematic).

LCD i2c module to Main circuit(CN4):





MAX485 module(TX) connections:

VCC<--------------------->5V(HC-12 connector on main circuit)

A<------------------------->1/4 inch audio jack.

B<------------------------->1/4 inch audio jack.

GND<--------------------->GND1(HC-12 connector on main circuit)

R0<------------------------>RX(HC-12 connector on main circuit)


DE<------------------------>RE(short both RE and DE).

DI<------------------------->TX(HC-12 connector on main circuit).

DC jack to Main Circuit(P1 screw terminal connector):



Relay Contactor connections:

A1<-------------------------->230 VAC1(neutral).

A2<-------------------------->NO(relay pin).

S1<-------------------------->230 VAC1(neutral).

S2<-------------------------->230 VAC2(line)

L1<--------------------------->Pump motor wire 1

L2<--------------------------->Pump motor wire 2.

NOTE: Be careful while handling with mains line, Don't do these connections if you are not sure what you are doing.

Connect the COM pin of the relay to 230 VAC2(line).

Step 5: Software and Programming:

Transmitter/Sensor Code:

It begins by including "SoftwareSerial.h" library for serial communication and declaring the pins. Next, in the setup function the serial communication and all the input/output pins are initiated.

In Loop function,

>It first checks if the tank is full or not.

>If it is full it sends 255 through serial communication.

>If it is not full it checks the water level through ultrasonic sound sensor and sends the data through serial communication.

This program uses a sub-function getwtrLvl() to get the current water level. It first measures the time taken by the sensor to transmit and receive the ultrasonic sound waves. Then the time is converted into distance using the speed of the sound.

dist = pulseIn(echoPin, HIGH);// gives the time taken by the sound wave.

dist = dist / 28 / 2; // converts the time into into distance in cm

dist = dist *1.25; // here 1.25 is correction factor to overcome the error in measurement

return dist; // returns distance to the calling function

If you are not sure how to program ATTINY 45, Here is a video tutorial on how to program these using Arduino UNO :


It also begins by including few required libraries and declaring the required pins, constants and variables. The setup program initializes the serial communication, input/output pins and LCD.

In Loop function,

>It first checks if the emergency push button is pressed or not, If it is pressed it will invert the button state.

>Sensor Check part of the program checks for the sensor error. i.e, If the data received is not valid(<=1) and is continued 5 times then it displays Sensor error and motor is turned off.

>Next part displays the current water level and sets the motor state to 1 if the water level is less than the low level or else if it is 100% (full) sets the motor state to 0.

This program uses two sub-function updtMotor() and getWaterLvl(). The updtMotor() function updates the motor status on LCD and also gives the signal to the relay.

The getWaterLvl function first checks if there is any connection error. If the connection is not established between the transmitter and the receiver within the timeout(3000 ms) period. It will display sensor error and turns off the motor.

Afterwards, If the connection is good it receives the data received and returns the water level accordingly.

>If the received data is 255. it returns 100.

>If the data received is between 0 and 250, it calculates the percentage of water level using the formula :

res = ((totDist - Status)*100)/totDist; (here totDist is the depth of the tank measured by sensor).

>Else if the received data is anything else it will return -1, indicating invalid data.

You can find all the required files and programs for this project in this GitHub repository:

Step 6: Final Thoughts!

This project was made in intention to minimize the daily day water waste. It has been working as expected so far and has to be tested for long interval of time. If you have any doubts and questions about the project, ask them in the comment section below.

Once again, please be careful while dealing with the mains wiring. If you are not sure what you are dealing with don't do it.

A word about sponsor:

LCSC Electronics is one of the fastest growing suppliers of electronic components in China. They been supporting electronics enthusiasts like me to keep making projects by providing components. So, I suggest you all to take a look at their website for ordering electronic components online. You can visit for more information.

Thank you for going through this article.

Assistive Tech Contest

Participated in the
Assistive Tech Contest