CONTENTS

Home
Updates
Software
Electronics
Music
Resume
Contact


YouTube
BlueSky
GitHub
LinkedIn


Solenoid Music

Posted: June 8, 2022

Introduction

This is a set of projects that use solenoids to smack things to make music. The first project uses a set of glasses filled with different levels of water to make different tones. The second is the same solenoids hitting keys on a xylophone.

Below are the videos for the projects and below that are longer explanations of what was done to make these projects work, including source code..

Video

The video shows 7 of the 8 glasses / soleonids with the 8th on the far right and out of the video. The solenoids are glued to a wooden bar on the main board to raise them so they hit closer to the middle of the glass. 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: https://youtu.be/2_NfvhZ4FB4

Video Of The Xyolophone Coming Soon.

Water Glasses

The first project uses different sized glasses of water to create different tones. 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. There is a link to the source code at the bottom of the page.

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.

Xylophone

After working with glass, it seemed like a xylophone project was needed. I found a super cheap xylophone on Amazon and made a wooden structure that could hold the same solenoids. This project not only has a xylophone, but an M5Stack MIDI module for the drums. That module runs at 5v so it seemed like switching to a Microchip (Atmel) ATtiny2313 would make sense. This time the code is written in assembly language.

To do the drum sequence, I used Drums++. To make it possible to have a melody for the solenoids, I added a "melody" feature to Drums++. The Drums++ source file dark.dpp contains the drum sequence and melody using the the new syntax. After being compiled by Drums++, a dark.mid file is generated. The .mid file is then converted into .json using parse_mid. A python script then reads in the .json file and builds a file called music.inc that contains the data in a format that a small music player on the chip can play. The music data plus the code to play the music fits in the ATtiny2313's code with about 200 bytes to spare.

For the circuit, this time transistors were soldered. The transistors for this circuit are 2N7000 MOSFETs with 1k ohm on the gates. Unfortunately, I tried cutting a corner and left out the pull-down resistors on the gates but it did really funky stuff, so like previous circuit I put 10k ohm resistors from the gate to ground and the problem fixed itself.

Full setup.

Above is the full setup showing the xylophone with solenoids, a Mini-Marshall guitar amp connected to a Boss OD-20 guitar pedal (and behind it a Boss Noise Reducer), an M5Stack MIDI module connected to another Mini-Marshall (for the drums), a circuit board full of transistors to drive the solenoids, and a breadboard containing the ATtiny2313 that plays the song by sending MIDI commands to the MIDI module, and pulses to the solenoids.

Solenoid circuit board

Above is the circuitry for this project. Eight MOSFETs for eight solenoids and the Microchip (Atmel) ATtiny2313 that has the music and firmware stored in its flash memory.

Xylophone and solenoids

Above is a closeup of the solenoids hot-glued to the wooden structure that holds them above the xylophone.

Source code

https://github.com/mikeakohn/small_projects/tree/main/solenoid_music

Copyright 1997-2025 - Michael Kohn