The $5 Picaxe Beatbox


(click image for better view)


I thought it would be a neat to build a toy that records and plays back beats like a simple drum machine. For those who are musically inclined, it provides endless hours of entertainment and even has practical purposes in learning and practicing music. Even better if it used less than $5 worth of parts and could be built in 30 minutes.

Here is such a toy.

Turn it on. The LED glows indicating it is in record mode. Tap out a beat and the controller records your beats. After sample memory is filled up (about 5 seconds), the LED goes out and the beatbox goes into playback mode, endlessly looping playback of your sample. Press the drum pad again and you’re back in record mode again. Finally, a chance to put that finger-drumming to good use. And if you continue finger-drumming along with this $5 beatbox, you can easily tap out some very complicated rhythms.

Since you are probably not likely to drum out a rhythm which repeats exactly every 4.8 seconds, the beatbox uses the last beat you played as the first beat of the next measure. This allows a variable drum beat loop length and works quite well once you understand you need to play a single beat at the end indicating when the loop should restart.

To conserve precious recording memory, recording doesn’t actively start until you press a drum pad. Although this means that you can’t have a rest as the first beat of your drum loop, it is hardly a limitation in practice and makes the interface work well. You can always add a rest at the end of the rhythm for the exact same effect.

The device enters a power saving mode if no input is detected during recording, or if playback persists for an unreasonably long period of time. Alternately, touch both pads at one time to enter powerdown immediately. Touch pad 1 to turn the device on.



The original design had a single piezo pad and recorded an ADC value into the controller’s 48 bytes or RAM. Since fairly rapid sampling (approx 20ms or faster) is necessary to avoid noticeably quantizing drum beats by the sampling rate, this only allowed for about 1 second of samples. To fit more samples in the same space, samples are binarized (the sensor was either touched, or it wasn’t) and this value is byte-packed into RAM. Using 2 bits per sample, more than 4 seconds of rhythm is recordable.

After playing with version 1 for a while, it became apparent that differentiating between major and minor beats would be a *very* nice improvement. Think of a metronome which stresses the first beat of each measure. So the original design was modified to allow 2 inputs which are played back as low and high pitch tones. Because 2 bits per sample were used in byte-packing, the sample length is still 4 seconds. In fact, a third drum pad could be added very easily.

Tapping on a piezo can result in a high voltage that could damage the picaxe, so crossed diode protection was used to eliminate potential damage. Because the response from a tapped piezo is an exponentially decaying voltage, the original code included a simple “leading-edge detection” algorithm. A bleeder resistor was included across the piezo to help drain the voltage. A scope to check out the piezo response would have been invaluable for design.

But after trying a few scrap piezo's in the design, it became obvious that sensitivity varied greatly as well as the decay time constant. This has something to do with electrical and mechanical parameters of the piezos, but cost valuable memory and code space in compensating for these differences. Since the idea of the pad was merely to provide input, the design was rethought.

The current implementation uses light dependent resistors (LDRs) for input. These are each mounted within a small fastening nut in order to provide a nice solid pad to tap on. Tap on top of the nut, and it blocks almost all of the light from the LDR. I blocked a few surrounding perf-board holes with glue to eliminate light leakage from the bottom. The surface of the LDR was coated with clear fingernail polish to help make it a bit more robust.

Input edge detection was tossed in favor of smarter playback. Since it is unlikely that a pad could be intentionally touched in 2 consecutive samples, the playback doesn't allow such a thing. The beat plays back only on the leading edge of each recorded input signal. Following consecutive samples are ignored until either the other pad is played or input is removed from the original pad. This is a form of switch debouncing in software to filter the signal as desired.

For ouput, I've found that mounted piezos have much better sound than the unmounted elements. So use a mounted one for playback of your drum loops if you can.



Picaxe 08M microcontroller
8 pin socket
Mounted piezo speaker
Light Dependent Resistor (2)
Misc Resistor (4) - (see text)
3 pin programming header
Perf board



Assembly is pretty easy. Follow this schematic to hook up the sensors and output piezo speaker. Program the chip with this code and you'll be well on your way to a $5 drum machine. Because scrap LDRs were used, I used resistors that were approximately equal to the LDR value in medium light as the other half of the voltage divider. Value isn't too critical, because some compensation can be made within software as long as the LDR and voltage dividing resistor are within an order of magnitude of each other. The program includes calibrations for each LDR (e.g. sensor1Thresh) which can be changed independently if pad sensitivity is too little or too much. I used this short test routine to see the values of the LDRs as I tapped on them, so I could enter calibrations into the software. In circuit programming allows for that sort of adjustment.



Sometimes it is fun to do more with less, and fitting the complete design into a tiny inexpensive Picaxe-08M is a nice minimalist approach. But if you wanted to be decadent, even at minimal cost, more sensing pads could be added, along with more sophisticated recording logic (e.g. a Picaxe-18X). An I2C EEPROM could store tens of thousands of samples instead of just a few hundred.

This code is explicitly released under the GPL. And this page is licensed under a Creative Commons Attribution 2.5 License.  

Write me if you find this project interesting. Link to this page if you find it relevant..

Warning, rhythm tracks may repeat endlessly in your mind. Others may not find your finger-drumming quite as entertaining as you do. This project is provided without any warranty and probably isn't suitable for anything.

Read or write a comment on the hardware projects

Back to Picaxe Projects