↖️ Blog Archive

Self-Playing Piano, Part Six

Bradley Gannon

2025-12-26

TL;DR: I made a semi-automatic coil winding machine. It substantially reduces the effort and physical pain associated with winding the coils by hand, which I’d been doing until now. The machine uses a stepper motor and an Arduino Nano to turn the coil at a consistent rate and stop at the desired number of turns. In addition to being slightly faster than hand-winding, the quality of the coils is generally better, and I can go for longer because my hands don’t get as tired.

Note that I took this video when I was still using full steps instead of quarter steps. The current system is quieter.
A small square circuit board with an Arduino Nano, a stepper driver, some buttons, and some off-board connectors sits on a workbench The stepper motor and shaft adapter sit idle, waiting for the next solenoid to be attached

There are 88 keys on a piano, which means I need 88 solenoids. So far, I’ve wound all solenoids by hand, which is simple enough but takes more concentration and hand strength than you might expect. I can typically wind about three coils in one hour, after which my hands are too tired to continue. I can’t listen to anything or really do anything else at all except for carefully wrapping wire around the solenoid core and counting the turns. I tend to lose count, so I started making tally marks on scraps of paper every ten turns to try to avoid getting lost. Overall, it’s desperately boring.

This was okay for small-scale testing, but now that I’m ready to expand my design it’s not going to cut it. I had a feeling that even just a little bit of tooling in this area could substantially improve the ergonomics and quality of the process, and this turned out to be right. My goal wasn’t to make a fully automated winding machine but merely to take the stress off my hands and let the machine keep count for me. Then I could zone out and listen to a podcast while feeding wire on for a lot longer before getting tired.

A stepper motor is ideal for this task. Unlike a typical electric motor, which converts electric current into torque with open-loop control, a stepper motor allows for precise angular motion in discrete increments or “steps”. A microcontroller can send logic level pulses to a driver chip that applies current to the motor phases in a particular order to rotate the shaft one step at a time. The NEMA 17 stepper motor is common among hobbyists and has good support, so I picked up a few from Digi-Key along with some A4988 driver boards.

Then I created CAD models for a motor mount and a shaft adapter. The motor has a standard mounting interface, and its shaft is a smooth rod with a flat portion on one side. The mount attaches with M3 screws, and the shaft adapter is a press fit on one end and uses yet more M3 screws to attach to the solenoid support on the other end. I printed these up and attached the motor. I did have to reprint the shaft adapter to dial in the press fit tolerances, but fortunately this was a quick iteration loop that didn’t waste much material. I intended to attach everything to a block of wood, including the large spool of magnet wire from which I’ve been winding this whole time, but it was easier to clamp the motor mount to my workbench and set up the wire spool on the floor.

With the mechanical work done, I moved on to the electrical. The circuit isn’t too fancy. 12 VDC comes from a power supply I already had on hand and powers an Arduino Nano and the A4988 stepper driver. The Nano is a 5 V device but has a linear regulator onboard that tolerates 12 V. Dropping 7 V across a tiny SMD linear isn’t ideal, but the Nano doesn’t need much current, so it seems to be alright thermally. I connected all logic inputs on the A4988 to the Nano’s digital pins. Even though I don’t really need software control over all of these inputs, I figured it would be better to make them available just in case. The A4988 has two phase ports, which I ran into female JST connectors. For direction and speed control, I connected two pushbuttons to pull-up inputs on the Nano. These allow me to change speed and direction by using the buttons as “up/down” inputs. This design came together relatively quickly and was easy to cut on the CNC using the process I’ve described before. I used pretty wide tolerances and the board came out great. After soldering the board and connectorizing the motor’s phase wires, I was ready to go. I used female headers for the Nano and the A4988 so I can pop them off and use them for other projects if I want to later.

Last came the software. I wrote a Rust program that maintains a state struct and modifies it according to button presses. I ended up writing a button debouncer, which was a nice exercise, and then it was a matter of setting up the right logic and sending pulses at the right times and speeds. The code knows that there are 800 steps per turn (using quarter stepping on the A4988), and it knows that I want 280 turns, so it keeps count and stops when it’s finished. Then I can swap in another solenoid support, hit reset, and start again. There are two speed settings for each of the two directions, which lets me go fast (1 turn per second) when the wire is being fed on in the middle of the solenoid and slow (0.25 turns per second) when I need more precision at the edges.

Thirteen solenoids with red wire wrapped around black PLA support structures sit haphazardly on a white table
I made eight of these solenoids in less time than it took me to make the other five, and with higher quality and less hand strain.

The system works well. I can comfortably make four or five solenoids per hour now, and it takes much less strength and concentration, so I can do it for longer without fatigue. As long as I keep a little tension on the wire, I can nudge it to feed it onto the solenoid precisely and back up when I make a mistake. This has resulted in even tighter windings than before and generally higher quality. I made eight solenoids in about 105 minutes across two days, so I’m confident that I can use this tool to do the remaining winding for the project without too much trouble. It’s still a decent amount of work, but it’s a big improvement and seems much more manageable.

The motor does get hot after a few minutes, but I set the current limit on the A4988 to 1 A, so the temperature reaches a safe equilibrium. This has resulted in some warping of the PLA mount, but in the worst case I’ll just print another one, maybe with some beefier walls. I had also initially used full motor steps, but this was loud and caused enough vibration to loosen some nuts holding the thing together. I slipped a sheet of plastic foam under the mount to reduce its coupling to the table and switched to quarter steps in the motor driver to smooth out its motion.