Introduction to Embedded Systems
Tank Level Monitoring using AVR Report
BSc. Electrical Engineering
Session (2020-2024)
Submitted By
Name M. Ehsan Ullah
Roll No ELEN51F22R011
Semester 4th
Course Title Introduction to Embedded Systems
Date 29-05-2024
Submitted To
Engr. Atif Mursaleen
Department of Electrical Engineering
College of Engineering & Technology
University of Sargodha
1
Tank Level Monitoring System Report
1. Objective
To design a tank level monitoring system that displays the tank level on an LCD display and
controls a pump to maintain the water level within specified limits. The pump will turn ON if the
water level is below a low threshold and turn OFF if the water level exceeds a high threshold.
2. Theory
Level Sensors
For monitoring the water level in a 1-meter-high tank, we can consider different types of level
sensors, such as:
Ultrasonic Sensors: Use sound waves to measure the distance to the water surface.
Float Switches: Mechanical devices that float on the water surface and activate a switch
at predetermined levels.
Capacitive Sensors: Detect changes in capacitance caused by the presence of water.
Pressure Transducers: Measure the pressure at the bottom of the tank to infer the water
level.
For this application, an Ultrasonic Sensor (e.g., HC-SR04) is suitable due to its accuracy, non-
contact nature, and ease of interfacing with microcontrollers.
Control System
An AVR microcontroller (e.g., Arduino Uno) will be used to process the sensor data, control the
pump, and display the tank level on an LCD. The control system will operate based on the
following logic:
Pump ON: If the water level is below the low threshold.
Pump OFF: If the water level exceeds the high threshold.
Display and Input System
2
A 16x2 LCD display will be used to show the water level. For user input to set the low and high
threshold levels, a simple interface with push buttons can be implemented.
Equations
The primary equation for the ultrasonic sensor is:
Time × Sp ⅇⅇd of sound
Distance=
2
Where:
Time is the duration between sending and receiving the ultrasonic pulse.
Speed of Sound is approximately 343 meters per second at room temperature.
Components Used
L298 Motor Driver: The L298 motor driver offers bidirectional control for DC motors
and can handle high current loads, making it suitable for applications requiring precise
motor control, such as robotics and automation projects.
Figure 1: L298 motor driver
HC-SR04 Arduino Ultrasonic Sensor: The HC-SR04 ultrasonic sensor accurately
measures distance by emitting ultrasonic pulses and calculating the time it takes for the
pulses to return, enabling precise distance sensing in various applications like obstacle
avoidance and distance measurement.
3
Figure 2: The HC-SR04 ultrasonic sensor
Relay Module (1 Channel): The relay module serves as an electromechanical switch,
controlled by an electrical signal from the Arduino, enabling or disabling the operation of
devices like pumps by opening or closing a set of contacts.
Figure 3: Relay Module (1 Channel)
Arduino Uno: The Arduino Uno is a versatile microcontroller board equipped with
digital and analog input/output pins and onboard processing capabilities, facilitating the
development of a wide range of electronic projects due to its user-friendly interface and
extensive community support.
Figure 4: The Arduino Uno
4
LCD 16x2: The 16x2 LCD display provides a simple interface for displaying textual
information, offering two lines with 16 characters each, enhancing user interaction by
providing real-time feedback on system status and sensor readings in electronic projects.
3. Apparatus
L298 Motor driver
Hcsr 04 Arduino ultrasonic sensor
Relay module 1channel
Arduino uno
Lcd 16x2
4. Procedure
I. Selecting a Suitable Level Sensor
Ultrasonic Sensor (HC-SR04):
Range: 2 cm to 400 cm.
Accuracy: ±3 mm.
Operating Voltage: 5V.
II. Designing the Control System with AVR Microcontroller
1. Components:
Arduino Uno Microcontroller
HC-SR04 Ultrasonic Sensor
16x2 LCD Display
Relay Module for Pump Control
Push Buttons for User Input
Power Supply
2. Circuit Diagram:
HC-SR04 Ultrasonic Sensor:
5
Trig pin (Trigger) connected to digital pin 7 of Arduino Uno.
Echo pin (Echo) connected to digital pin 6 of Arduino Uno.
LCD Display (16x2):
Data pins (D4-D7) connected to digital pins 2-5 of Arduino Uno.
RS (Register Select) pin connected to digital pin 12 of Arduino Uno.
E (Enable) pin connected to digital pin 11 of Arduino Uno.
Relay Module:
Signal pin connected to digital pin 13 of Arduino Uno to control the pump.
Push Buttons:
Connected to digital pin A1 of Arduino Uno for setting thresholds.
3. Programming:
Initialize the sensor, LCD, and input/output pins:
Ultrasonic Sensor: Trig pin (output) connected to Arduino pin 7, Echo pin (input)
connected to Arduino pin 6.
LCD: Data pins (D4-D7) connected to Arduino pins 5-2, RS pin connected to
Arduino pin 12, E pin connected to Arduino pin 11.
Push Buttons: Connected to Arduino digital pin A1 for setting thresholds.
Continuously read the water level using the ultrasonic sensor:
Trig pin of the ultrasonic sensor sends a trigger signal (connected to Arduino pin
7).
Echo pin receives the echo signal, which is measured by the Arduino (connected
to Arduino pin 6).
Display the current water level on the LCD:
Arduino communicates with the LCD using digital pins 2-12.
Check the water level against the low and high thresholds:
Threshold values are stored and compared within the Arduino code.
6
Turn the pump on or off based on the water level:
Pump control is managed by a relay module connected to Arduino digital pin 13.
Provide a user interface for setting thresholds using push buttons:
Push buttons are connected to Arduino digital pin A1, providing user input to set
threshold values.
III. Selecting Suitable Display and Input System
LCD Display (16x2):
Resolution: 16 characters x 2 lines.
Interface: 4-bit or 8-bit parallel.
Push Buttons:
Type: Momentary push buttons for setting low and high thresholds.
5. Conclusion
The tank level monitoring system designed using an HC-SR04 ultrasonic sensor, AVR
microcontroller, relay module, LCD display, and push-button interface effectively achieves the
objective of monitoring and controlling the water level in the tank. By continuously measuring
the water level and comparing it with predefined thresholds, the system ensures the pump is
activated when the water level is below the low threshold and deactivated when the water level
exceeds the high threshold. The selection of suitable components and the implementation of
appropriate control logic result in an efficient and reliable tank level monitoring system.