Vending Machine


What do you do with an old coke machine? Put it under computer control and make it delightful!


A vending machine is a common machine, so people expect it to work a certain way. Simply doing something unexpected is rewarding. Playing a song when the machine would otherwise be silent, flashing lights that dont usually flash, vending strange objects in large quantities at unexpected times.

A vending machine is an invisible mechanism. The internals are elaborate compared to the simple insert coin, push button interface. Adding new depth to the interface is rewarding. Secret button codes, invisible sensors for member cards and fingers. This happened accidentally, allowing people to get free drinks by executing a careful sequence of actions.

A vending machine is a provider of wealth. The contents of the machine are inherently motivating, and can be leveraged to motivate people through elaborate actions. Connecting a Dance Dance Revolution (DDR) style dance pad to the machine, and making the selection of a drink depend on executing a sequence of steps successfully was rewarding. Hiding the operation of the machine behind a web API and enabling people who can program to get free drinks.


In its regular configuration, this model of vending machine was an elaborate electromechanical mechanism. It involved no microcontrollers, instead using relays, motors, cams, solenoids, buttons, limit switches and a coin acceptor to execute the pay/select/vend sequence.

First, the coin acceptor was replaced with a Raspberry Pi. This allowed computer control of the payment accepted signal, which would allow the select/vend sequence to continue. This was indicated to the rest of the machine with a 120V AC signal line, controlled via a relay connected to the Raspberry Pi.

Next, speakers were added. This was a simple set of desktop speakers in the base of the machine, connected to the 3.5mm audio jack on the Raspberry Pi. This allowed a song to play on successful vend.

Next, panel light control was added. The front panel of the machine is a frosted acrylic with a vinyl graphic overlay. The attention getting lighting behind it is usually from fluorescent tubes. These were replaced with LED light strips, controlled with a FET that could be turned on and off rapidly to set the intensity of the lighting. This was connected to an Arduino for high speed control, and the Arduino was connected to the Raspberry Pi for computer control of the lighting. Now the lights would flash and a song would play on successful vend.

This left the select/vend sequence under machine control, limiting our creative options. The buttons for selection and the motor array for vending are directly connected with AC signalling wires, meaning they had to be modified together. The motors were put under control of a relay array. Fortunately they are equipped with cams and limit switches that take care of rotation positioning for us. Once the motor begins rotating, a limit switch and cam will keep it rotating until it has returned to a home position. The relay board was connected to an Arduino, providing a USB serial interface for computer control.

At the same time the front button array was wired into an Arduino, in a common ground configuration. The Arduino would scan the button array and report which buttons are closed using flag bits in a byte sent over the USB serial connection, allowing a computer to read the button state.

After this, the Raspberry Pi was able to read the button sequences and control the motors directly. This allowed secret button sequences, different payment amounts, surprise vending, random vending, etc. At this point the machine was mostly under computer control, excepting monitoring of stock levels, temperature and control of the refrigeration unit.

Keywords: embedded, distributed, Linux, Raspberry Pi, Python, C, Arduino, Stripe


Regardless of delight, the machine does charge money for drinks, and a good metric for success is profit. This is driven by a revenue - costs = profit model. Revenue is drinks sold * drink price, costs are drinks sold * drink price * processing fees.

If the machine is not operating because it is broken or in some configuration where drinks are not sold, revenue will suffer. Conversely, if more events are held at the hackerspace revenues tend to increase as more thirsty people are around to buy drinks.

While I was at the hackerspace, the machine created some hundreds of dollars of profit for the space. I am not currently maintaining the machine, however it is still in use.

Get notification of new articles via email: