โ 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
- ๐งฎ Block Diagram
- โ Calculations of Distance
- ๐ ๏ธ Development Tools Required
- ๐ป Project Hierarchy
- โ Working
- ๐ Generate Documentation
- ๐ญ Manufacturing
- ๐ฏ Results
- ๐ฌ What is next?
- ๐โโ๏ธ Contribute
- ๐ Contact me
- ๐ References
- ๐ Licenses
- ๐ Credits
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.
It has many applications such:
- Process tank: An important function.
- Hot water tank: Water is removed, perhaps for washing down, and the level needs to be restored ready for the next wash cycle.
The main components of the system are:
- Fluid tank: Used to hold the desired amount of fluid.
- Measurement system: Senses the level of the fluid inside the tank.
- Controller: Used to maintain the desired level by starting and stopping the pump depending on the information from the measurement system.
- Pump: Feeds water from the source to the tank when actuated by the controller.
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:
-
Calculate the time consumed from the instanse of sending the waves to the instance of recieving it using a timer inside the microcontroller.
-
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.
-
The distance between the sensor and the surface is:
Distance = Speed * (Time / 2)
-
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.
-
MikroC Pro is used for code development and compiling the system.
Website: www.mikroe.com
-
Text Editor: Visual Studio Code
VS Code is used for code development. It is free.
Download: https://code.visualstudio.com/
-
Hardware Simulator: Proteus 8.9
Proteus is used to simulate the hardware. So, no need to purchase any hardware.
Download: https://www.proteus.co.jp/
-
Mechanical Design Software: SolidWorks
Website: https://www.solidworks.com/
-
PCB Design Software: Altium Designer
Website: https://www.altium.com/
-
Doxygen is used to generate documentations of the code in html, latex, pdf, and other formats.
Download: https://www.doxygen.nl/download.html
-
Command Line Automation Tool: make
Make is used to automate kernel commands. I've used it to automate the generation of documents from doxygen.
Download:
- Linux or MacOS: https://www.gnu.org/software/make/
- Windows: http://gnuwin32.sourceforge.net/packages/make.htm
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).
- box: Contains the mechanical design of the enclosure using Solidworks.
- attachments: Contains the external parts downloaded from the internet to incoroporate in the final assembly enclosure using Solidworks in the file assembly.SLDASM.
- arrows_keypad, control_circuit, and power_circuit: Step files of the electronics circuits here, to incoroporate in the final assembly enclosure using Solidworks in the file assembly.SLDASM.
- assembly.SLDASM: Contains the final assembly of the projects containing enclosure, electronic circuits, and attachments.
- assembly_drawing.SLDDRW: Contains the drawing file generated by Solidworks for the assembly.
- final_assembly.PDF: Contains dimension, and different views of the assembly. It is generated from the file final_assembly.PDF.
-
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.
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.
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
-
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.
To generate documentation:
- YOU MUST HAVE DOXYGEN AND MAKE INSTALLED ON YOUR COMPUTER.
- From the home directory of the project (tank_level_control), open the command prompt in your OS (cmd for Windows, bash for linux, ...)
- Run the following command:
make -f doxygen.mk all
- The documentation will be generated in the docs directory.
**Here is a comparison between CAD design on Solidworks versus the final physical shape: **
- Product:
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:
- test_power_circuit.m4v to see the working of power circuit.
- test_kit.m4v to see the working of control circuit.
- test_short_circuit.m4v to see the working of short circuit protection.
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.
If you want to contribute to the project, add a new record like here
- Resources used can be found in resources directories inside software, mechanical, and electrical directories.
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.
All credits and external sources are listed inside the page and inside this repo, references themselves.