Ask MAKE: Playing back a recorded sound


Ask MAKE is a weekly column where we answer reader questions, like yours. Write them in to mattm@makezine.comor drop us a line on Twitter. We can't wait to tackle your conundrums!

singing_scope.jpg

George writes in:

I've been wanting to make a prank project, that I can leave somewhere to play back a recorded sound and flash some lights. I'll use LEDs for the lights, but don't know how to play back sound. Do you have any suggestions?

Aha, this sounds like it could be a fun project. I'm going to assume you are using a microcontroller to monitor an input (sound? light? time? vibration?), and then initiate a sequenced event. It's a bit late for Halloween, but this would be a good way to make lawn props that react when someone comes near your house.

Because playing back sound takes a reasonable amount of memory and speed, it's not something that can be done easily with a standard microcontroller. Instead, the best way to handle this would be to hook up another device, that can be started by the micro and then do the heavy lifting of actually playing back a sound. At least three possibilities come to mind: using a Wave Shield, hacking an MP3 player, or hacking a cheap toy with a sound recorder.

If you are using an Arduino, the Wave Shield might be an ideal solution to your problem. It is an expansion module that allows you to play sounds off of an SD card, and there is a nice library to control it as well. It runs in at about $22 bucks, which seems pretty reasonable for what you get.

If you aren't using an Arduino, or already have an old MP3 player and don't want to spend the bucks on a project you will only use once, then you can try to use that. The best way to do this is probably to wire an optocoupler to the play button on the MP3 player, and then trigger that with your microcontroller. If you have more than one sound track that you want to trigger, you could also wire up the next button, but that might get tricky. The bonus for going this way is that you could recycle some electronics junk that would otherwise go to the scrap heap.

Either of the two above solutions are great if you are only thinking of making one or two of the devices, but what if you want to make a bunch of them? In that case, it might be more economical to try hacking a cheap toy, such as this one. Somehow these are still available, and are less than $2 in quantity. The sound quality probably won't be anywhere as good, but hey, the're cheap! If you are in a rush, you could also try hacking a voice recording card that you can pick up at a local store. Good luck!

In the Maker Shed:

Makershedsmall

waveshield_crop_cc.jpg

Arduino WaveShield Kit


Recent Entries

Comments

Oldest comments listed first.

Posted by: kwantam on October 29, 2009 at 1:08 PM

sound and microcontrollers

This is mostly bad advice. Yes, these approaches will work, but for short, moderate quality sound reproduction (on the order of a few seconds, which I assume is what George had in mind, given the prank nature and the flashing lights) most any modern microcontroller is up to the task.

For example, the Arduino Duemilanove is available with a 32kbyte program ROM. This is usable for data storage, which can be read via the LPM instruction. A program to monitor a sensor and play sound is trivial, and along with the bootloader should take no more than 3kB (generously). This leaves 29kB of flash for storing audio. 8-bit audio at an 8kHz samplerate (giving 4kHz maximum audio frequency) is sufficient for, e.g., moderate quality voice reproduction, and you can fit almost 3.5 seconds of it into 27kB. (Note, 8051/8052-derived micros also support this via MOVX, and even the Microchip DSPics will let you read data from program memory, though they are pretty gimpy at doing so because of how their memory is organized.)

Playback is as simple as loading the 8-bit data into one of the 8-bit PWM SFRs, updating the value 8kHz, then low pass filtering the resulting output with an R-C network. Use an op-amp to drive a small speaker and you're done. Alternatively, you can use the PWM output to control a half-bridge or H-bridge driving the speaker with an L-C filter, effectively making a class-D audio stage.

With regard to processing power, using the PWM output and updating at 8kHz takes almost none. In fact, I've designed a small board with a very similar purpose to George's that uses the microcontroller for playback and also to implement the controller for a dc/dc converter. Most of the processor power goes to the dc/dc converter feedback loop; the audio is almost an afterthought by comparison. I have an incomplete writeup (for now, just soldering instructions plus BOM, board, and code) of my design at http://web.jfet.org/awkwardalarm/

Any of these is a far more enlightening approach than "buy this solution, it'll just do it for you!"


Posted by: Matt Mets on October 30, 2009 at 1:42 PM

Ok, that's a fair criticism, I shouldn't have been so quick to overlook using a micro to generate sound. Here's a sketch for Arduino that uses a timer-based PWM to play back PCM (pulse-control modulation) audio:

http://www.arduino.cc/playground/Code/PCMAudio

If you need higher quality or longer sounds, though, I think an external module is going to be the best way to go.


Posted by: eGort on October 29, 2009 at 1:35 PM

Cheap recording device

A cheap 30 second recording device you could hack is:

http://www.allelectronics.com/make-a-store/item/SAW-3/SAW-3-DIGITAL-VOICE-RECORDER/1.html

I'm sure an Arduino could trigger it via a relay.

Please post your creation when you're done. Others cold learn a lot!


Posted by: Mr. Roboto on October 29, 2009 at 2:52 PM

serial controled mp3 player

Not cheap, but full on features and easy to control via serial COM:

http://www.robotshop.us/rogue-robotics-ump3-mp3-play-back-module-1.html



Posted by: Simon on October 29, 2009 at 7:19 PM

You could use an HK828 chip:

http://www.jaycar.com/images_uploaded/zz-8200.pdf

They aren't cheap though (at least not down in this part of the world).

I used one to make this: http://www.youtube.com/watch?v=WN1riSZcjKs

I have previously done it myself using a micro and some memory then clocking out 8 bit sample bytes into a buffer then into a R-2R resistor D to A converter. That worked pretty well. I've done that using a PIC 16f84 (obsolete now) and also a 6502!


Posted by: Matt Mets on October 30, 2009 at 1:35 PM

Yeah! I remember the A Team music box, it's awesome! Thanks for chiming in.


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out. Make: The risk-takers, the doers, the makers of things... Welcome to Make: Online!


CRAFT Maker Shed Maker Faire MAKE television
Holiday Gift Guides from MAKE
Gifts for Dads
Science and Chemistry
Gifts Under $20
More guides: Santa Claus Machines, Geek Toys for Grown Up Girls & Boys


Check out all of the episodes of Make: television

Alex Rider Dream Gadget Contest
Make: Science Room

Connect with MAKE

Be a MAKE fan on Facebook MAKE on Facebook
Visit our Facebook page and become a fan of MAKE!
MAKE on Twitter MAKE on Twitter
Follow our MAKE tweets!
MAKE Flickr Pool MAKE on Flickr
Join our MAKE Flickr Pool!
    make_tips on Twitter




    Maker SHED

    Advertise here with FM.

    Why advertise on MAKE?
    Read what folks are saying about us!

    Click here to advertise on MAKE!



    Subscribe to MAKE Magazine!

    Make: Online authors!

    Gareth BranwynGareth Branwyn
    Senior Editor


    Phillip TorronePhillip Torrone
    Senior Editor
    | AIM | Twitter


    Becky SternBecky Stern
    Associate Editor
    | AIM | Twitter


    Marc de VinckMarc de Vinck
    Contributing Writer
    | AIM | Twitter


    John ParkJohn Park
    Contributing Writer
    | Twitter


    Sean RaganSean Ragan
    Contributing Writer
    | Twitter


    Matt MetsMatt Mets
    Contributing Writer
    | AIM | Twitter


    Dale DoughertyDale Dougherty
    Editor & Publisher
    | Twitter


    Shawn ConnallyShawn Connally
    Managing Editor
    | Twitter


    Goli MohammadiGoli Mohammadi
    Associate Managing Editor

    Kip KayKip Kay
    Weekend Projects
    | AIM | Twitter


    Collin CunninghamCollin Cunningham
    Contributing Writer
    | AIM | Twitter

    Adam FlahertyAdam Flaherty
    Contributing Writer
    | AIM | Twitter



    More contributors: Mark Frauenfelder (Editor-in-Chief, MAKE magazine), Kipp Bradford (Technical Consultant/Writer), Chris Connors (Education), Diana Eng (Guest Author), Peter Horvath (Intern), Brian Jepson (O'Reilly Media), Robert Bruce Thompson (Science Room)

    Suggest a Site!

    Current Podcast

    itunesdl.gif Weekend Project: Beetlebot Simple robot from your parts bin that avoids obstacles. Thanks go to Jerome Demers for the original article in MAKE, Volume 12. To download the Beetlebot video, click here or subscribe in iTunes. Check out the complete Beetlebot article... More...

    Get the Make: Online sent via email
    Enter your email to receive Make: Online each day:



    MAKE Fascination video series brought to you by Dow

    Make: Education
    MAKE: en EspaƱol MAKE: Japan
    Important please read


    Subscribe to MAKE Magazine!

    Recent Posts from the Craft: Blog