Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Hack 555 Toy Piano for

Better Sound Quality


recalculate the resistor values

circuit4u

Nov 16, 2019·5 min read

There are many cheap DIY 555 timer soldering kits on eBay
(for example search: NE555 piano), which can generate sounds
at different frequencies, with 8 push-buttons.

They are sold as toy pianos. But the piano notes are way off. So
don’t expect to play any piece of music on these toys, unless
you are willing to do some hacking.

Fortunately this one on eBay comes with its schematic


This is a typical 555 astable oscillator circuit that outputs
square waveform to drive a speaker. As one of the keys from S1
to S8 is pressed, the C2 and different resistor path determine
the RC time constant that sets the frequency of the square
waveform.
The circuit is configured such that from right to left,
subsequent key press (from S8 down to S1) adds additional
resistor into the RC time constant, thus longer the period =
lower the frequency, just like a piano keyboard does.

One reason that it doesn’t sound like a piano is because the


frequency of the notes are way off. However we can “re-tune”
the piano by replacing these resistors with the correct values.

Scale on the Piano


Here is a very nice introduction about the scale (i.e.
frequencies) on a piano keyboard

So the key (pun-intended) is to generate these frequencies with


the steps: 2 2 1 2 2 2 1, out of the 2^ n/12 power
[ scale =: +/\ 0 2 2 1 2 2 2 1
[ freq_factor =: 2^ scale % 121 1.12246 1.25992 1.33484 1.49831
1.68179 1.88775 2

These are the multipliers in front of a major frequency, to get


all the notes in a scale. For example, C major scale, the major
frequency is 130.813Hz
freq_factor * 130.813130.813 146.833 164.814 174.614 195.998
220 246.942 261.626

It starts from 130.813Hz and after 8 notes reaches 261.626Hz


(Middle C), that is twice the frequency. In “fancy” music term
262Hz is one octave higher than 131Hz. (EE engineers who use
log-log scales in frequency response plots should be familiar
with these terms.)

(For details: Piano Major Scales and Frequencies)

Similarly armed with these frequency factors, you can walk up,
as well as walk down one octave, say from 698.456Hz (F5 on
piano keyboard) to get all the notes in a scale.
[ ff =: 698.456 % freq_factor NB.go down scale from F5698.456
622.254 554.365 523.251 466.163 415.304 369.994 349.228

It’s not a Major scale, but you can play music with notes of
these frequencies as well. (one octave higher than F Major, if
your piano teacher asks)

Calculate RC Time Constant for 555 Toy


Piano
Why pick 698.456Hz you ask?

It seems that is the highest (right most) frequency of that eBay


toy piano. You can certainly tune the 555 to Major C or other
piano scale. (I attached J-lang code and an example at the end
of this article)

Now let’s come back to our 555 toy piano. We’d like to show
that we can do better than the engineer who designed that $3
eBay toy piano.
For example to generate 698.456Hz, with the existing CAP.=
100nF, R5 =
[ r5 =: (% 698.456 * 1.4 * 100e_9)10226.6

We omit the R1 in the schematic, because it is relatively small


comparing to R5 =10 kΩ (1/2*R1 = 500 Ω).

Two important engineering lessons:

 make approximation first to ease the math, but then


verify that the result validates the assumptions for
the approximation.

 resistors don’t come with arbitrary values. They


follow an exponential scale (just like our music
notes). (standard resistor values). You can certainly
put multiple resistor in series to have more accuracy
of the RC time constant. But we are making a $3 kit
on eBay, let’s put our engineer hat on.

So the toy piano’s R5 is exactly 10kΩ, kudos to the engineer.

But the accuracy goes downhill from there, as we look at R2,


R9, R8, ….

For subsequent notes, the resistors adds onto the RC time


constant of the previous one, so the frequencies go lower and
lower. We need to calculate the Δt, then the add-on (next)
resistor
[ dT =: - 2 (-/) \ % ff NB. time difference0.000175333
0.000196804 0.000107263 0.000234041 0.000262702 0.000294873
0.000160714[ rs =: dT % 1.4 * 100e_91252.38 1405.74 766.168
1671.72 1876.44 2106.24 1147.95[ rr =: r5 , rs NB. ideal10226.6
1252.38 1405.74 766.168 1671.72 1876.44 2106.24 1147.95

So from the calculated values of ideal resistors, we pick values


from E12 standard resistors
[ rr2 =: 10e3 1.2e3 1.5e3 820 1.5e3 1.8e3 2.2e3 1.2e3 NB.
redesigned10000 1200 1500 820 1500 1800 2200 1200

These are resistor values for R5, R2, R9, R8, R7, R6, R4, R3,
obviously very different from the majority 2kΩ in the original
schematic.

Here is the comparison of frequencies generated, our redesign


and the original $3 toy.
frequencies of notes

The red line shows the exact frequencies of a perfectly tuned


piano notes. Green line is our re-tuned toy piano. (Because our
resistors lean towards the smaller side, the frequencies are
higher.)

The blue line is the original $3 design. You don’t want your
piano teacher to hear the sound of that.

In addition, here is the resistor values to re-tune for C-Major


scale, if you’d like to try it. I picked values from E24 standard.

R5=27k, R2=3.3k, R9=3.6k, R8=2k, R7=4.3k, R6=1k,


R4=5.6k, R3=3.0k
It is not a two-thousand dollar digital piano. But for $3+, we
are getting pretty close.

And here is the J-lang code to calculate these resistors


WRITTEN BY

circuit4u

Follow

 Music

 555 Timer

 Digitalpiano

More from circuit4u


Follow

Nov 13, 2019

Light NeoPixel with 555 Timer IC


(Part II)
Look ma, only one resistor
To continue the discussion from Part I, the design goal is to
generate BIT-1 for NeoPixel with 555 IC.

The following is another 555 astable circuit uses only one pair
of RC, and it outputs equal high time and low time.

It can be analyzed using that RC step response equation (see


Part I of this article).
Read more · 5 min read
3

Nov 12, 2019

Light NeoPixel with 555 Timer IC


(Part I)
Look ma, no MCU

NeoPixels (Adafruit’s comprehensive introduction) are 24-bit


RGB-colored (GRB to be exact) LEDs, which can be strung
together and controlled with 1-wire serial digital signal.

Considering how stringent the timing of the digital signals are


(according to WS2812B datasheet), it’s pretty amazing that
Julian (his youtube video) was able to light up NeoPixels with
a single 555 timer IC, without any help from MCUs.

With today’s ultra-high transistor counts electronics


components, small MCU ICs are cheaper, lower energy and
much more powerful than a good old 555 timer IC.
Nonetheless, it is an interesting electrical engineering design
problem to solve.
In this article, I am going to explain how to calculate RC
component values and how to generate pulse width
modulation (PWM) signals for NeoPixel’s 1-wire data protocol,
again only using 555 timer IC. …
Read more · 4 min read

Nov 10, 2019

Coding Consistent Overhead Byte


Stuffing (COBS) for packet data
How Wikipedia could get it wrong for embedded systems
HDLC introduced a common byte stuffing method (with 0x7D,
0x7E), until the advent of clever COBS. There are plenty of
reference material: Wikipedia page and the original paper,
even with C source code to get you familiar with the method.

It is a very useful technique to learn for embedded system,


since anecdotally 10% of any hardware engineer’s time is spent
(wasted) struggling with serial port communication, for each
project.

Yes, embedded systems are still using serial port today (year
2019).

The basic idea of COBS is to keep a running pointer (relative to


the previous “0” position) of “0” occurrences, which replaces
the original “0”s in a byte stream. Thus, “0” can be used to
mark the end of the stream, in a protocol. …
Read more · 4 min read

Published in The Startup

·Nov 2, 2019
Generate Combinations on
Rosetta Code
Python and J-lang code

Rosetta code, deriving its name from the famous ancient


Rosetta stone, is a website that collects code snippets solving
simple computer problems. For every computer problem,
solutions from different computer languages are listed side-by-
side for comparison. In that sense, it is the Rosetta stone of
computer languages, which totals way more than three.

The other day, I was trying to find from there, some


code/algorithm to generate combinations of a list of items,
i.e. Rosetta code: combinations

No surprise, some math oriented languages have built-in or


library functions that give the answers directly.

For example, according to Rosetta code, such a function is


called nchoosek((0:4),3) in
MATLAB, combinations(0:4,3) in
Julia, Subsets[Rang[5], {3}] in Mathematica. …
Read more in The Startup · 4 min read
51

Dec 17, 2018

Play 24-point game with J


language
fast prototyping a math card game with a powerful
“vocabulary”

24-point is a math game played with a deck of regular playing


cards. Once presented with 4 cards, players try to come up
with a formula to reach 24, using 4 numbers and simple
arithmetic, fastest one wins.

Here is all the possible 4-numbers out of 52 cards and the


solutions (link).

For example, the 4 cards drawn are: 2, 4, 5, 8. Possible


solutions are:
4 * 5 + 8 - 2
8 * (5 - 4 + 2)
8 * (2 * 4 - 5)
4 * (8 - 5) * 2
8 * 5 / 2 +…

You might also like