Building a fully analog electronic piano using only resistors, capacitors, and transistors, is an insightful experiment in electronic sound generation from first principles. I designed and built a 13-key analog piano in early 2019 using discrete through-hole components on a breadboard powered off a 9V DC battery. The design creates 13 astable multivibrator oscillator circuits, each able to be tuned to a given note frequency in the C5 to C6 range. The outputs of the oscillators are collected (mixed) to create a polyphonic analog audio signal that is amplified and run through an 8-ohm speaker. The device fits into an 11x25cm footprint. Check out how it sounds! (To hear the explanation of how it works, start at the beginning.)
Feb 9th, 2019, Design V1
The Original (V1) Design
The analog design is based around this basic oscillator circuit (BJT astable multivibrator) that generates a fixed frequency sound based on the values chosen for the two RC circuits (R1, r1, C1, and R2, r2, C2). To get 13 keys, this circuit is duplicated 13 times, once for each key, and the components are selected to generate the 13 semitones of the chromatic scale (C, C#, D, D#, … A#, B, C).
The astable multivibrator circuit works like this: Initially both transistors Q1 and Q2 are switched off so the flows through R1 and R2 cannot go through the transistors. As the flows through R1 and R2 so both capacitors C1 and C2 are charging up via their respective RC circuits. Even when component values are identical for paths 1 and 2 (for symmetry in the oscillation), minor differences in the manufacture of the parts will mean that one of them reaches threshold charge level first. Let’s say, without loss of generality, that C1 charges up first. At this point, C1 switches on transistor Q2. This draws power through R2 into Q2, reducing the charge on the negative plate of C2. This releases charge on the positive plate of C2 which flows to activate Q1
Other references: Ray Marston and you can also read about it in Charles Platt’s excellent Make: Electronics (3rd ed, 2021, pp.X-X). or Hackaday 2011 or Analog Oscillator catalog 2009, see Fig 13 for astable multivibrator.
To simplify parts selection, For each oscillator, we use 2 capacitors, 2 transistors, and 5 resistors, plus a trimpot (5K-10K) for tuning the frequency of the oscillation (pitch of the note).
The sharp sound is because the astable multivibrator oscillator generates a square wave pulse train (on/off) which sounds quite harsh to the ear as it generates all harmonics. A lowpass filter could be added to each oscillator using a 0.1uF or 1uF cap to ground to pull away the highest frequencies. (Adding frequency filtering to alter the tone is on the list of design improvements. Simple oscillator design can produce sine wave vs. multivibrators which produce square or sawtooth waves.)
The neat bit is that because it is entirely analog, all of the oscillations are collected (superposed) via their own 100k-ohm resistor into a single audio output signal, in theory providing up to 13-key polyphony.
Tuning the Piano
Because this is a pure analog design, it will require tuning (see this StackExchange discussion on why).
By playing around with the values of the resistors and caps in the multivibrator oscillator circuits, I was able to preset them to get a coarse tune that is +/- 1 semitone of the correct pitch, with a 5K trimpot in series in each oscillator for fine tuning the pitch (covers approx 2.5 semitones). Manually varying the trimpot tunes the oscillator circuit to one of the 13 frequencies in a musical octave (C5, C#, D, etc. up to C6). The trim pots give 2-5% tuneability to each frequency. It takes a couple of minutes at the start of playing to tune up the 13 oscillators, after which they stay in tune for several hours at a time.
To tune the synthesizer, you can use (from least to most precise):
- A piano that is in tune, and tune by ear.
- Online Tone Generator, any musical note and tune by ear.
- A table of frequencies of each note from C0 (16Hz) to B8 (7.9kHz), and an o’scope to measure the frequency, and tune by measurement.
Improving the Original Design
The original design worked, with a few limitations, addressed in V2 (November 2021).
1. Issue: The keys in the original design are momentary pushbutton tactile switches. While these are fine in many button application, for a piano/synth keyboard that allows playing chords, they are less than ideal: 1/ they are quite clicky when pressing, 2/ they need a fair bit of force to press, 3/ their switching mechanism tends become a bit dodgy after some time. They are also a bit too close together.
Fix: The new design swaps out tactile pushbutton switches for micro limit switches. They’re a bit bigger, but they have nice playability, with a lever arm that pushes down with little finger force. The keys are placed with 2cm spacing between key centers, enough to allow 5 finger playing with one hand. Chords are now easier to play, as well as fast arpeggios. While they are 5x more expensive than pushbuttons (15p vs. 3p ea), they are still cheap enough that the 13-key keypad is less than £2 (vs. 40p).
2. Issue: Voltage stability: in the original design, piano went out of tune as the 9V battery discharged.
Fix: Added voltage regulator to ensure tuning holds even as battery runs down. The new design uses MT3608 boost converter to boost input voltage to a stable 10V power rail (10V can be set by manually adjusting the trimpot on the board). This allows using a full battery (above 9V) or a run-down battery (below 9V). Tuning is now held for the duration of a playing session, and is impacted more by variations in temperature.
Note, a theoretically simpler solution, using a zener diode, won’t work: zener diodes only properly regulate low currents with fixed loads. This is because a polyphonic analog piano by its nature presents a dynamic load: no load with no keys pressed, variable load with all keys pressed, higher load as volume is increased. Note: 10V might be too high, if it exceeds the reverse base-emitter breakdown voltage of the 2N2222 transistors (see Fig 13)
3. Issue: Non-isolated Oscillators. Polyphony (chords) had interference. Tuning was multi-pass.
Fix: The new design replaces the original 10k-ohm audio resistors with 100k-ohm resistors that effectively isolate each oscillator from the audio bus. Additionally, two signal diodes (1N4148) are used to prevent current/voltage from one oscillator reaching the others. The first prevents reverse voltage through the pressed key. The second prevents reverse voltage through the audio bus. This makes each oscillator truly independent from the others. Tuning is now stable, with one pass through sufficient. No interference when playing chords, as the audio signals mix without diffusing on the audio bus.
4. Issue: Tuning required a small screwdriver (not user-friendly) and was not sufficient for the higher notes.
Fix: The new design replaces screwdriver tripots with RV09 PCB potentiometers with built in shafts to allow tuning of each oscillator using fingers. Trimpot value is fixed at 5K-ohm which gives approx 2 semitones of tuneability using standard 1/4 W resistors, with R3 value chosen to put the tuned note within approx the center of the pot range, proving maximum tuneable range. For the 2 highest notes (B5, C6) tuning uses 10k-ohm trimpots to cover the larger frequency gap between adjacent notes as frequency goes higher. The 10k-ohm trimpots cover approx 5 semitones. The cost for the finger adjustable trimpots is about 10x higher (32p vs. 3p ea) but is a much better user experience.
5. Issue: Higher power draw with complicated amplifier.
Fix: The original design had a quiescent power draw of 20mA using 9V battery, so 150mW-200mW consumption, driven by the LM386 amplifier. In the new design, I have replaced the LM386 amplifier with a “LoFi” simplified amplifier design build around a 2N2222 transistor, a pot for volume control, a 0.6W resistor for handling higher power through the speaker. This has reduced quiescent power consumption 6x down to 3.5mA. The change reduces parts count by 8 components.
6. Issue: Polyphony creates unstable line out voltage.
Fix: The new design provides appealing multi-key polyphony, and with the audio signals dropped through 100k-ohm resistor, the signal strength for 1 key press is low (0.3V, 21mA). The problem is that this grows linearly with simultaneous key presses, so a chord of 3 keys is up to 0.9V, 70mA, and is louder than the single key. What we need is an active analog component: a summing amplifier (using op-amp IC741).
Cost / Bill of Materials
The cost for the old version came to £10.30 using breadboards (£3.75). The new version (with more expensive trimpots and keys), comes to £17.20 using a 10x22cm prototype PCB board. Parts costs (excluding boards) were approx 65% of total cost (old version), and about 75% of total (new version).
To build this project requires some equipment (multimeter, test leads, wire stripper, pliers, and a low-cost digital oscilloscope (optional but recommended)) with estimated cost under £30.
Bill of Materials & Costs
13x tactile switches (keys) @ 3p ea = 40p; new version: 13 microlimit switches @ 15p ea = £2
26x 2N2222 transistors (2/key) @ 2p ea = 52p
26x caps (2/key) @ 3p ea = 78p
78x resistors (5/key) @ 0.5p ea = 39p; new version: 65x resistors (6/key) @ 0.5p ea = 33p
new version: 26x 1N4148 signal diodes @ 4p ea = £1
13x 5K (#502) trimmer pots for analog tuning, 3p/pot = 39p, new version: 13x 5k-10k @ 32p ea = £4.16
1x on/off switch = 12p
1x 9V battery with flying leads = 86p (=76p + 8p)
new version: MT3608 boost converter, 45p
1x 8 ohm, 0.2W, 2” Speaker = £1, new version: 1x 8ohm, 1W, 1" speaker = 75p
old version only: [1x LM386 audio amplifier chip DIP-8 = 10p]
old version only: [3 caps amplifier/filtering caps @ 3p ea = 9p]
new version only: 1x 2N2222 transistor as amplifier = 2p
new version only: 1x IC741 op-amp = 35p
1x B10K potentiometer (volume control) = 75p
1x red LED + 2.2k resistor = 15p
1m hookup wire, three colors = 35p
SubTotal = old version = £6.56 parts, new version = £12.60 parts
Build substrate:
Old version:
2 880-tie point breadboards = £1.28/board = £2.56
1 440-tie point breadboard = £1.19
Subtotal £3.75
New version:
£4.60 10x22cm PCB board double-sided, FR-4
Total = old version = £10.30, new version = £17.20
Reflections
There are ways around the above tuning challenges, including more elegant tuning methods or incorporating digital elements into the design e.g. using a crystal oscillator and digital divider to obtain a close-enough frequency. Whether your ear can tell the difference or not is a personal preference.
- use 555 analog timing chips, which essentially are packaged BJT multivibrators, with additional analog magic to maintain their frequencies through the kinds of variations that throw individual components out of tune.
- use crystal oscillator and digital counter/divider to generate square waves with approximate (fixed) frequencies
- use a microcontroller to generate the frequencies using its onboard oscillators and counters
In hindsight, this is a similar design to the Poly555 by Oskitone where the oscillations are driven using 20 independent 555 timer IC chips to produce a 20-tone polyphonic keyboard. Note that the Poly555 also requires tuning the tones via pots. Do the 555 timers reduce complexity? Not really. Our design uses 12 discrete components per oscillation. The 555 chip uses 25 transistors internally, an example of medium scale integration (MSI) and requires a few external resistors and caps to set the oscillation frequency. What they may do however (not tested) is preserve tuning for longer, with the oscillators largely contained with the chip die, smaller, and less susceptible to differences in ambient. Would be a good experiment if one wishes to build another version.
Closing Thoughts
Purely analog electronic music is certainly possible on a DIY budget. Using the astable multivibrator oscillator one can generate in quite a simple fashion a working 13-key analog keyboard, on budget of under £16. The analog approach requires tune, and how this is done and how stable, is an interesting part of the design.
Appendix: quick primer on the theory of music tunings
Added Nov 12th, 2021
When discussing the tuning of an analog instrument (guitar, piano, the above 13-key device), tuning by ear inevitably leads to a discussing about why we tune the way we do, and whether there are alternatives to the standard equal temperament tuning. (With digital instruments, if you wrote the code, or the instrument allows you to set the tuning, it is even easier to change, but this is the exception.)
Here’s a 5 minute run through of temperament, or tuning theory:
Pick a note, say A4 (the A above middle C, called C4). In Western music, the convention is that A4 is 440Hz (concert pitch). Octaves since Greek times are double ratio, so A5=880Hz, A3=220Hz. Octaves define your interval. By convention in Western music, there are 12 semitones in an octave: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. It doesn’t have to be that way, and in various other music cultures there are 17 tones in an octave, or 24 (called quartertones). Because octaves are defined by doubling, the natural way to define 12 equally spaced intervals (notes) is logarithmically. Hence you get as the multiplier 1.0595 (to four places) = 2^(1/12), or the 12th root of the double ratio. Let’s check: A4 is 440Hz, and if you multiply repeatedly by 1.0595, you get the frequency for the other 12 notes in the fourth octave. On your 13th step you get to A5=880Hz, the octave higher (try it, you should get 880.36792, because we’ve round up the multiplier in the fourth decimal). There’s probably a lot more to it than this, but in a paragraph, that would be my summary.
For a historical look at tunings, and an explanation of why modern “equal temperament” tuning was not what Bach historically used for his famous “Well Tempered Clavier” piece, plus the intricacies of what makes music sound good, see this well-written online article, An Introduction to Historical Tunings, (1997) by Kyle Gann, music professor at Bard, Bucknell, and Columbia ( https://www.kylegann.com/histune.html )
There’s an interesting discussion at Hackaday on a device for helping tune pianos.
Happy prototyping!
Feel free to share your comments, creations, or questions.
Related Reading
- Electronics in the Junior School – Gateway to Technology
- Gallery of projects for interested adults and/or explorations with children (up to teens)
- MathSciTech Electronics Parts Supply List (UK focus) to jump into Electronics yourself.
- Note Generation vs. Sound Synthesis (MIT)
- Drawing sensible schematics
- Analog Circuits, Kent Lundberg (MIT)
- Polyphony in Synths and Instruments
Leave a Reply