Page 1 of 1

MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 07:28
by ThomasB
I thought I would share a bit about my Milk Level Sensor that is based on ESPEasy. It's built and running, but unfortunately the ending is not a happy one. At least not yet.

BTW, I've briefly mentioned this project in this thread: viewtopic.php?p=70133

The goal was simple: Show the remaining level of refrigerated milk that is locked inside a cabinet that is stored below a coffee machine. The milk is in a one gallon container that frequently needs to be changed. It is used to make hot milk foam on a fully automated EverSys coffee machine. Here is what the machine looks like:

CoffeeMachine2.png
CoffeeMachine2.png (476.7 KiB) Viewed 29525 times

There were some self-imposed rules.
(1) Must be "fool proof." Fools in this case are mostly college educated retirees.
(2) No changes permitted to the equipment, cabinets, and countertops.
(3) Nothing can have direct contact with the milk or other food items.
(4) Materials must be suitable for food contact applications and tolerate alcohol based sanitizing chemicals.
(5) Must be easy to install and/or remove. Simple hand tools allowed.

The finished system is shown below.

System1b.jpg
System1b.jpg (162.35 KiB) Viewed 29525 times

The ESPEasy Hardware is shown below:

ESPEasy1.png
ESPEasy1.png (127.79 KiB) Viewed 29525 times

Some notable things:
▪ A VL53L1X non-contact distance sensor (optical laser) determines liquid level. It measures distance from top of jug downward to milk surface. Math does the rest.
▪ This optical laser is in a plastic assembly that rests on top of the milk container. It touches the container, NOT the milk.
▪ The color display mounts on a cup holder rack next to the machine. It reports 0-100% milk level and its temperature.
▪ A large RGB NEOPixel LED shows status at a glance. Green=Good Milk Level, Yellow=Low Level, Red=Milk Empty
▪ Emails are sent to report status that needs immediate attention.

In the end I was able to check off all the boxes in my "rule" list except #1. The system is not fool proof. Which is a deal killer.

The issue is that the long milk suction tubing (which goes into the top of the milk container) often gets in the view of the optical sensor and disrupts the measurements. And unfortunately it causes the display to report good milk levels, even if the jug is empty.

I could solve the issue by replacing this flexible silicone hose with a stiffer suction tube so it could be directed away from view. But that would violate rule #2; No changes to equipment are permitted.

The suction tube goes though the plastic assembly that holds the sensors. It's made of three pieces, shown below. The big "tongue" seen on the top piece is used to push the milk suction tubing away from the VL53L1X distance sensor. But the tubing has a mind of its own and managing its direction is like controlling a room full of angry cats.

milk_jug_mtg3b.png
milk_jug_mtg3b.png (227.84 KiB) Viewed 29525 times

TL;DR The project is assembled, hardware working, ESPEasy rules written and debugged. Too bad I have to find a solution to make it work for the intended application.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 07:43
by ThomasB
P.S. Thanks to TD-er and Ath for providing solutions to some issues I ran into. I appreciate it!

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 08:25
by Ath
Thomas,

You have a very well executed and documented project, chapeau!

Unfortunately the tube is working against you for now; as a possible solution you could separate the tube/milk input and the level sensor, and move the sensor into a more fixed position at the back of the container, where it doesn't get obtruded by the tube? It will require to add another (small) opening to the container, so that might be a no-go, or even unfeasible if the complete container is replaced with a fresh one when empty :?
Second suggestion is to direct the sensor angle diagonal to the back-bottom of the container, so the chances of the tube getting in the way are smaller. You'll have to slightly adjust the volume calculation, but that's in capable hands, AFAICS ;)

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 08:49
by TD-er
I have not yet looked closely at this exact version of the sensor you use, but maybe we could also do a read-out of several sections of the field-of-view and then not take the closest object, or perform some filtering.
Maybe you could find something in the datasheet to see if there is some indication the sensor is capable of doing so?

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 08:57
by Ath
The VL53L1X has settings to narrow its ROI (Region Of Interest), that's planned to be implemented, though I didn't start with that project yet...

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 18:30
by ThomasB
I also thought about changing the ROI / Field of View. Probably won't fully solve my dilemma, but could help.

Like TD-er mentioned, what would have been cool is if this sensor had electronic beam steering. But as far as I know that's not supported.

BTW, I spent twenty years in medical ultrasound, so beam steering is something I understand. :)


EDIT:
... unfeasible if the complete container is replaced with a fresh one when empty
That is correct, the entire milk container is changed. And poking a hole in it violates at least one of the "rules."

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 24 Jul 2024, 23:16
by TD-er
Ultrasound beamsteering is slightly different from what this sensor does... or at least what I suspect it does.
If it does indeed look at phase shifts in IR, then I'm extremely impressed.
I think it does just have multiple "pixels" to see in slightly different angles.

Anyway, with your background, I think you can already form some ideas of why I have been working lately in improving time-sync among ESPEasy nodes to get sub-msec jitter :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 02:40
by ThomasB
I think it does just have multiple "pixels" to see in slightly different angles.
According to the application notes, by default it uses the entire 16x16 photo diode array for 27°FOV. That is about 10cm diameter at the bottom of the milk container. But the FOV can be programmed to use as little as a 4x4 region, which narrows it to about 15°. So there is merit in this idea.
I think you can already form some ideas of why I have been working lately in improving time-sync among ESPEasy nodes to get sub-msec jitter
Increase your clock frequency. A lot. And switch to decaf. You're welcome. :)

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 08:53
by TD-er
Not sure if my clock frequency should be increased...
It is not like my brain will be in 'sleep mode' while waiting for just about anything.
So better not make those waiting periods even longer.

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 08:59
by chromo23
Hey Thomas,

nice project! I once had a similar problem with a flexible silicone hose. I therefore shortened it and attached a stainless steel tube. It violates your rule #2 but only a tiny bit :) And rules are meant to be broken...sometimes.

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 09:02
by TD-er
Well at least to be "bent a bit".
Quite on-topic in more than one way :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 09:30
by chromo23
BTW: Thomas, you are not the first one that is ESPEasyfying a coffeemachine :D

viewtopic.php?p=65029#p65029

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 10:45
by bidrohini
Hello Mr. Thomas,I have a question. if I use homemade low-cost sensors like this https://www.pcbway.com/project/sharepro ... 69c3d.html
instead of the VL53L1X sensor, how will it effect the performance do you think?

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 18:30
by ThomasB
I once had a similar problem with a flexible silicone hose. I therefore shortened it and attached a stainless steel tube. It violates your rule #2 but only a tiny bit :)
I agree, a stiff hose would solve it. But I would be hated by the coffee crew. Because inserting it into the container would be difficult due to the cramped space in the little refrigerator.

BTW, any changes to the coffee machine's parts, no matter how simple, would allow the manufacturer's repair tech to blame me for everything that goes wrong. Some of my "rules" are intended to prevent that situation.
BTW: Thomas, you are not the first one that is ESPEasyfying a coffeemachine
Nice. Maybe we should start a club for ESPEasy Coffee Machine Hackers.

BTW, you would have been filled with joy if you got to hack the mechanics on the machine I show in the first post. There are many solenoids, valves, motors, and clicky/blinky things to play with. Here's a top view into the main part, which shows the boiler (right) and bean grinder (left).

The machine's main guts.
The machine's main guts.
Eversys_TopView1.jpg (195.62 KiB) Viewed 29409 times
f I use homemade low-cost sensors like this https://www.pcbway.com/project/sharepro ... 69c3d.html
instead of the VL53L1X sensor, how will it effect the performance do you think?
Sensors like those typically have direct contact with the liquid. Which opens up a whole can of worms in my situation due to food safety issues. Which is the reason I need to use a non-contact method of measuring the milk level.

When I was conceiving this project I initially thought of using a strain gauge and measure the weight (0-3.6 kg) of the milk container. But space in the refrigerator was limited and I worried about the sensor accuracy as ice built up on it. Then the idea of using a laser based sensor took hold. And I got what I asked for, but the results are not exactly what I wanted. I hope to rectify that soon. :)

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 22:01
by chromo23
ThomasB wrote: 25 Jul 2024, 18:30 But I would be hated by the coffee crew. Because inserting it into the container would be difficult due to the cramped space in the little refrigerator.
I see, so my next best recommendation would be something like ptfe tubing. Stiff enough but also flexible. ;)
ThomasB wrote: 25 Jul 2024, 18:30 BTW, you would have been filled with joy if you got to hack the mechanics on the machine I show in the first post.
I definitely would be... :)
ThomasB wrote: 25 Jul 2024, 18:30 There are many solenoids, valves, motors, and clicky/blinky things to play with. Here's a top view into the main part, which shows the boiler (right) and bean grinder (left).
There have to be. Otherwise the high price of these machines would not be justified. :shock:

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 22:04
by chromo23
ThomasB wrote: 25 Jul 2024, 18:30 When I was conceiving this project I initially thought of using a strain gauge and measure the weight (0-3.6 kg) of the milk container. But space in the refrigerator was limited and I worried about the sensor accuracy as ice built up on it.
Another idea would be to put the load cell unter the fridge if possible....

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 22:06
by chromo23
ThomasB wrote: 24 Jul 2024, 07:28 I could solve the issue by replacing this flexible silicone hose with a stiffer suction tube so it could be directed away from view. But that would violate rule #2; No changes to equipment are permitted.
i missed that... so no ptfe tube i guess

Re: MilkMate: Liquid Level Sensor Project

Posted: 25 Jul 2024, 22:23
by ThomasB
Another idea would be to put the load cell unter the fridge if possible....
In the planning phase I considered something like that. I looked at digital shipping scales that had a serial port. Prices are low too.

But I eventually decided that the laser distance sensor solution was more elegant and appeared simpler. Got it half right. :)
There have to be. Otherwise the high price of these machines would not be justified.
Crazy high prices! This machine sells for >$20K USD. But it is a coffee brewing miracle. It grinds beans, presses them, adds water and milk foam, and mostly cleans itself. All menu driven, so the user can choose their favorite brew.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 26 Jul 2024, 00:26
by ThomasB
Based on all the suggestions, and the advice from a magic eight ball, I think I can solve this. Hopefully I won't violate any of the rules, at least not in an obvious way.

Currently playing with a short piece of semi-rigid PE poly tubing that I heat-formed into a gentle "S." With a bit of luck I won't have to modify anything on the coffee machine. Will report back soon.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 02 Aug 2024, 06:53
by ThomasB
The solution I decided to use requires cutting the coffee machine's milk suction tubing. Not a horrible thing, but it bothers me because this is a modification and that breaks one of my self-imposed rules.

I'm using 6mm clear PTFE tubing that was heat-formed into a "S" curved shape. The milk cap was redesigned to hold it in a fixed position. When the cap is placed on the milk container the suction tubing is forced into a corner, out of the way of the optical sensor's view.

The PTFE tubing's top end will be connected to the long silicone hose that feeds the coffee machine. The bottom end gets a 17cm length of silicone hose terminated in a filter/sinker that lays on the bottom of the milk jug. This section of hose is the piece that will get cut off the existing suction hose.

Redesigned milk cap with PTFE tubing.
Redesigned milk cap with PTFE tubing.
Milk_Jug_Cap3.jpg (247.81 KiB) Viewed 28780 times

The PTFE tubing is semi-flexible and so it's not difficult to insert it into the milk container while everything is still inside the refrigerator's tight quarters.

I haven't installed the MilkMate system on the coffee machine yet. I need to do a demo and earn approval before I can proceed. But I think I can say the project is done. And a success.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 02 Aug 2024, 08:29
by Ath
ThomasB wrote: 02 Aug 2024, 06:53 I think I can say the project is done. And a success.
Yay! ;)

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 09:40
by TD-er
Maybe you can also write some rules to trigger a warning when the level gradually rises :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 18:35
by ThomasB
Maybe you can also write some rules to trigger a warning when the level gradually rises
Good idea. And maybe there should be an air quality sensor on the milk cap so it can analyze the odor.

Looks like I'm back to the drawing board; Version 2 will fix these missing features.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 19:43
by TD-er
Do you want to wait till v2 is ready, or do you want more new suggestions now? ;)

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 20:26
by ThomasB
You are a brat. :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 20:35
by TD-er
OK, so some more ideas...
You could also wire some current sensing (thus no modifications needed) so you could detect how often it is used.
And some reflective sensor to detect if the stack of cups is low, or change of milk holder so you know how long it has been since last replacement.
Might only need some reflective tape on the milk can.

And maybe adding some presence sensor to turn on some light if needed.

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 21:17
by Ath
:lol:

An active mind can be a burden... but also very helpful :?

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 21:53
by ThomasB
You could also wire some current sensing (thus no modifications needed) so you could detect how often it is used.
That's a tough one. Because the machine periodically does automated functions that current-wise would look similar to beverage dispensing. For example, boiler heating, hot water flushes, coffee rinses, and other operations.

But I have access to the beverage logs using the front touch display. Went rogue and found the password in order to do that. Because I'm a nerd. And the machine has remote access via its Ethernet port that is currently unused (no nearby jack). One of these days I will get it connected to the network and crack that function so ESPEasy can read its mind. :)
And some reflective sensor to detect if the stack of cups is low,
I like that sort of thing. But it is very low fruit. The rack holds about a week's worth of cups and we (coffee crew) visit the machine several times a day to clean/check it. So cup inventory never gets low.
change of milk holder so you know how long it has been since last replacement. Might only need some reflective tape on the milk can.
No need for another sensor to detect if it was replaced. The MilkMate system has an open door sensor, plus the milk cap has a luminance sensor (along with the distance sensor). So plenty of clues to decide if the carton was changed. I considered adding a rule to email me that the milk was changed, but not interested in knowing that (yet).

Good ideas, thanks for the suggestions. Even if you are trying to be a brat. :D
An active mind can be a burden... but also very helpful
Yes, nerd-people like us seem to be afflicted with that problem.

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 22:24
by TD-er
A number of years ago, I've done some work for a company (1.5 year on location) which employs lots of nerds in all kinds of degrees of nerdyness (radio-astronomy) and one day the cleaning crew (or maintenance crew) did not properly lock the front of the coffee machine.
There you could see an USB connector and some view of the PCB.

Within a day someone had tried to write a new firmware for the coffee machine, probably trying to add some easter egg.
That didn't go as well as planned, as one of those firmware-upgrades did actually brick the machine (not even the first attempt) and we had to walk to another one further away for at least a week.
And no, it wasn't me... I only heard about it from various people.

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 22:27
by TD-er
ThomasB wrote: 03 Aug 2024, 21:53 [...]
Good ideas, thanks for the suggestions. Even if you are trying to be a brat. :D
A brat ? ;)

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 22:44
by ThomasB
:lol: Hee-hee. Yes you were being "a brat." This is not the same as "being brat."

https://www.reddit.com/r/OutOfTheLoop/c ... term_brat/

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 03 Aug 2024, 23:11
by TD-er
I also found this as a description:
"very honest, very blunt, a little bit volatile."
To double-down on this definition;
Sounds like typical Dutch to me :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 04:15
by ThomasB
MilkMate has been in service for a while. So I think it's time to do a short presentation of the project. Although it only monitors milk status in an espresso machine at my community clubhouse, it has been a game changer.

The espresso machine is in a small convenience store that utilizes Amazon's Just-Walk-Out technology. No one is on site, customers just grab and go.

Amazon Store
Amazon Store
20230925_113807.jpg (2.19 MiB) Viewed 2602 times

Despite being a "super-automatic" machine, the espresso maker is intended to have a staff person on hand to keep things running smoothly. But this one is on its own, with a small ghost crew that visit every couple hours to restock and clean.

BTW, using a touch screen the customer can select lattes, cappuccinos, macchiattos, espressos, and so on. All using freshly ground beans with smoothly textured milk foam. The coffee is free and tastes just as good as the local Starbucks (some say better).

Espresso Machine
Espresso Machine
20250126_202928.jpg (2.44 MiB) Viewed 2602 times

At the back of the customer cup holder rack is a small color display for reporting milk level and temperature. The display's enclosure only has the TFT panel and it is connected via a long SPI cable to the ESP32 that is inside a cabinet. Power is by a wall wart. ESPEasy runs the show.

Color Display shows milk level and temperature
Color Display shows milk level and temperature
20250216_202511.jpg (3.17 MiB) Viewed 2602 times

Inside a 3D printed milk jug cap is a VL53L01 distance sensor and LM75A temperature sensor. These do not come in contact with the milk, which is important for food safety.

The milk level measurements are insanely accurate. Resolution is 1% (0-100%), and device accuracy is ideal for this application. In a nutshell, the displayed milk level values are spot on.

The temperature sensor is in contact with the exterior surface of the milk jug, where as our old method relied on measuring the air temperature in the fridge. The contact method is much better.

Milk Jug with Sensors
Milk Jug with Sensors
20250129_142935.jpg (2.93 MiB) Viewed 2602 times

Before MilkMate the crew member had to pull out the refrigerator from a locked cabinet and then open up the fridge to see the milk level. Now they only need to walk by the display.

But there's another trick it can do. The crew gets hourly status notifications on their phone. Urgent SOS notifications are sent if the milk runs out.

Mobile Notifications
Mobile Notifications
Milk_Empty2.jpg (43.65 KiB) Viewed 2596 times

Count me in as another satisfied ESPEasy user. If any of the devs drop by, the coffee is on me. :)

- Thomas

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 08:51
by TD-er
Cool to see the result! 8-)
And I'll remember the offer for coffee :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 09:09
by chromo23
Great project! Happy to see that it works as expected. :)

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 09:33
by Ath
That's a clean and professional looking coffee corner :D

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 10:06
by TD-er
Yep, now that you mention it, I don't see any duct tape... :lol:

Re: MilkMate: Liquid Level Sensor Project

Posted: 11 Mar 2025, 19:36
by ThomasB
TD-er wrote: 11 Mar 2025, 10:06 Yep, now that you mention it, I don't see any duct tape...
Oops, looks like I forgot it. :)