A piano robot is an embedded electromechanical system that uses microcontrollers to drive an array of solenoids or stepper motors, physically depressing acoustic piano keys to reproduce digital MIDI sequences or algorithmic compositions. What this changes in a real circuit is the transformation of a standard passive acoustic instrument into a high-precision, high-current MIDI-controlled output device, demanding rigorous management of inductive kickback, PWM timing, and localized power distribution. People commonly confuse a piano robot with digital synthesizers (which generate sound electronically via oscillators) or simple MIDI controllers (which only send digital data and lack the physical actuators required to strike a string).

The Physics and Electronics of Striking a Key

To build a reliable piano robot, you must understand the electromechanical reality of the solenoid. A solenoid is an inductive load. When you apply voltage, the current ramps up based on the coil's inductance and resistance. The physical force generated is proportional to the square of the current and inversely proportional to the air gap between the plunger and the stop. This means the solenoid needs a massive burst of current to pull the plunger across the initial large air gap (the 'strike'), but requires significantly less current to hold the plunger against the stop (the 'hold').

Bench Rule: If you apply continuous 12V to a 12V-rated solenoid to hold a key down during a long sustained note, the coil will overheat, melt its internal insulation, and short out within minutes. You must use PWM to drop the average voltage after the initial strike.

Let us look at a worked numeric example for a full 88-key keyboard conversion. Assume you are using 12V DC push-type solenoids rated for 2.5A peak strike current and 0.5A hold current. If a complex glissando or heavy chord triggers 20 keys simultaneously, your instantaneous peak current demand is 50A (20 x 2.5A). If you naively size your main power bus for the absolute worst-case scenario of all 88 keys striking at once, you would need to handle 220A, requiring massive 2/0 AWG battery cables. Instead, we use a staggered-strike software approach and local decoupling capacitors. We size the main 12V feeder bus at 6 AWG (rated for ~65A continuous) to handle realistic musical peaks, and distribute power via 14 AWG local sub-buses to groups of 12 keys, relying on local 2200µF electrolytic capacitors to supply the microsecond-level peak current spikes without sagging the main rail.

Where You Meet This in Practice

You will encounter piano robot architectures in interactive art installations, automated accompaniment systems for live vocalists, and accessibility projects for musicians with limited mobility. The commercial equivalent is the Yamaha Disklavier, but the DIY and embedded maker space relies heavily on the ESP32 microcontroller due to its dual-core processing and native wireless capabilities.

In modern builds, the ESP32 receives note data via the MIDI Association's BLE-MIDI specification over Bluetooth Low Energy, or via traditional 5-pin DIN opto-isolated UART. Because the ESP32 only has a limited number of hardware PWM pins, driving 88 individual solenoids requires multiplexing or dedicated constant-current sink drivers. The TLC5940 16-channel PWM LED driver is a staple here. While designed for LEDs, the TLC5940 can sink up to 120mA per channel. To drive our 2.5A solenoids, the TLC5940 outputs are fed into the gates of logic-level N-channel MOSFETs (like the IRLZ44N), which handle the heavy 12V switching. This offloads the high-frequency PWM generation from the ESP32's CPU to the TLC5940's internal grayscale timers, ensuring perfectly timed note velocities without CPU jitter.

Real-World Scenario Walkthrough: The 12-Key Chord Brownout

Theory is clean; the workbench is not. Here is a real-world scenario from a 12-key prototype marimba/piano robot build that highlights the dangers of inductive loads.

  • Setup: 12x 12V 1.5A solenoids driven by an ESP32 DevKit v1 and a bank of IRLZ44N MOSFETs. Power was supplied by a standard 12V 10A switching bench supply. Logic and solenoid power shared a common ground breadboard bus.
  • Numbers: Striking a 4-note chord simultaneously demanded an instantaneous 6A current spike. The 22 AWG jumper wires connecting the power supply to the breadboard had roughly 0.1 ohms of total resistance and high parasitic inductance.
  • Outcome: When the chord triggered, the ESP32 immediately threw a brownout detect and reset. The MIDI connection dropped, and the remaining notes in the sequence played as chaotic stutters.
  • What went wrong: Two things. First, the 6A spike across the thin jumper wires caused a momentary voltage sag (V = IR) that dropped the 12V rail down to 7V, which in turn caused the onboard AMS1117 3.3V regulator on the ESP32 to drop out of regulation, triggering a brownout reset. Second, when the MOSFETs turned off, the collapsing magnetic fields in the solenoids generated massive inductive voltage spikes (kickback). Without flyback diodes, this >50V spike coupled through the shared ground impedance into the ESP32's 3.3V logic rail, corrupting memory.

The fix required a strict separation of power and proper flyback protection, executed in the following sequence:

  1. Solder 1N5819 Schottky flyback diodes in reverse parallel across every single solenoid coil to clamp the inductive kickback to ~0.3V above the supply rail.
  2. Run a dedicated, heavy-gauge (12 AWG) ground wire directly from the power supply negative terminal to the solenoid ground bus, completely bypassing the ESP32's logic ground path.
  3. Connect the ESP32 logic ground to the solenoid ground at exactly one single point (star grounding) to prevent ground loops.
  4. Add a 1000µF low-ESR electrolytic capacitor and a 0.1µF ceramic capacitor across the 12V and GND rails at the MOSFET bank to act as a local energy reservoir for chord strikes.

Common Confusions and Pitfalls

When designing the actuator layer of a piano robot, builders frequently fall into a few specific traps that degrade performance or destroy hardware.

Relays vs. MOSFETs: Beginners often reach for standard 5V mechanical relays to switch the 12V solenoids. This is a critical mistake. Mechanical relays have bounce, slow actuation times (often >10ms), and limited mechanical lifespans. A piano staccato note requires a strike and release in under 30ms. Relays will physically fail to keep up with fast trills and will burn out their contacts from arcing. Always use logic-level MOSFETs or dedicated solenoid driver ICs.

Velocity Mapping: In a digital synthesizer, MIDI velocity (0-127) simply scales the audio amplitude. In a piano robot, MIDI velocity must be mapped to the physical dwell time of the solenoid's strike pulse. A velocity of 127 might require a 25ms full-voltage PWM pulse before dropping to the hold duty cycle, while a velocity of 20 might only require an 8ms pulse. If you do not calibrate this mapping empirically with a microphone and an oscilloscope, your robot will sound like a typewriter rather than a musical instrument. Adafruit's MIDI for Makers guide provides excellent foundational logic for parsing these MIDI bytes in embedded environments.

Material Warning: Never use standard PLA 3D printed filament for the physical push-rods that connect the solenoid plunger to the piano key. The repeated mechanical impact and friction will deform and melt PLA over time. Use PETG, ABS, or preferably, brass or Delrin (acetal) rods for the actuator linkages.

FAQ: Building Your Own Piano Robot

Can I power a piano robot with a standard 12V PC power supply?

Yes, but with caveats. An ATX power supply's 12V rail can often deliver 20A to 40A, which is excellent for a 24-to-48 key subset. However, ATX supplies require a minimum load to regulate properly and can shut down if they detect the massive, sudden current spikes of a chord strike as a short circuit. You must add a large bulk capacitor bank (e.g., 10,000µF total) on the 12V output to smooth the transient draw and prevent the ATX supply's over-current protection (OCP) from tripping.

How do I prevent the solenoids from buzzing loudly when holding a key?

Solenoid buzz is caused by the PWM frequency being too low, allowing the plunger to physically vibrate against the stop. If your hold PWM is running at 100Hz or 500Hz, you will hear an audible hum. Push your PWM frequency to at least 1kHz to 4kHz. The inductance of the coil will smooth out the current ripple at higher frequencies, resulting in a silent, firm hold.

Do I need optical isolation for the MIDI input?

Absolutely. The MIDI specification inherently requires an opto-isolator (like the 6N138 or PC900) on the receiving UART RX line. Because a piano robot involves massive inductive loads switching on and off, electrical noise will easily travel through ground loops if you connect a synthesizer's MIDI out directly to your ESP32's GPIO pins without optical isolation. This will result in phantom notes and corrupted serial data.