How do i measure the level of a water tank with a microcontroller?
Well, assuming you are operating here on earth (as opposed to in orbit), you can use a float sensor that you measure using the micro. The question is: Do you need to know the exact level, or do you just need some sort of trip when it gets to high/low?
On the 'trip at specific level' theme, you can get switches like this - generally the float contains some kind of attitude sensing switch. When the water level is lower, the float ends up on it's side, and the switch is 'off', while raising the level forces the float upright, and therefore 'on'. These are often used for sump pumps. They are pretty reliable and very easy to deal with, though you have to be careful to anchor them correctly, and you have to be sure that nothing gets in the way of the float.
If you need to know the actual level, then you've got lots of choices, but it's less simple. You can go with something like an ultrasonic sensor (ultrasound beam firing down from the top of the tank to reflect off the water level).
These guys seem to make level indicators for BIG tanks which consist of a float and an external weight cabled together. As the float rides up and down on the fluid, the external indicator moves appropriately. You could build something similar, with nothing more complicated than photo-cells to read the level (if it's a large tank, or you want lots of granularity, you'd need a lot of photo-cells).
Alternately, taking the cabled float idea, you could put an idler wheel that moves whenever the cable moves, and then attach an encoder to that. This would allow you to track the level with pretty high accuracy.
I know that the soon to be released book Practical Arduino has a water tank depth sensor project included, which uses a differential pressure transducer to measure the water pressure at the bottom of the tank, and from that to calculate how full the tank is.
Schematics are on the above link, along with a link to the source code on github.
(Full disclosure: I have no association with the book, but have met one of the authors a couple of times at our local hackerspaces.)
A method I like, but have not tried is to put two insulated plates in the liquid. No condution, electrolosis, contanimation....... They form the plates of a cap. and are used in some sort of oscillator ( choice up to you ) Because water is a good dialetric the frquency depends strongly on the amount of water between the plates. Meaure the frequency to get the depth.
You might be able to get a similar result by applying an ac signal and measureing the current thru the cap.
More details would help, but I think the ultrasonic method is probably the simplest, conceptually, anyway (hence the need for more details :-]). I threw together a level sensor for the fuel oil tank in my basement using a MaxSonar ultrasonic transducer. I'm switching to a Parallax Ping sensor, as soon as I can get my hands on one. The MaxSonar unit has proved to be somewhat of a pain; turns out it's only got a resolution of one inch (2.54cm), which equates to nearly 7 gallons in my tank. I put the MaxSonar unit in a PVC cap at the top of the tank pointing down (out of reach of the liquid).
One way of doing this is to place an led at the bottom of the tank pointing to the top, and a photodiode at the top of the tank, facing the LED. The LED will be attenuated by the water in the tank, you'll need to experiment to determine how much. Also, it's best to take a series of rapid measurements and average them when using this method.
There are a surprising number of ways to check for level. There are sensors that use RF, sending a pulse down a waveguide and detecting the reflection off the surface of the liquid in the tank. There's ultrasound, floats, bubbler tubes, pressure taps... The method used depends on the size of the tank, the contents, ambient environment and other factors.
I'm surprised at all the complicated electronic solutions here, I would use a simple potentiometer. Most micro controllers have a basic analog i/p.
+V ----- | | / \ /<----------> to analog i/p \ | | ----- GND
Use a standard water tank valve float (there may already be one). The remaining problem is coupling the float to the pot to get maximum swing (you could also use a slider pot).
|-| | | |o| <--------Slider pot. ||| ||| | | <--------Coupling. | ____ | (float)----------o-----o <--Anchor point of float. ----
Place a small tube in a corner of the tank that is slightly larger in diameter than a ping pong ball.
Place an infrared LED on one side of the tube and a photoresistor opposite of the LED (by drilling a hole in the tube of it's opaque or placing on the outside if its transparent). Hot glue the electrical parts to waterproof them and drop the ping pong ball into the tube.
When the water level raises or lowers to the point that the ping pong ball breaks the infrared beam you'll know it hit the desired level. This works if you just need a discrete (on/off) level indicator.
This system is also used in paintball guns designed to prevent you from chopping balls by assuring that the whole ball is in the firing chamber before allowing the electronic trigger to arm the firing solenoid.
It's simple, effective, and requires little or no calibration.
My two cents: http://www.circuitstoday.com/simple-water-level-idicator
Another solution (no pun intended);
Use a potentiometer as suggested above. The normal rotation range is 270 degrees. Attach a float to the potentiometer using a boom arm. (length=1 unit)
Between full and empty the boom arm will move 90 degrees.
The ADC on a PIC is either 256 or 1024 steps (yes, zero is a step).
I'll use 256 steps for clarity.
270 degrees = 256 ADC steps. 270/90 = 3 (one third of potentiometer range)
255/3 = 85 ADC steps
Program some code to mark the 0 degree point (tank empty) when a button is pushed.
This stores an offset point in the PIC eeprom. Now the potentiometer does not have to be exactly at zero because this calibration point can be set.
Using trigometry calculate a lookup table (hint: php script) to correspond to each step of the ADC.
Hint: each ADC step corresponds to 90/85 = 1.0588 degrees.
Yes, you should have paid more attention in maths class. dumb waste of time back then, indespensible now. engage brain. learn trigonometry. teach others.
Acronym : The Old Arab Carried A Heavy Sack Of Hay.
The hypontenuse is the length of the boom arm. Make it 1 unit long. Lookup table then provides percentage of tank depth. (multiply by 100 of course)
Please check the following link:
I think it may be useful to you.