Page 1 of 1
Random Music Box
From MAKE Magazine
This project first appeared on the pages of MAKE magazine.
Microprocessor organ and servo drum play an endless song.
- Author: Kevin Weekly
- Difficulty: Moderate
Here’s a fairly inexpensive ($30–$40) project that uses a microprocessor to generate a constant stream of random but pleasant-sounding music. A Microchip PIC16F685 generates 5 square waves that are amplified and combined to play on a small speaker. A lookup table in the software stores chord progressions common in Western music. As the music runs from chord to chord, 3 oscillators play the chord itself, 1 plays a tonic-dominant (1-5) bass pattern, and 1 plays random notes from the underlying scale as a melody. Potentiometers adjust how much of each component (chord, bass, and melody) is mixed into the final output. To keep the beat, the microcontroller also generates output for driving a servomotor to strike a drum or equivalent.
Sections
Tools
Relevant parts
- PIC16F685 microprocessor, 20-pin DIP $3

- Op-amp chip, OPA4342, 14-pin DIP or use another quad op-amp, like the cheaper LM324
- Capacitor, 20nF, 10µF, 1µF, 100µF
- Potentiometer (3), 50kΩ or other value All 3 must be identical

- Resistor (6), 4.7kΩ, 10kΩ

- Speaker, 8Ω, small

Relevant parts (continued)
- Male header, 3-pin, 0.1" spacing
- DIP socket, 14-pin, 20-pin
- Hook-up wire

- Breadboard (2) or ProtoBoard

- Power supply, 5V I used a 4xAA battery pack with a voltage regulator.
- Masking tape
- Drum and drumstick or equivalent. For one version, I used a metal rod and a cardboard box.
- Servo Other servos would probably work, but they must handle PWM (pulse width modulation) input. # I tried an HS-325HB and it did nothing but twitch.

- View:
- Paginated
- Full width

Edit Step 1
— Assemble the circuit.
¶
Download the project schematic at http://www.makezine.com/17/diymusic_rand....
You can solder it onto protoboard or put it together temporarily on a solderless breadboard. I placed and connected the components in this order: sockets, resistors, capacitors, power wires, signal wires, potentiometers, and finally the off-board connections to the speaker and servo. The web page has sketches showing each step.

Edit Step 3
— Verification
¶
Before inserting the ICs into the sockets and powering on, it’s important to make some sanity checks, to avoid destroying the expensive ICs. First, check connections on the circuit with the digital multimeter.
Next, make sure the power and ground rails aren’t shorted out. Then power on the circuit and make sure each chip’s power pin (Vcc) is getting 5V.
Finally, plug in the ICs. If you don’t hear music output, disconnect power immediately to avoid any magic smoke.

Edit Step 4
— Add the drum.
¶
You should now have a noisy circuit happily playing chords. To add percussion, the servo output alternates between maximum and minimum deflection every beat. The music box MAKE built uses a metal case as both project box and drum.
For my original version, I soldered the circuit onto protoboard and taped everything into a cardboard box.
For those with some PIC coding experience, the source code for the firmware is mainly driven by lookup tables, which you can easily modify to do other musical things such as playing songs, scales, etc.
For the schematic, a GIMP file with wiring, compiled firmware, source code, and an audio sample, go to http://www.makezine.com/17/diymusic_rand....
This guide has been completed 1 time.
Page 1 of 1

I completed the breadboard prototype for this today, and it sounds pretty good. There is some severe distortion on the pot that connects to the last pin (top right if the notch is at the top) of the op amp. Has anyone found a way to smooth that out? (I have to keep the knob turned all the way down).
Thanks for the great how-to though! Once I get the distortion figured out, I'm going to get to put onto a proto board and mount it with the servo.