# Best way to determine if a 5 gallon water jug is getting empty

I have an espresso machine that gets its water from one of those 5 gallon blue water bottles (I would plumb it, but our water here is WAAAAY too hard).

If I ever accidentally let the bottle run out of water, the rotary pump in the espresso machine will be ruined, which would be a costly mistake.

I know that I can install some sort of magnetic float sensor inside the water bottle, but since I have to change it out once every few weeks, having another thing inside the bottle would make changing it out harder, and microbial contamination more likely. The pump that pumps water out of the bottle forms a tight seal at the lid, and anything running under it or through it would compromise that seal.

Is there something I could use to detect if the water level is low from the outside of the bottle? Like a laser sensor?

• I believe water absorbs infrared light, so you could experiment with an infrared LED / phototransistor. There are special components too and possibly break outs. I believe it is how rain sensors work in a car. Feb 27, 2014 at 17:52
• A pressure sensitive base (i.e. springs and a switch) might be something to consider as well. The accuracy may not be excellent, but as long as you accounted for that in your tolerances it could work. Feb 27, 2014 at 19:12
• You might be able to use the difference in specific heat at a point on the bottle with and without water to the level of that point. A resister dissipating a level of energy detectable to the touch that is in thermal contact with a temperature sensor and all of that in thermal contact with the appropriate point on the bottle. Mar 9, 2014 at 21:57

Using a Force Sensor to Measure a Quantity of Water

To satisfy your requirement of having the sensor on the exterior of the water container, I would recommend using a force sensor to weigh the bottle at set intervals. A force sensor, such as the FlexiForce A401, is a type of resistor that changes resistance in response to the amount of force applied. While not as accurate as a scale, it should provide enough accuracy (+-3% according to the datasheet) for the application described.

The basic procedure would be to hook up the force sensor to the Arduino and first measure the resistance with an empty bottle, then measure again with a full bottle. This will give you an idea of the force that your specific platform is actually applying to the sensor, and you can then fine tune the voltage (as per the datasheet) for your installation.

A basic tutorial using a similar force sensor with an Arduino can be found here.

Other Possibilities

• It's basically using the tare weight of the empty water container (or nearly empty, anyway) to trigger the alarm. I would suggest that the hoses from the espresso machine plus a minimum safe amount of water be in the bottle when getting the baseline sensor measurement. Mar 9, 2014 at 17:41

Another option is to measure the current going into the pump; when it runs dry, the current goes up, which generates the heat that fries the pump.

Or measure the temperature on the pump, but measuring the current will detect the beginning of the pump's meltdown, while the temperature may only detect the middle or end of the meltdown. :-(

Or install a current limiter or breaker inline with the pump, just in case everything else fails. :-)

• Interesting. This would require modifying the espresso maker somewhat to implement, correct? Would a fuse be an acceptable method? Feb 27, 2014 at 23:59

I think you want a "liquid level switch", possibly also known as a "fluid switch" ... I realize this may not satisfy your requirements, but this is one way to solve the problem for >\$10. I would probably hack something together that would put this sensor inline to the bottle. it's probably too hacky, but you could have a disc of plywood the same diameter as the water bottle, with a pipe fitting in the middle where you could mount the switch, so that the water bottle routes water through it so that when it runs low, it would trigger the switch before it runs to the pump.

• Yeah, that needs to be in the water, which is what I don't want. Feb 27, 2014 at 19:54

Whenever light follows a path that takes it from one material to the next, it makes a sharp turn. However, the angle of deviation is different based on the characteristics of the materials.

You can use this principle.

Set a LED on the level that you want to be your lowest. When the water is full, its light will follow a certain path across the container and reach its light sensor. When the water gets bellow the level, it will miss it (or you could set up a second sensor if you really wanted to).

Based on this info, you can know when the water gets too low. Just take appropriate action.

Watch out on the recommendation to measure the water used. This could be dangerous. You may have a leakage (either now or later) or somebody might tip the machine and spill some water. In either case your water level would be lower than the level you calculate, which would certainly result in your espresso machine be ruined.

It seems to me that if you have pumped out 4.9 gallons you know the jug is close to empty. If an inline flow meter between the pump and the espessso maker is out due to water contact, then maybe you know that an espresso shot takes x amount of water, and once one has called for y shots (and calculated x times y) one is in the danger zone of running out of water?

• Would work if all shots were equal, and then only if water was only used to make shots (not steam milk or clean glasses, or make americanos) Feb 27, 2014 at 20:11
• An espresso shot or even an Americano would seem a fixed amount (digital in this context), but yeah, steaming milk and cleaning in particular could vary (analog in this context). jlbnjmn's suggestion of essentially weighing the jug periodically is looking good, unless you can find a jippe suggested sensor that would maybe shine through the bottle near the bottom and then have some sort of reading change when it was no longer shining through water. Feb 27, 2014 at 20:20
• Nah, they are only semi-fixed per bean, and only assuming you don't change your recipe. The amount needed for a shot of espresso is not known beforehand as it can change per bean, per mood, per desired output weight or volume. Nov 18, 2020 at 2:25

Honestly - you're overthinking this.

A dipstick or a float would be all you need. Once the water level drops below your minimum, the float moves down with the water level and pulls a switch or allows a LDR to see through a hole. Then do something like turn on a light.

Less is more.

• Again, I dont want it in the water. Feb 28, 2014 at 1:39

Lasers

If your blue water bottles are like mine, they are transparent.

Here's what I would try first:

I would get a cheap laser, and shine the light horizontally through the bottle. I would aim the laser through a short chord -- not pointed directly through the middle of the bottle; perhaps 1/8 turn to the left of center.

``````    -------
L../.......\..........S1
/         \
|     o     |        S2
\         /
\       /
-------
top-down view
``````

When the bottle is empty, the laser beam will shoot pretty much straight through the bottle -- I would put one photo-sensor S1 there.

When the bottle is not quite empty, the laser beam will bend (refract) -- for redundancy, I would put another photo-sensor S2 there.

As long as the Arduino sees the laser hitting S2 alone, there's still some water in the bottle, at least up to the level of the laser -- turn on the green light.

Anything else -- light detecting only at S1, or nothing detected at either sensor, or light detected at both sensors (yes, it can happen) -- something doesn't seem right, better have the Arduino turn off the green light and turn on the red light.

I would start with the simplest thing that could possibly work. If I'm lucky, it might work. If not, there's lots of little tricks involved in getting the light where you want it to go. There's also lots of tricks for blocking sunlight, etc. from going where you don't want it to go. Little black tubes, red plastic filters, pulsing the laser at a few kHz, collimating lenses, lock-in amplifiers, etc.

There seem to be lots of tutorials that describe how to detect a laser using Arduino -- see

(This would probably work just as well with a medium-power LED or "infrared LED" and some careful optical focusing and alignment. But -- lasers!)

• Im definitely going to try this one, because I feel like it'll be a solution where I can change the bottle out without removing any sensor gear. The laser and the sensor just need to be mounted bear the bottle, not actually on it. Feb 28, 2014 at 14:35

you can use a metal detector like setup using the fact that electronic permittivity of water is different than that of air

have a coil with AC next to the bottle and an unpowered coil inside it

then by measuring the current and/or voltage generated by the second coil you can sense the difference between with water next to it and without

Try a non contact water sensor: https://www.dfrobot.com/product-1493.html I use them and they work very well. You stick it on the outside of the jug, If it falls off the jug will show empty protecting your pump. The ones I use are similar and have an open collector, so no micro is required. I think I paid about \$6 a year or so ago. They make adjustable ones. Nice point nothing touches the water or can contaminate it.