Using a Solenoid for Percussion on a Ukulele




About: I am an American teaching English at Shangluo University, Shaanxi. I like making machines that do interesting but fairly useless things - I call them Quixotic Machines.

This project is about adding a solenoid to the top of a ukulele to produce percussive effects like drums or even tap dancing. It is a great project if you like ukulele or guitar, Arduino Uno coding, and simple transistor circuits.

I very quickly programmed just a couple of rhythms for the solenoid but the possibilities are probably endless.

The sounds of the solenoid drumming can be picked up by the ukulele bridge microphone but also are picked up by just a standard microphone (I use a Blue Snowball iCE USB mike that is wonderful).

This also makes for a nice metronome and you can soften the sound by putting some self-adhering foam where the solenoid shaft hits the ukulele. Really helps me smooth out my timing when I play.

Check out the video for a couple of demo ditties.

Step 1: Make the Transistor Circuit to Drive the Solenoid

Probably the first thing to build is the simple circuit to provide voltage to the solenoid. I used the circuit from this website:

I hand-drew the circuit shown in the picture. I use an IRF740 MOSFET but probably just about any MOSFET will work that can be triggered on and off by 5 volts provided by the Arduino UNO. Probably any diode will work too. I use a 10k potentiometer to control the rhythm timing and speed.

I would wire the circuit up with jumpers on a breadboard to be sure the circuit works before you solder it up.

Step 2: Mount Solenoid on Ukulele or Guitar

This is where we may part company. My ukulele is a beater so I have no problems drilling holes in it and hotgluing stuff to it - I have a nice Merida ukulele that I would not do that to. So you have to figure out how you want to mount the solenoid. I mounted mine to an L bracket I made out of 3mm plywood and then hotglued it to the face of the ukulele. You could also bolt it the uke but I can't think of any temporary or less damaging ways to mount it. It can also be mounted inside the uke for a nice clean look but I like to see it moving on the outside.

Your choice.

Step 3: Arduino Code

Here is the code. I filter the potentiometer by reading it 10 times to get a consistent value.

You can use analogWrite or digitalWrite, either one to make the solenoid move. analogWrite(0) is equivalent to digitalWrite(LOW) and analogWrite(255) is equivalent to digitalWrite(HIGH).

#include Servo.h

// ukedrum code jdemello nov 2017

int potPin = 1; // analog pin used to connect the potentiometer

int val; // variable to read the value from the analog pin

int potVal;

int solenoidPin = 2;

int solenoidAnalogPin = 9;

int filterAverage(int measurementsToAverage,int pinNumber) {

int avgSensor;

for (int i = 0; i < measurementsToAverage; ++i)


avgSensor += analogRead(pinNumber);

// delay(1);



avgSensor /= measurementsToAverage;

return avgSensor;

} // end functionZf

void doThreeQuarterDrum() {

/* digitalWrite(solenoidPin, HIGH);

digitalWrite(13, HIGH);


digitalWrite(solenoidPin, LOW);

digitalWrite(13, LOW);


digitalWrite(solenoidPin, HIGH);

digitalWrite(13, HIGH);


digitalWrite(solenoidPin, LOW);

digitalWrite(13, LOW);



analogWrite(solenoidAnalogPin, 255);

delay(potVal * 20);

analogWrite(solenoidAnalogPin, 0);

delay(potVal * 20);

analogWrite(solenoidAnalogPin, 255);

delay(potVal * 40);

analogWrite(solenoidAnalogPin, 0);

delay(potVal * 40 );


void doFourFourDrum() {

analogWrite(solenoidAnalogPin, 255);

delay(potVal * 2);

analogWrite(solenoidAnalogPin, 0);

delay(potVal * 2);

analogWrite(solenoidAnalogPin, 255);

delay(potVal * 2);

analogWrite(solenoidAnalogPin, 0);

delay(potVal * 2);


void setup()



pinMode(solenoidPin, OUTPUT);

pinMode(13, OUTPUT);

pinMode(solenoidAnalogPin, OUTPUT);


void loop() {

potVal = filterAverage(10,potPin);

potVal = map(potVal, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)

Serial.print(" potval : ");Serial.println(potVal);

if (potVal < 5) {analogWrite(solenoidAnalogPin, 00);

delay(200); }

if (potVal > 5 && potVal < 80) {

doThreeQuarterDrum(); }

if (potVal > 90 && potVal < 180) {

doFourFourDrum(); }




    • Trash to Treasure

      Trash to Treasure
    • Tape Contest

      Tape Contest
    • Arduino Contest 2019

      Arduino Contest 2019

    2 Discussions

    Thank you. It was an easy, fun little project that I will probably keep around as I like to perform now and again for the students here at the university. Might look into mounting a second solenoid to get some more intricate rhythms.