Solenoid Music

Posted: June 8, 2022


Here's a simple electronics project for creating music using different sized glasses of water. I found a set of 5 super cheap solenoids on Amazon and got two of them so there could be a total of 10 tones. It turns out the intro to Guns N' Roses Sweet Child O' Mine only requires 8 tones, so I built a circuit and programmed an MSP430G2553 to trigger the solenoids.

The source code is written in Java and compiles / assembles with Java Grinder and naken_asm. Expanded explanation, video, and source code below.


The video shows 7 of the 8 glasses / soleonids. The 8th is on the far right and out of the video. Trust me, it's there :). I originally had all 8 solenoids hot-glued to the board, but to get the lower notes, it required bigger glasses. The lowest notes also have extra wooden blocks to raise the solenoid up so it hits in a spot that rings better. The sound is captured just by the microphone on the camera and even the bass guitar isn't hooked up to an amplifier, so it's a little quiet. Oddly, this is the song that made me get a guitar.. and instead of playing guitar here I'm playing bass. YouTube:


The most tedious part of this project was the physical setup. For every solenoid there needs to be a PN2222 transistor, 2 resistors, one kickback diode, and wires connecting to the MSP430 and to the solenoid. Since I had 10 solenoids, I decided to make 10 of these little circuits, but in the end only 8 were actually needed.

For the solenoids, normally each one could cost at minimum $10 each which would have made this an expensive project, but someone was selling sets of 5 of these for around the price 1. The comment on Amazon warned the buyer that these were pretty small and not very strong. For this project, totally perfect. A strong solenoid maybe could have broken the glass. These struck the glasses at the perfect strength to make it loud enough and not hurt anything.

On top of the solenoid circuits being tedious, finding the right glasses to get the right tones was not fun. When going to Walmart and grocery stores, I was in the cooking and bottled drinks aisles tapping on all the glass looking like a jackass trying to find the right tones. Ended up getting a measuring cup and some expensive bottled waters that fit this project. Actually, the Whole Foods Organic Pink Grapefruit soda is quite good.

The firmware on the microcontroller was written in Java, just because it made it a little easier than assembly language. Definitely makes the code easier to read, a lot more English-like. P2.0 to P2.5 are connected to the first 6 solenoids and P1.4 and P1.5 to the final 2. The code runs at ~2MHz and implements a TimerListener interface with a timerInterrupt() method that is called every 2000 CPU cycles. To delay in the main() code, a simple while loop waits until a certain number of interrupts fire.

Source code

Copyright 1997-2024 - Michael Kohn