Skip to content

A system designed to control the level of fluid in a tank ๐Ÿ’ง๐Ÿ’งโš—โš—

License

Notifications You must be signed in to change notification settings

makaram99/tank-level-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Tank Level Control

Creative Commons Licence license release last commit

Render

โœ… Perform a review and leave a comment here
โœ… If you want to contribute, add a new record like here
โœ… If this needs to be improved, create an issue here

Table of Contents


๐Ÿ”‘ Introduction

Tank Level Control System is a system designed to monitor and control the level of a fluid in a tank.

If the tank gets empty and filled periodically such as in Residential Buildings as shown in the image below. It will be a boring task to get a human to monitor the tank. Also, human problems such as quick response is always slower than automation system. So, the automation system is the best solution for this problem.

residential_buildings_tank

It has many applications such:

  1. Process tank: An important function.
  2. Hot water tank: Water is removed, perhaps for washing down, and the level needs to be restored ready for the next wash cycle.

๐Ÿงฎ Block Diagram

System Construction

The main components of the system are:

  1. Fluid tank: Used to hold the desired amount of fluid.
  2. Measurement system: Senses the level of the fluid inside the tank.
  3. Controller: Used to maintain the desired level by starting and stopping the pump depending on the information from the measurement system.
  4. Pump: Feeds water from the source to the tank when actuated by the controller.

โž— Calculations of Distance

With the ultrasonic sensor, it sends ultrasonic waves which get beack to the sensor when hitting any surface (e.g., liquid in our case). The distance between the sensor and the surface is calculated by the following formula:

We can calculate the distance between the sensor and the surface as follows:

  1. Calculate the time consumed from the instanse of sending the waves to the instance of recieving it using a timer inside the microcontroller.

  2. As long as the ultrasonic waves are in fact sound waves. So, the speed of ultrasonic waves equals the speed of sound = 343 m/s.

  3. The distance between the sensor and the surface is: Distance = Speed * (Time / 2)

  4. Why the distance is divided by 2? The distance is divided by 2 because the waves go to the surface, then back to the sensor. So, the time calculated is the time it takes to go from the sensor to the surface and back to the sensor, hence the time must be divided by 2.

Sensor Working


๐Ÿ› ๏ธ Development Tools Required


๐Ÿ—ป Project Hierarchy

The project contains some files and directories:

  • electrical: Contains everything about the electrical circuit.

    • pcb: Contains PCB design of all electronics boards used in this project.
    • simulation**: Contains simulation files of all electronics boards used in this project.
    • resources: Contains all resources used while designing circuits.
    • docs: Contains videos of testing circuits, photos of circuits, and the pdf files describing the circuits.
    • store_bills: Contains store bills of components purchased for the project.
    • bill_of_material.xlsx: Contains bill of material of components purchased for the project.
    • version_edits.txt: Contains all bugs of the electronic circuits in the current version. So, they need to be fixed in the next version.
  • mechanical: Contains everything about the mechanical design (Enclosure).

  • software: Contains everything about the code.

    • code: Contains the code of the project.
    • resources: Contains all resources used while designing circuits.
    • problems.txt: Contains documentation of some problems occuredd while testing the system physically.
    • version_edits.txt: Contains all bugs of the code in the current version. So, they need to be fixed in the next version.
  • docs: Contains the documentation generated using doxygen and make, and other documents designed by me.

  • README.md: Contains the introduction of the project (What you are reading now).

  • LICENSE: Contains the license of the project.

  • Doxyfile: Contains the configuration of doxygen (Documentation generator).

  • doxygen.mk: Contains the configuration and rules to be run using make to generate documents.

  • Makefile: Contains the configuration and rules to be run using make to automate buil process of the software (compile, flash, clean, ...) documents.

  • steps_of_project.pdf: Contains the block diagram of steps of the project.


โš™ Working

Code

To develop the project (code), you need to:

  • YOU MUST HAVE (MikroC Pro) or (Visual Studio Code with XC8 PIC Compiler) installed on your computer.
  • Open the code directory.
  • If you have:
    • MikroC Pro: Click twice on tankLevel.mcppi file. It will open with Mikro C Pro.
    • Visual Studio Code with XC8 compiler: Open the project with VS Code.
  • Enjoy the development.
  • To build the project, if you have:
    • MikroC Pro: Click on Build button on quick access bar of MikroC Pro, or press Ctrl + F9 on the keyboard.
    • Visual Studio Code with XC8 compiler:
      • Open the terminal inside VS Code by pressing on Ctrl + ` on the keyboard.
      • Type the command make all. It will compile the project.
      • The hex file will be generated in the code directory with the name app.hex.
      • To flash the hex file to the PIC, type the command make flash.
      • To remove the output files (hex and intermediate files), type the command make clean.

NOTE: I've documented the code as much as I can. So, I hope you will understand the code.

Simulation

To simulate the project, you need to:

  • YOU MUST HAVE Proteus installed on your computer.

  • Proteus has compatibility issues with its version, and the project may not be opened if you have a different version of proteus. So, you need to install Proteus 8.9 to be able to simulate the project.

  • From the simulation directory, open the folder of any of the boards.

  • Click twice on the file ends with .pdsprj.

  • It will open with Proteus as shown here:

    • Control Circuit
    simulation_control_circuit - Power Circuit simulation_power_circuit
  • As shown in the Control Circuit, it is divided into blocks such as Controller, PUMP, and Sensor blocks.

  • To run simulation, click on F12 from the keyboard.

  • Increase/Decrease the distance measured by the ultrasoni sensor by pressing Up/Down arrow on the Sensor block. The distance measured by the sensor will be displayed on the LCD screen as a percentage representing the level percentage of the tank. The percentage depends on a predetermined value equals to the height of the tank (in our case, the tank is 24cm height).

  • When the percentage is lower than 15%, the pump will be turned on.

  • When the percentage is higher than 80%, the pump will be turned off.

  • When the percentage is between 15% and 80%, the pump will be latched to the last state. If the pump was on, it will be remains on. If the pump is off, it will remains off.

  • To stop the simulation: Press twice on ESC key from the keyboard.

NOTE: The keypad is not used in the current version of the project. It is put for future use.


๐Ÿ“‘ Generate Documentation

To generate documentation:

  1. YOU MUST HAVE DOXYGEN AND MAKE INSTALLED ON YOUR COMPUTER.
  2. From the home directory of the project (tank_level_control), open the command prompt in your OS (cmd for Windows, bash for linux, ...)
  3. Run the following command: make -f doxygen.mk all
  4. The documentation will be generated in the docs directory.

๐Ÿญ Manufacturing

**Here is a comparison between CAD design on Solidworks versus the final physical shape: **

  1. Product:

Enclosure

2. Control Circuit:

Control

3. Power Circuit:

Power

4. Keypad:

Keypad


๐ŸŽฏ Results

After running the project either on the simulation (Proteus) or running the physical hardware. The result was as expected. So, you also can use the project and it will work as expected.

You can check the working of the project by opening the test_project.m4v file.

If you want to check operation of each circuit, open:


๐Ÿ”ฌ What is next?

I will always try to improve this project. Next Version: Features of the next version can be found in the file version_edits.txt in software directory.


๐Ÿ’โ€โ™‚๏ธ Contribute

If you want to contribute to the project, add a new record like here

๐Ÿ“ž Contact me

LinkedIn Gmail

๐Ÿ“– References

๐Ÿ”“ Licenses


All DOCUMENTS inside this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

All SOURCE codes & BINARIES are licensed under Mit License.

Creative Commons Licence

license

๐Ÿ” Credits

All credits and external sources are listed inside the page and inside this repo, references themselves.

About

A system designed to control the level of fluid in a tank ๐Ÿ’ง๐Ÿ’งโš—โš—

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages