Peanuts for the code monkey


Write code, commit to GitHub, get peanuts…

A few months ago I bought a mini gumball machine from the clearance section of Maplin – I think I paid about £4 for it. I wasn’t really sure what to do with it, so I just left it for a while. Then I had an idea: a bit like those animal behaviour experiments you sometimes see on TV, it would be cool to have a gumball machine that automatically rewarded me for doing work.

The thing I like about this project is that it’s a really minimal hack. I’m not aware of many — any? — Ardunio projects that use just one wire (you’d normally need at least two wires to complete a circuit for even a simple blinking LED project). There is no Arduino code to write because the project uses the Standard Firmata sketch that comes with every Arduino install.

In fact the only ‘work’ in this project was writing the Node code to query GitHub and control the Arduino pin.

If you’d like to make your own version of this project, here’s what you need…


For this project I used an Arduino Nano. It’s the smallest Arduino I’m aware of that has built-in USB. A Nano without pin headers can fit easily inside the base of the gumball machine. If it has pin headers you might have to bend some of them to get it to fit.

The Arduino USB connection needs to feed through the back of the gumball machine and out to the ‘host’ machine that you plan to run Node on. I used a drill and hacksaw to make a narrow slot in the back of the gumball machine. It’s pretty neat, but if you were going for perfection you could wire a USB port to the back of the gumball machine so that it can be mounted flush for a factory-fresh look.

The switching is really simple. Rather than control the motor directly (which would’ve required a relay, MOSFET, motor shield or similar) I relied on the electronics already contained in the gumball machine. The machine has a touch sensitive button which detects its small current being grounded by a person touching the button.

You can achieve the same effect by using the internal pull-up resistors on an Arduino. Simply cut the wire that is going to the button and connect it to one of the digital pins on the Arduino. I used a short female jumper cable to make it a solderless hack, but you could just as easily solder the wire straight on to one of the Arduino pins.

All that remains on the gumball side is to write the StandardFirmata sketch onto the Arduino board. It’s in File > Examples > Firmata within the Arduino IDE.

The Node.js script

The node script is available on GitHub.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.