CandyLock - A Candy Jar Only the Owner Can't Open
A candy jar that locks out it's owner - only Chat holds the key.
The Concept
To keep my chat-controlled claw machine refilled, I buy the biggest containers of m&M’s I can find. But somebody keeps eating them straight from the jar at all hours of the day. Not me. Somebody else. So to curb my their excessive sugar intake and keep me from buying pounds of m&M’s a week, we need a lock that only a third party can open.
The Lock Hardware

The containers I buy twist open at the top. So if we design a cage around that, tight enough to not come off but loose enough that it spins freely around the lid, we can keep the jar from being opened.
Simply slice the design in half and with a hinge on one side and latch on the other we have a functional lock.
A small compartment by the latch is enough to house the microcontroller and solenoid, with a mosfet to energize it. No battery necessary for this one as it can be plugged into USB power anytime it’s to be used.
Microcontroller & Wiring
A USBC port is the only connection to the outside of the lock. Wires for power and ground ONLY are delivered to the rest of the circuit, no USB data lines. One mosfet is used to provide ground to the solenoid which engages it, only requiring one GPIO from the MCU. The lock is spring loaded so it re-locks as soon as it’s closed again, not requiring power or another input from the Internet.
Trusted Third Party
In programming the Wi-Fi microcontroller, you can set the trigger to be anything you can think up. My lock listens to my twitch chat and will respond to any unlock command that doesn’t come for me or one of my accounts. Obviously this could be made more secure in the future and only listen to a white list of specific people.
But you could also connect it to discord to be controlled by your friends, or when you’ve finished a workout that day, or even just at a specific time or days of the week.
But you’d have to be there at that time, ready to seize the opportunity. Otherwise no soup for you.
Safeguards From Yourself
The separate, power only, USB port means you will not be able to plug in and reprogram this to give yourself a snack. The microcontroller is accessible for maintenance only from the inside, after the lock has been opened.
After debugging and finalizing your code, disable the web portal and OTA downloads and flash it once more for the last time. Don’t leave yourself a back door that you “totally won’t take advantage of” on a whim.
I find that when done properly, I don’t even consider this candy an option for me anymore and don’t crave it, even knowing it’s there. In the end, the lock psychologically fixes the problem instead of mechanically.
Resources
Source code (made with AI assistance): https://github.com/DaverDavids/CandyLock
3D files: https://github.com/DaverDavids/CandyLock