Water Level Controller using 8051
In this article, we demonstrate the construction of a water level controller utilizing the 8051 microcontroller. While this website features several water level controller projects, this particular one stands out as the first to incorporate a microcontroller. The primary function of this water level controller is to continuously monitor the water level in an overhead tank and activate the water pump when the level falls below a predetermined threshold. To provide a visual indication of the tank’s water level, five LEDs are employed, and the pump is automatically deactivated when the tank reaches full capacity. Additionally, the system ensures that the pump remains off if the water level in the sump tank drops below a specified level, even during a pumping cycle.
For those interested in this Water Level Controller project, we offer a Project Kit available for purchase through our Online Store. This kit is an enhanced version of the project mentioned above. In this Water Level Controller project kit, the water level is assessed using four float switches. An LCD module is utilized to display both the water tank’s level status and the motor’s operational status. The device continuously monitors the water level in the tank and activates the motor when the tank is empty, turning it off when the overhead tank or container reaches its maximum capacity.
Purchase Now
Incorporating float switches into the circuit enhances its durability, ensuring extended operation without frequent maintenance. The project kit is offered in two variants: a plug-and-play version and a do-it-yourself version. Additionally, the kit includes a 12-0-12 mains transformer, although it is not illustrated in the diagram below.
The level sensor probes for the overhead tank are linked to the microcontroller’s Port 2 via transistors. Refer to Figure 1 for the configuration of the sensor probes for the overhead tank. Here’s how it works: a positive voltage supply probe is inserted at the bottom of the tank. The probes for detecting 1/4, 1/2, 3/4, and FULL levels are positioned one by one above the bottom positive probe with equal spacing. Let’s consider the topmost probe, representing the full level. It’s connected to the base of transistor Q4 through resistor R16 at the other end. When the water level reaches its maximum, current flows into the base of transistor Q4, turning it on and causing the collector voltage to drop.
Q4’s collector is linked to P2.4, and a low voltage at P2.4 indicates that the overhead tank is empty. As the water level drops below the full level probe, the base of Q2 opens, turning it off. Consequently, the collector voltage rises substantially at P2.4, signifying that the tank is not yet full. The remaining sensor probes (3/4, 1/2, 1/4) function in a similar fashion, and the microcontroller determines the current level by scanning the port pins P2.4, P2.5, P2.6, and P2.7. If all these port pins are high (indicating that all the sensor probes are open), it signifies that the tank is empty.
The pump is under the control of port pin P0.5. When it’s time to commence pumping, the controller sets P0.5 to a low state, activating transistor Q6. This, in turn, triggers the relay K1, switching on the pump. Simultaneously, LED D6 lights up, indicating that the motor is running. LED D7 serves as the low sump indicator. If the water level in the sump tank falls below a particular level, the controller lowers P0.7, causing LED D7 to illuminate. The circuit diagram for the water level controller is depicted in the image below.
Circuit diagram.

Program.
MOV P2,#11111111B // initiates P2 as sensor input
MOV P0,#11111111B // initiates P2 as the output port
MOV A,#00000000B
MAIN:ACALL SMPCK // checks the level of the sump tank
MOV A,P2 // moves the current status of P2 to A
CJNE A,#11110000B,LABEL1 // checks whether tank is full
SETB P0.1
SETB P0.2
SETB P0.3
SETB P0.4
CLR P0.0 // glows full level LED
SETB P0.5
LABEL1:MOV A,P2
CJNE A,#11111000B,LABEL2 // checks whether tank is 3/4
SETB P0.0
SETB P0.2
SETB P0.3
SETB P0.4
CLR P0.1 // glows 3/4 level LED
LABEL2:MOV A,P2
CJNE A,#11111100B,LABEL3 // checks whether tank is 1/2
SETB P0.0
SETB P0.1
SETB P0.3
SETB P0.4
CLR P0.2 // glows 1/2 level LED
LABEL3:MOV A,P2
CJNE A,#11111110B,LABEL4 // checks whether tank is 1/4
SETB P0.0
SETB P0.1
SETB P0.2
SETB P0.4
CLR P0.3 // glows 1/4 level LED
JB P0.6,LABEL4
CLR P0.5 // switches motor ON
LABEL4:MOV A,P2
CJNE A,#11111111B,MAIN // checks whether tank is empty
SETB P0.0
SETB P0.1
SETB P0.2
SETB P0.3
CLR P0.4 // glows EMPTY LED
JB P0.6,MAIN // checks whether sump is low
CLR P0.5 // switches motor ON
SJMP MAIN
SMPCK:JB P0.6,LABEL5 // checks whether sump is low
SETB P0.7 // extinguishes the sump low indicator LED
SJMP LABEL6
LABEL5:SETB P0.5 // switches the pump OFF
CLR P0.7 // glows sump low indicator LED
LABEL6:RET
END