Robot Glockenspiel

Here's a robotic glockenspiel which can be programmed and played from the Internet. This two-minute video gives an overview:

If you want to try it out, visit glockenspiel.appspot.com

The source code is at github.com/NeilFraser/glockenspiel

If you are interested in the hardware, read on below.


In 2019 I turned my daughter's toy xylophone into a self-playing robot. It was fun, but I quickly got frustrated trying to compose music for an eight-note scale. So I purchased a second-hand 25 note glockenspiel from eBay for $35.

[Photo of the top of the glockenspiel]

The glockenspiel sits over 25 solenoids, each of which strikes one of the glockenspiel's bells from underneath. This allows one to play the glockenspiel normally with mallets from the top while the computer plays from the bottom. There's also a big red reset button to terminate the current tune.

The wooden board is an off-cut from making our dining room table.

[Photo of the robot with the glockenspiel removed]

The glockenspiel itself is largely unmodified. Four slots had to be cut into the plastic edges to permit access to the bells in each corner. The craters on the bells are made by the factory during tuning.

[Photo of the underside of the glockenspiel]

Each solenoid is a push-pull design. They run off 12 volts, have a 4 mm stroke, and cost around $1 each from China. To avoid a harsh metal on metal striking sound, I laser-cut a tight-fitting plastic ring around the tip, epoxied a laser-cut cylinder of wood onto the the ring, sanded the wood down to a hemisphere, and coated the top with liquid latex.

[Photo of a push-pull solenoid]

The solenoid holders were designed using SketchUp, then 3D printed. The black holders (for the accidental notes) hold the solenoids a bit higher than the white holders (for the natural notes). Some laser-cut wooden and cardstock shims allow for fine-tuning of the final height.

[Photo of solenoids in 3D printed mounts]

The underside of the main board looks a bit overwhelming at first, but it's actually just the same simple circuit repeated 25 times. Care was made to label each wire and maintain orderly wiring harnesses. When one note stops playing in 10 years, I want it to be relatively simple for my daughter to debug and fix.

[Photo of the underside of the robot]

A Raspberry Pi Zero W is mounted at one end of the board. It cost $10 and is a full Linux computer with onboard Wifi, a couple of USB ports, and an HDMI connector. More importantly, this computer has 26 GPIO pins -- which directly led to the choice of a 25-note glockenspiel. The extra GPIO pin is used for the illuminated reset button.

[Photo of the Raspberry PI Zero W]

Each of the GPIO pins runs to a MOSFET transistor which controls a solenoid. Originally I purchased ready-made boards, but made the mistake of getting ones that used TRIACs. Those only work for AC, not for DC (they can only switch off when the voltage is 0), so I had to replace them. Since the rest of the hardware had been built, I made my own MOSFET boards that exactly matched the form factor of the discarded TRIAC boards.

[Photo of one of the MOSFET control boards]

All the solenoid wires connect to a central terminal block. Soldered to the back of the block are all the flyback diodes that safely discharge the energy of the collapsing magnetic fields when the solenoids switch off. Without them, the EMP would cause the computer to reboot after the first note (ask me how I know).

This 40-pin terminal block used to be part of the signalling system of the West German railway system (DB). They ripped out tons of hardware when they updated from relay-based logic to computer control back in the late 1980s. I never figured out what to do with those fancy 20 pole relays, but the terminal blocks keep coming in handy.

[Photo of the main terminal block]

Hidden under the board is a muting switch. It cuts the common power wire for all the solenoids. With this switch flipped, the computer still runs, the status lights on the driver boards still blink, but no power flows through the solenoids. This is useful at night.

[Photo of a muting switch]

The power supply is a relatively anaemic 12 volt 2 amp wall-wart. It's not capable of fully powering a large chord (where multiple solenoids fire simultaneously). The real stars are two capacitors that do most of the heavy lifting. Each solenoid strike is only 8 milliseconds long, so the capacitors have plenty of time to recharge before they are called on again.

[Photo of a pair of capacitors]

In the centre of the board is the main power distribution block. 12 volts (yellow) and ground (green) come in from the capacitors, and 5 volts (red) is generated by a buck transformer wrapped in heat-shrink tubing. The 5 volts runs the computer and the status lights.

[Photo of the power distribution block]

The glockenspiel needs to be transportable so that it may get to Maker Faire and the like. I built a custom carrying case out of scraps lying around. The side wood are off-cuts from someone's redwood deck. The main panels are off-cuts from the floor of our library. The handle is from a suitcase I found on the side of the road. I had to buy the hinges and clasps.

[Photo of the glockenspiel in its case]

I'm almost as proud of the case as I am of the glockenspiel. As such, when I flew it across the Atlantic for a conference, I was worried that the case might be damaged. Thus I packed the case in a cardboard box with some custom styrofoam inserts. After that trip the cardboard was pretty well shredded, but everything inside was intact.

[Photo of the suitcase closed]

While this page is all about the hardware, what I consider the most interesting part is the software. One can program tunes using Blockly, or JavaScript. Code is executed using the JS-Interpreter. MIDI files can be imported and converted to blocks.

Here's a random collection of interesting tunes:

Lullaby (JavaScript)
Wiegenlied, Op. 49 by Johannes Brahms. Plays three times, the first time at regular tempo, the next two progressively slower. Simulates a music box winding down.
Happy Birthday (Blockly)
Four trills per note.
Alle Meine Entchen (Blockly)
Loops nested three deep.
Frére Jacques (Blockly)
Played as a two-voice round.
Tam Lin (JavaScript)
Starts slow, speeds up.

If you compose something good, send me a link by email.

Additionally, here's a directory of MIDI files which play very well on the glockenspiel.

-------------------------------------
Last modified: 31 August 2023