What’ll it be? Monkey wrench, swimming pool, zombie, painkiller? You can have any of these exotic drinks and more mixed by Stefan Höving’s home-made cocktail machine, whose secret ingredient is a Raspberry Pi.
This article first appeared in The MagPi 70 and was written by Nicola King
Bioengineering student Stefan came up with the idea for automated cocktails thanks to a friend who “would always pour way too much alcohol into the drinks when we would get together on the weekends… We basically needed something that can ensure that everyone always has the same composition of juice and booze, that would still be enjoyable.”
Stefan was also looking for a project to practise his fledgling Python programming skills, learned during his part-time job at an analytical institute. “The first thing I had to do was program a graphical user interface in PyQt for a temperature control system,” he recalls. While that never came to fruition, the GUI would eventually be put to good use in his cocktail machine, which offers a choice of nine drinks via a touchscreen display.
Tubes and valves
Housed in a handcrafted hexagonal wooden case, the cocktail machine holds five bottles. Each is fitted with a shot dispenser with two tubes: air is pumped through one tube to force liquid up the other, which leads to a magnetic valve to turn the flow on or off. “From there, all five tubes (one for every bottle) are funnelled into the outlet that one can see above the glass,” explains Stefan.
To ensure the correct volume measures are poured out, the platform where the glass is placed is a scale. “The first thing the program does after a cocktail is selected is [discount] the weight of the glass. I was surprised by how precise the scale actually is.”
It did cause Stefan a headache during development, though. “For some reason, [its HX711 ADC] chip would produce random and really off values, although there was nothing on the scale. This would only happen when the machine was completely assembled. I reassembled the machine three times until I understood this behaviour.” In the end, the annoyingly simple solution was to connect the VCC of the HX711 to 3.3 V power instead of 5 V.
Stefan also had a problem with the original aquarium air pump, which worked fine with one bottle but couldn’t produce enough pressure to displace liquid from all five. “The gas volume of the five bottles combined was simply too high. So I got myself a bigger pump and it worked.”
The air pump, magnetic valves, and LED lighting are controlled by an eight-channel relay board connected to the Raspberry Pi via a PCB with resistors. “For making easy connections, I soldered them and some plugging connectors to a PCB board. So I have easy access for maintenance purposes.”
Equipped with bottles of rum, vodka, cola, orange, and pineapple, the machine can produce nine different cocktails using the recipes within the Python code – available from Stefan’s GitHub repo – but it could easily be adapted to produce other drinks, including non-alcoholic ones. “For new cocktails, you would have to adjust the ratios in the code accordingly.”
Dispensing liquid from each required bottle in turn, from the smallest to largest volume, helps to mix them in the glass. “A mechanical way of stirring might be possible,” says Stefan. “However, I have not come up with an elegant solution so far… I am open to any suggestions.”