LEGO + Build HAT chocolate-dispensing Advent calendar
Richard Hayler tells us about a tamper-proof chocolate-dispensing Advent calendar he built using the new Raspberry Pi Build HAT and LEGO.
After working on the Raspberry Pi Build HAT for so long it was great to finally get it launched so that I could actually start playing with it myself and working on something just for my own satisfaction.
When my children were younger I’d often discover that they’d cheat with those cheap Advent calendars by removing all the chocolates on December 1st and then sealing the doors shut again. So I’d pondered some sort of automated treat-dispensing machine that only releases one chocolate each day.
How does it work?
When you press the button, the light will turn green and dispense a sweet if one hasn’t already been dispensed that day. If you have already used the Advent calendar that day, the light will turn red and you’ll have to appease your sweet tooth elsewhere.

The Raspberry Pi computer keeps a log file of when a treat has been dispensed, rather than just relying on checking the day of the month. I didn’t want anyone cheating the system by just rebooting the Raspberry Pi.
Precision motor control and easy prototyping with LEGO and the Raspberry Pi Build HAT made this project far less frustrating and time-consuming than when I first toyed with the idea of 3D printing a mechanism a few years ago. And the Build HAT Python library served me well on the software side of things.
Chocolate martyr
Designing an approach that would only release a single chocolate ball at a time was the trickiest part of the build. I did have to experiment with different sizes and shapes of confectionery and unfortunately had to consume the rejected ones as I was going along. Cup-shaped sweets worked well (and were tasty) but were just too large for 24 of them to be held without making the overall build too big.

The video footage of the finished project was very rough but fortunately I was able to bribe my son (with chocolates obviously) into using his editing skills to put together what I think is a fairly decent promo.
Digital décor
The LEGO elements are really colourful and make a great decoration on their own. I was imagining a Hansel and Gretel candy house aesthetic which I think works well, and it meant I could just use random elements that I had in the LEGO tub.
The 3D LED Christmas tree was a perfect fit for the space left over and nailed the festive theme with some simple random blinking, thanks to the GPIO Zero Python library.

So the end result was a cool centrepiece of the kitchen table. The only problem is we’re all a little bit sick of chocolate after all the scoffing that went on during the build.
No comments