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 : https://lcsc.com/product-detail/LCD-Displays-Modul...

ATTINY45/85 : https://lcsc.com/product-detail/_MICROCHIP_ATTINY4...

LM7805 : https://lcsc.com/product-detail/Linear-Voltage-Reg...


b. Transistors and Diodes:

NPN transistor(2n3904) : https://lcsc.com/product-detail/Transistors-NPN-PN...

N-channel MOSFET(IRFD024PBF) : https://lcsc.com/product-detail/MOSFET_Vishay-Inte...

Diode (1N4007) : https://lcsc.com/product-detail/Diodes-General-Pur...


c. Connectors and Terminals:

5 pin Connector : https://lcsc.com/product-detail/Wire-To-Board-Wire...

4 pin Connector: https://lcsc.com/product-detail/Wire-To-Board-Wire...

2 pin Connector: https://lcsc.com/product-detail/Wire-To-Board-Wire...

2 pin Screw terminals(Blue) (x2): https://lcsc.com/product-detail/Pluggable-System-T...

2 pin Screw terminals(Green) : https://lcsc.com/product-detail/Pluggable-System-T...

DC jack female(x2): https://lcsc.com/product-detail/Power-Connectors_X...

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


d. Resistors and Capacitors :

1K ohm : https://lcsc.com/product-detail/Chip-Resistor-Surf...

10K ohm(x3) : https://lcsc.com/product-detail/Chip-Resistor-Surf...

100nF(x3) : https://lcsc.com/product-detail/Multilayer-Ceramic...

100uF : https://lcsc.com/product-detail/Aluminum-Electroly...


e. Switches and Relays :

Push button(small) : https://lcsc.com/product-detail/Others_TE-Connecti...

DIP switches(SPST 2)(x2) : https://lcsc.com/product-detail/DIP-Switches_Made-...

Push button(large) : https://lcsc.com/product-detail/Electrical-Switche...

Toggle Switch : https://lcsc.com/product-detail/Toggle-Switches_YU...

12VDC Relay : https://lcsc.com/product-detail/Relays_SLC-12VDC-S...

Relay Contactor( 230VAC coil and capable of driving the pump to be connected).: https://www.tsktech.in/product/dp-contactor-16a/


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

Function:

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.

Wiring:

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).

echo<--------------------->echoPin(CN1).

Gnd<---------------------->GND(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):

Tip<----------------------->5V

Sleeve<------------------>GND

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):

GND<-------------------->CN4-1(GND1).

VCC<-------------------->CN4-2(5V).

SCL<--------------------->CN4-3(A5).

SDA<--------------------->CN4-4(A4).


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)

RE<------------------------>GND1.

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

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


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

Tip<----------------------->VCC.(12VDC)

Sleeve<------------------>GND1.


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 :

Receiver/Controller:

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: https://github.com/ManojBR105/Water-Level-Monitori...

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 https://lcsc.com/ for more information.

Thank you for going through this article.

Assistive Tech Contest

Participated in the
Assistive Tech Contest