Main Content

UltraSonic Liquid Level Controller

A Simple ultrasonic liquid level controller based on STM32 microcontroller

Introduction
As you probably know, Iran has dry weather, and there is a lack of water in my country. Sometimes, especially in the summer, it can be seen that the government cuts the water. So most of the apartments have a water tank. There is a 1500 litre tank in our apartment which provides water. Also, there are 12 residential units in our apartment. As a result, it can be expected that the tank goes empty very soon. There is a water pump attached to the tank which sends water into the building. Whenever the tank is empty, the pump works without water. This situation causes an increment in motor temperature, and during the time, it can cause pump breakdown. Some time ago, this pump failure happened for the second time for us, and after opening the motor, we saw that coil wires were burnt. After we replaced the pump, to prevent this problem again, I decided to make a water level controller. I planed to make a circuit to cut the pump’s power supply whenever the water came below the low limit in the tank. The pump won’t work until the water rises to a high limit. After passing the high limit, the circuit will connect the power supply again.

In the beginning, I searched over the internet to see if I can find a suitable circuit. However, I did not find anything appropriate. There were some Arduino based water indicators, but there could not solve my problem. As a result, I decided to design my water level controller. An all-in-one package with a straightforward graphical user interface to set parameters. Also, I tried to consider EMC standards to be sure that the device works valid in different situations.

You probably know the principle before. When the ultrasonic pulse signal is emitted towards an object, it is reflected by the object and echo returns to the sender. If you calculate The time travelled by the ultrasonic pulse, you can find the distance of the object. In our case, the item is the water.

Note that when you find the distance to the water, you are calculating the volume of empty space in the tank. To get the volume of water, you have to subtract calculated volume from total tank volume.

Hardware
For the sensor, I used JSN-SR04T waterproof ultrasonic sensor. The working routine is like HC-SR04 (echo and trig pin).

Specs:

Distance: 25cm to 450 cm
Working voltage: DC 3.0-5.5V
Working current: <8mA
Accuracy: ±1cm
Frequency: 40khz
Working temperature: -20 ~ 70 ℃
Note that this controller has some limitations. for example :

1- JSN-SR04T cannot measure distance below 25CM, so you have to install the sensor at least 25CM above the surface of the water. Moreover, the maximum distance measurement is 4.5M. So this sensor is not suitable for huge tanks.

2- the accuracy is 1CM for this sensor. As a result, based on the diameter of the tank, the resolution of volume that the device will show can be varied.

3- the speed of sound can be vary based on temperature. As a result, accuracy can be affected by different regions.

However, these limitations were not crucial to me, and the accuracy was suitable.”

Link to article