Introduction
Monitoring the water level in tanks or reservoirs is essential to prevent overflow and manage water usage efficiently. An ultrasonic water level indicator provides a non-contact method for measuring the water level using ultrasonic waves. This project demonstrates how to design an ultrasonic water level indicator using the 8051 microcontroller and an ultrasonic sensor.
Components Required
8051 Microcontroller (e.g., AT89S52)
Ultrasonic Sensor (e.g., HC-SR04)
16x2 LCD Display (for displaying water level)
Resistors (10kΩ, 1kΩ)
Capacitors (33pF, 100μF)
Crystal Oscillator (11.0592 MHz)
Breadboard and Connecting Wires
Power Supply (5V for the 8051 and sensor)
Circuit Diagram
The ultrasonic sensor is used to measure the distance to the water surface. The 8051 microcontroller processes this data and displays the water level on the LCD.
+5V ----- +5V
|
|
HC-SR04
+---+
VCC |VCC|
GND |GND|
TRIG |TRIG|------- P3.2 (8051)
ECHO |ECHO|------- P3.3 (8051)
+---+
LCD Display
VSS to Ground
VCC to +5V
VEE to Potentiometer (for contrast control)
RS to P2.0 (8051)
RW to Ground
E to P2.1 (8051)
D4 to P2.2 (8051)
D5 to P2.3 (8051)
D6 to P2.4 (8051)
D7 to P2.5 (8051)
Pin Connections
Ultrasonic Sensor (HC-SR04):
VCC to +5V
GND to Ground
TRIG to P3.2 of the 8051
ECHO to P3.3 of the 8051
LCD Display:
VSS to Ground
VCC to +5V
VEE to the potentiometer for contrast control
RS to P2.0 of the 8051
RW to Ground
E to P2.1 of the 8051
D4 to P2.2 of the 8051
D5 to P2.3 of the 8051
D6 to P2.4 of the 8051
D7 to P2.5 of the 8051
Software Implementation
The code is written in C using Keil uVision IDE. It involves triggering the ultrasonic sensor, measuring the echo time, calculating the distance, and displaying the water level on the LCD.
#include <reg51.h>
#include <lcd.h> // Include a custom LCD library
sbit TRIG = P3^2; // Trigger pin
sbit ECHO = P3^3; // Echo pin
void delay(unsigned int time) {
unsigned int i, j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++);
}
void sendTriggerPulse() {
TRIG = 1;
delay(1); // 10us delay
TRIG = 0;
}
unsigned int getEchoTime() {
unsigned int time = 0;
while (!ECHO); // Wait for echo start
while (ECHO) { // Measure echo pulse duration
time++;
delay(1);
}
return time;
}
void main() {
unsigned int echoTime;
unsigned int distance;
char distanceStr[16];
lcd_init(); // Initialize the LCD
TRIG = 0; // Set Trigger pin low initially
while (1) {
sendTriggerPulse(); // Send trigger pulse
echoTime = getEchoTime(); // Measure echo time
distance = echoTime / 58; // Calculate distance in cm
sprintf(distanceStr, "Distance: %d cm", distance);
lcd_clear();
lcd_print(distanceStr); // Display distance on LCD
delay(1000); // Delay for stability
}
}
Explanation
Initialization:
LCD Initialization: The lcd_init() function configures the LCD for display.
Trigger Pin Initialization: The TRIG pin is set low initially.
Sending Trigger Pulse:
The sendTriggerPulse() function sends a 10μs pulse to the TRIG pin of the ultrasonic sensor to initiate measurement.
Measuring Echo Time:
The getEchoTime() function measures the duration of the echo pulse received from the ECHO pin. This duration corresponds to the time taken by the ultrasonic wave to travel to the water surface and back.
Calculating Distance:
The distance is calculated using the formula distance = echoTime / 58, which converts the time duration to distance in centimeters.
Displaying Distance:
The distance is converted to a string and displayed on the LCD using the lcd_print() function.
Delay Function:
The delay function introduces a small delay between each measurement for stability.
Conclusion
This project demonstrates the use of the 8051 microcontroller to create an ultrasonic water level indicator. By integrating an ultrasonic sensor and an LCD, the system can measure and display the water level accurately. This project is a great way to learn about sensor interfacing, distance measurement, and using microcontrollers for real-time monitoring applications.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comments