The default 4 MHz clock
speed for the microcontroller is
more than adequate for measuring
audible frequencies. By using a
table of the established
frequencies for musical notes, the
result held in the W0 variable can
be used to initiate some event
such as lighting a designated LED
or group of LEDs. We can use a
list of the frequencies that make
up the chromatic scale for any
octave, such as the example
shown in Table 1 used for the
fourth octave scale. Using this list
and with the help of a tone
generator, you can compile an
inventory of the translated
numbers for each octave. For the
list in Table 1, the translation would look something similar
to this:
Note Frequency (Hz)
C4 261.63
C#4/Db4 277.18
D4 293.66
D#4/Eb4 311.13
E4 329.63
F4 349.23
F#4/Gb4 369.99
G4 392.00
G#4/Ab4 415.30
A4 440.00
A#4/Bb4 466.16
B4 493.88
■ FIGURE 8. Example of the frequency
translation process.
Table 1. Frequencies of notes
for the 4th Octave.
has translated values. You may want to double-check the
calibration, especially if you make any modifications to the
supplied schematics. The PULSIN frequency measurement
command requires only three arguments which are the
port or Pin# for the input, the State from which to
measure from, and the Variable used to hold the value for
the frequency. This command measures the length of a
pulse on the input pin. Depending on the State variable, it
either measures from the rising edge of the input or falling
edge indicated by declaring a 0 or 1 value on the
command line. The measured result is placed in the
variable of choice. For example:
C4 = 261 Hertz Translated value = 17
(beginning of the 4th Octave)
B4 = 493 Hertz Translated value = 37
(end of the 4th Octave)
PULSIN C.6, 1, W0
; measure the low to high transitions on C.6
; & stores in W0
To light an LED or group of LEDs with a specific
wavelength that includes a range of frequencies, you only
need to provide a conditional IF/THEN statement for the
range desired. The following is a code fragment that
would cause the grouping of four yellow LEDs shown in
the schematic to light if the sampled input frequency was
between 260 and 493 Hz:
EXAMPLE DISCRIMINATION FOR THE 4TH OCTAVE :
ITEM QTY DESCRIPTION SOURCE/PART#
BRD1 1 Proto Board Digi-Key V2009-ND
BRD1 1 Proto Board Digi-Key V2025-ND
If W0 > 16 and W0 < 38 THEN
; any notes between 260Hz
; to 494Hz
SCKT1 1 20 Pin Socket Digi-Key A106188-ND
SCKT2 2 18 Pin Socket Digi-Key ED3019-ND
IC2, 3 2 ULN2803 Digi-Key ULN2803APG(ONHZA-ND)
J1, 2 2 3.5mm Audio Digi-Key CP1-3543-ND
HIGH Y_UL,Y_UR,Y_LL,Y_LR : PAUSE
DELAY:LOW Y_UL,Y_UR,Y_LL,Y_LR
; light these 4 LEDS
Z1 1 2.7V Zener Diode Digi-Key 1N5223B-ND
C2 2.01 µF Capacitor Digi-Key P4525TB-ND
R1 1 10K 1/4W Resistor Digi-Key A105970CT-ND
R2 1 22K 1/4W Resistor Digi-Key 22KAACT-ND
R3 1 100 Ohm Resistor Digi-Key 10QBK-ND
R4 1 10 Ohm Resistor Digi-Key 100DSCT-ND
SP 4 1/2” Standoffs Digi-Key 3480K-ND
PH 8 4-40 Screws Digi-Key 335-1082-ND
D1-8 8 Green LED Digi-Key C4SMF-GJS-CV0Y0792TB-ND
D9-14 6 Blue LED Digi-Key C503B-BCS-CV0Z0461-ND
D15-18 4 Yellow LED Digi-Key 897-1071-ND
This IF/THEN statement lights the
four LEDs connected to ports B.0-B. 3 if
any notes within the fourth octave are
sampled. You can go even further to
enhance the effect of the translation of
sound to light by carving up the octave
into several patterns of yellow lighting.
D19-22 4 Pink LED Digi-Key 67-2062-ND
D23 1 Red LED Digi-Key C503B-RBN-CW0Z0AA1-ND
HDR1 1 40 Pin Male SIP SparkFun PRT-00116
We can accomplish this by lighting the
upper left (Y_UL) and lower right (Y_LR)
HDR2 1 40 Pin Female SIP SparkFun PRT-00115
IC1 1 PICAXE 20M2 SparkFun COM-10807
BATT 1 4AAA Batt Holder RadioShack Cat# 270-411
HLDR 1 Document Holder Office Max SKU# 309264
MISC Shielded 2 conductor wires for audio connection.
LED if it is the lowest part of the octave,
and upper right and lower left LED if it is
the highest frequency part.
By reserving just the center part of
38 November 2013