A Glockenspiel Music Box

My project ‘to-do’ list has for a long time included automating a percussion instrument. I recently decided that a xylophone or glockenspiel type instrument would be a good idea … until I saw the cost of one of those things!

So to fulfill my ambition in an economical way, I downsized to automating a toy glockenspiel. Here’s how it went.

Getting the parts together

I spent very little time planning this project and just ordered bits and pieces as they were needed. This meant that the delivery times from eBay resellers became the longest parts of this project – some brief bursts of activity followed by long waits spent doing something else.

Once I decided to use a toy, I needed to find one! After looking on eBay for a couple of weeks, I was able to source what seemed like a reasonable instrument with 15 playable notes (most toys only have eight notes, which is rather limiting). When it arrived, each note was helpfully marked on each tube (C, D, E, F, G, A, B, C, D, E, F, G, A, B, C). So, no sharp notes (#) but it covered two octaves + 1 note.

Working with the actual glockenspiel, and with half-formed thoughts on how the automation could work, I ordered a swag of small solenoids that could be used as strikers for each note. As is often the case, I ordered from an reseller supplying cheap prices but with little or no product knowledge, so essentially a I took a gamble on whether they would suit, with possible disappointment after a long wait for delivery. Luckily, the solenoids turned out to be suitable.

Once the solenoids checked out, I then ordered the small M2 screws to suit them, and got on with designing and implementing project while they travelled across the world to my workshop.

Basic design

I did some testing on the sound produced from the glockenspiel and the best sound came from striking each note in the center of the supported span. This makes sense for a ‘sweet spot’, as this is where the tube has the greatest vibrational amplitude.

I also measure the frequency of the notes using an App on my iPhone. The first C was 1.06KhZ, the center C was 2.12 KHz and the last C was 4.32 kHz. These frequencies correspond to C octave 6, C7 and C8.

The instrument came with a triangular plastic stand and I decided it was easier to incorporate this in the final product rather than use the tubes in a custom built stand, which is an often used technique when I searched for other similar projects.

I also found several recommendations to include some dampening material between the solenoids and their support, as the solenoid operation ‘clicks’ caused vibrations that were amplified by any supporting structure. This was duly noted and some 4 mm self-adhesive rubber foam was sourced for this purpose.

Making something

All the major parts were constructed from workshop scraps, mostly plywood. The final general arrangement for the device is shown in the photos below.

The yellow plastic base of the instrument is held in place by blocks at either end so that it cannot move. This is important for maintaining the relative position between the note tubes and solenoids overhead.

The solenoid driver hardware was discussed in this previous post, so will not be covered here. Each solenoid’s actuator signal is wired back to these boards, but to save some wires the common 12V supply for each pair was joined near the solenoids before being wired back to the driver boards.

The driver boards are connected to the Arduino using SPI (5 wires) and the solenoid 12V power is supplied into the barrel jack by a bench power supply (not shown).

Each end of the solenoid gantry is adjustable in the X, Y and Z directions to ensure that the gantry can be set up to make the solenoids align:

  • with the central axis of the instrument. As noted earlier, this is where the best sound is produced.
  • optimally above the tubes. The solenoid plunger should be at almost its maximum stroke so that it will ‘flick’ the tube when it strikes it.
  • so that they strike the top center of the tube.

These adjustments are made using M5 screws, metal inserts installed into the plywood components, and a T-nut epoxied onto the aluminium gantry bar (see the photos above). This scheme worked well to provide all the fine-tuning necessary.

Finally, the solenoids were screwed in place with their M2 screws through the aluminium gantry, with the dampening foam sandwiched between the back of the solenoid and the aluminium.

Wiring was straightforward, but tedious, and it checking for correct function every few solenoids helped make this a smooth process.

Initial testing

Once the hardware was roughly set up, a simple sketch to play all the notes loaded and run to allow for fine tuning the sound (ie, the distance of the solenoids from the note bars) and the optimal firing time for the solenoid to produce the ‘flick’ effect mentioned earlier.

The strike activation time was, for me, surprisingly short at around 10-12ms. It is also quite a critical time constant, as 8ms causes the actuator to ‘miss’ hitting the note and over 12ms causes an audible ‘thunk’ as the actuator is held onto the tube after hitting it.

The test code is shown below and the sound it produced, once the system was tuned, can be heard here. The Actuator class is a simple encapsulation of the SPI communications and the n-bits of actuator data.

include "Actuator.h"

// Basic definitions
const uint8_t NUM_ACTUATOR = 15;  // number of actuators
const uint8_t PIN_LD = 10;    // SPI SS pin
const uint8_t PIN_CLK = 13;   // SPI CLK pin
const uint8_t PIN_DAT = 11;   // SPI DATA (MOSI) pin

// Actuators object
void setup(void)

void loop(void)
  static bool b = true;
  for (uint8_t i = 0; i < NUM_ACTUATOR; i++)
    Serial.print(F("\nbit: ")); Serial.print(i);
    A.set(i, true);
    A.set(i, false);
  b = !b;

Playing a note

One aspect that I wanted to explore was whether the solenoid striking produced a sound that was any different from the mallets provided by the toy manufacturer. Particularly, I was concerned that the solenoid could produce a tinnier sound, as the metal plunger was different from the wood in the mallets.

To my untrained ear they sound very similar. A capture of the waveform produced also looks nearly identical (image at left). In the captured waveform there is a difference in the clarity of the resonance (ie, how much of a V notch there is between the bumps in the waveform) and how long the notes last, but this is likely due to how hard the note was struck. It is interesting that the shape of the waveform at the start, when the note is struck by the solenoid plunger/mallet, is very similar in both cases.

The Music Box

To test how well the project would play actual musical tunes, I wrote an RTTL player leveraging the a previous library (see this article) to simplify the implementation.

The result can be heard here. Not the most brilliant performance (especially without sharp notes), but still not bad for a toy glockenspiel, and certainly much better than I could play it!

The code for this project is available at my code repository.

All-in-all a fun project that was interesting from both a hardware and a software perspective. I learned something from this and I ended up with some new libraries and tools to use on other projects.

And I also ticked another project off my Arduino bucket list!

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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