Simple Raspberry Pi Pico Bartender
The idea of a Raspberry Pi Bartender project was actually started in 2018. We started of with a Raspberry Pi Zero W, 2 Channel relay, 2 pumps, step down converter and batteries. It was spurred at an event that we were at, where the drinks were getting stronger and stronger as the day progressed. People were also dropping bottles by the end of the night. Shortly before this event we had read an article about someone who created one of the first automated cocktail mixing machines using a Raspberry Pi. While this project was great; this was not really what we were looking for. We wanted something much simpler. And at this event the design started. Which eventually grew into a Raspberry Pi Pico Bartender
We started the build early the following week. We had one of our staff build us a wooden stand, drill the holes for the tubes to feed through and through the bottle caps on the other side of the pumps.

At first this seemed like such a great idea, but then we started noticing some difficulties pop up. We only hooked up 2 drink bottles to the pumps. Using relays to switch them on, wait a few seconds and turn the pumps off.
The first of the difficulties was that the buttons would seemingly randomly read presses. I started a log, to see if it was the relays malfunctioning, or was my program actually picking up button presses. The result… The program was actually reading the button presses. For the life of me I could not work out why. I spent hours messing with the code and had no joy. So eventually we packed the project away for a later date.
Fast-forward to 2021
We finally took our barman lovingly named “Dezzi” out of the dust and started the project up again. By this time the Raspberry Pi attached had been damaged, needing replacement. This took place soon after the global silicon shortage had really taken effect. So instead of opening another Raspberry Pi (which was in very short supply), we made the decision to use the recently launched Raspberry Pi Pico instead. At a much lower cost, and it was a new product, that this would give us the chance to test one out a little.
I wrote some wonderful code in micro-python, redid all the wiring for the MCU and relays. With all the hope in the world that our past problems would not arise; and again we started up the machine… And ended up very dissapointed. Same problems with the Pico. This was the point at which we decided we now really need to know what the issue is. After a few weeks of digging around online at every opportune time, we found it. Button noise… usually solved with the right resistors at the right places. I tried this a few times, but after still not having too much luck, I came across a forum post that suggested using Adafruits CircuitPython instead. This used the built in resistors on the MCU, so you don’t need to do the math. And voila!! Finally the first problem solved.
We finally got to use the machine long enough to uncover another problem. This, we decided would take place in a solution on another day. Let’s get the first version working, then we can make it better.
I will walk you though the current solution, if you want to follow along our journey and maybe offer us some advise.
Hardware:
Raspberry Pi Pico with presoldered headers
Two Channel 5V DC Relay Module
2 Official Sanwa Arcade Button (Green)
12V 7Ah Sealed Lead Acid Battery
Dual USB Output 6-24V To 5.2V 3A DC-DC Step Down Power Converter
Rocker Toggle Switch Waterproof Boot (main switch on and off)
Software:
Set up your Raspberry Pi pico: https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico
I will not be walking you through how to use CircuitPython on Pico, I think Adafruit did a fantastic job at that!
While the main tutorial is easy enough to follow, I am not a fan of MU editor. I wanted to keep using Thonny. I finally found that yes I can have both with: CircuitPython Libraries on MicroPython using the Raspberry Pi Pico
Using this tutorial, you use the same bootloader as you always did, and you simply install the CircuitPython libraries. You can follow their tutorials and familiarize yourself with how it works before continuing.
Great now that you have followed their examples to get your Pico ready, let’s get started.
Wiring:

Button 1 | 3.3 V and GPIO 15 |
Button 2 | 3.3V and GPIO 16 |
Relay IN 1 | GPIO 0 |
Relay IN 2 | GPIO 1 |
Hearbeat LED | 3.3V and GPIO 21 |
After this the Relay Power and GND is connected to 5 V on the Pico and GND rail on the breadboard. The Pump power wires is fed through the relay and connected to the 12V battery. The Dual USB Step down is connected to the Battery on power and GND pins, then using a Micro-USB to USB cable to power the Pico.
Code:
First we will start with importing the required libraries:
import board
import digitalio
import time
Then we can start assigning our PINS.
pump1 = digitalio.DigitalInOut(board.GP1)
pump1.direction = digitalio.Direction.OUTPUT
pump1_btn = digitalio.DigitalInOut(board.GP16)
pump1_btn.switch_to_input(pull=digitalio.Pull.DOWN)
pump2 = digitalio.DigitalInOut(board.GP0)
pump2.direction = digitalio.Direction.OUTPUT
pump2_btn = digitalio.DigitalInOut(board.GP15)
pump2_btn.switch_to_input(pull=digitalio.Pull.DOWN)
I set the relays to GPIO 0 and 1 on the Pico, and set them as an output. The buttons are connected to GPIO 15 and 16, this is set to pull down. This pull down assignment is where the internal resistors come into play.
Because LEDs and relays work in opposite directions; LEDs are pull up (you set the pin high) and relays are pull down, we need to work in the opposite direction in our code. So we now set the pumps to true, which will set the initial state of the relays to off.
pump1.value = True
pump2.value = True
Next I added a “heartbeat”, this is a simple indication of when the machine is ready to pore
heart = digitalio.DigitalInOut(board.GP21)
heart.direction = digitalio.Direction.OUTPUT
heart.value = True
Let’s take a quick look at the rest of the code. Simple yet effective.
while True:
if pump1_btn.value:
print("pump1 pressed")
heart.value = False
pump1.value = False
time.sleep(15)
pump1.value = True
heart.value = True
time.sleep(1)
if pump2_btn.value:
print("pump2 pressed")
heart.value = False
pump2.value = False
time.sleep(15)
pump2.value = True
heart.value = True
time.sleep(1)
Here we say that if one of the buttons are triggered, the first turn the heartbeat off, as the machine is unable to pore at that moment. Then trigger the relay, wait for 15 seconds, turn the relay off again, and hearbeat on again. Settle then exit the loop.
if pump1_btn.value:
heart.value = False
pump1.value = False
time.sleep(15)
pump1.value = True
heart.value = True
time.sleep(1)
The same is duplicated for the second button. The script is saved as main.py, as this is the script the Raspberry Pi Pico looks for the run at start up.
In a later post I will take you though an update or 2, along with removing the duplication in my code.