Web
Analytics

How to add Sound

to Your Project

Fig. 1

This is a build page about how to add sound effects, songs, or just about any audio content to a modeling project. There are many ways to do this, several of them will be discussed, and two in particular will be used as an example. There are several SBC (single board computer) add-on boards, like Arduino shields or Pi hats to provide audio, but these are usually at least as big as the Uno form factor, too big to consider here.

The parts for one of these example projects are shown above, but there is more than just audio there. Before that, however, we need to discuss some of the options.

The first step to adding sound to your project is to gather the sound files that you want to play. This can be done in variety of ways. Sound files can be recorded directly - almost all smart phones have sound recording apps that can produce mp3 files, for instance. They can also be ripped from movie DVDs, or if the scene containing the sound is posted online, there are free online apps that will convert a video clip at a specific URL to an mp3 file of the sound on that clip. (Search on "online audio conversion" to find a site like this one for example.) Once you have a sound file you can use a freebie audio editor like Audacity to amplify, trim, or change the sound file as needed. An important tip is that it is easy to over-drive these small speakers in an effort to get some volume, which only results in distorting the sound. This can be reduced in one of two ways - adding a volume control (a potentiometer or some switches) to reduce the amplitude to something the speaker can handle, or reducing the amplitude of the recorded mp3 file to begin with. This latter method saves you the headache of trying add pots or switches to an already crowded model.

Once you have all your sound clips, copy all those files onto a micro SD card. Any more, micro SD cards come in a minimum of 1 or 2 gigabytes, and as of this writing, MicroCenter sells 8 gig cards for just $6, so space on them is definitely not going to be a problem. 8 gig is probably enough space to hold every song you've ever heard! Sometimes you see micro SD cards called TF cards because that's their nomenclature when used in a cell phone, but they are the same hardware.

There are several ways to play mp3 files on the SD card. Deciding which approach to take depends on three main considerations - 1) how much control you need, like how it will be triggered, which mp3 needs to played on what condition, etc, 2) how much sound fidelity you need, and 3) how it will be powered. Bigger is definitely better for speakers, but at this writing (spring 2018) much progress has been made in the design of tiny speakers, mostly for use in tvs, laptops, cell phones, and tablets so the choice of speaker in a cramped space is much better than it used to be. Model trains now emit accurate locomotive sounds, and hobby shops carry some of these smaller speakers, as well as selling them online. The amp chip used on all these devices well exceeds the characteristics of these small speakers, so that is less of a consideration unless you want to drive much larger speakers that need more power than the 1 to 3 watts or so they can provide.

Below, I show four of the most common and inexpensive solutions, and then go over some of the more common speakers available, and then provide a couple of example projects.


Fig. 2

The first one is by far the cheapest, but is also the lowest in sound quality - in fact, you can just barely recognize the sound with these as they are supplied. It is the tech used in those insanely priced greeting cards that play music or whatever other sound. Go to a Hallmark store and listen to them if you want an audition. Their sole virtue is that they are inexpensive, but as you will see, so are the other ones below. They are sold by several companies, one of which is called BigDawgs and are shown here. More info about using them is given on the website. The sound is typically triggered by one or more switches, and how much storage each version can hold affects the price as well. In the photo above, the bottom of the board has a slide switch, which triggers the sound when the card is opened. It also has a microphone so that you can simply record whatever sound you want played directly. Other models can play multiple sound files. Your sound files (either .mp3 or .wav ) is readied and copied over to the device using the micro USB port on the board using some supplied software called SoundLoader.

As you can see, they are very inexpensive, but are designed to fit in a greeting card and then inside an envelope. This means the speakers are about as thin as they can be made, and the sound suffers quite a bit as a result. Upgrading to some better speakers like those discussed below makes a big difference, but then you lose quite a bit of their cost advantage. They are also powered by three thin hearing aid type batteries, making 4.5 volts. Because the PC board must be thin it has a large area, which means you may have trouble fitting them inside a model. However, if they can be made to fit and they work like you need them to, they can be an inexpensive solution.


Fig. 3

Another approach is a combination mp3 board - an mp3 decoder, SD slot, and amplifier combined. Above is a GPD2856C full mp3 player - lots of functionality in the board shown above. This board sells on Ebay (at this writing) for anywhere from $2 to $7 including shipping depending on where the supplier is located. It can be powered by 3.5 or +5 volts, which can be applied to either soldering pads or to the micro USB port in the middle of the bottom of the board shown above. On the left is the micro SD card slot, as well as a standard USB Type A slot for a flash drive or external hard drive, which are expected to be formatted FAT32 and have the mp3 files on them. The USB socket only hosts a flash drive, there is no device presence for this interface.

This board is the largest of the solutions discussed here, but it is still pretty small at 1.75 x 1.4 inches (45x36mm) in size. For a sense of scale, note that in Figures 3, 4, and 5, the larger silver metal piece houses the micro SD card, roughly the size of a fingernail!

The main tech here is a 8002A 2 watt mono amplifier chip (spec says 3 watts output if driven from +5) to drive the speaker - the IC is hidden behind the speaker terminals in the above picture) and the GPD2856C-009A mp3 player chip. This chip provides stereo output to the headphone jack, but left channel mono audio only to the speaker through the 8002A. Speaker turns off when headphone jack is used, which could go to an upgraded amplifier/speaker set.

There are four buttons - two of these are prev/next track for song selection. These same two buttons are used for volume control - a long press (> 2 seconds) on the next button increases volume, and a long press on the prev button decreases volume. The Play/Pause button just toggles that condition, but its long press toggles between selecting the SD card or Flash drive. The presence of one or the other is automatically detected on power up, so the board just starts playing automatically. Lastly, there is the repeat button to toggle "repeat the same song" mode with "play all the songs" mode. There is no long press function on that button. Finally, there is an LED that flashes when a track is playing. A lot of stuff for just a few bucks!


Fig. 4

Above is another mp3 device that I will call the GPD2846A Lite - This board is very much like the one in Figure 2 - it uses the same chips - but is a little more barebones. The screw terminals for the speaker are gone, the on-board push buttons are gone (pads for soldering your own buttons or shorting out are provided), the micro-USB connector for power is replaced with just GND and BAT+ soldering pads, (either 3.5 or 5 volts) and the other USB type A flash drive socket is gone. Most significantly, the stereo headphone jack is gone, so the only output from this board is both channels mixed to mono for the speaker. Other than that, its the same one in Figure 2 with a 3 watt (at 5 volts) on board amplifier. These cards are newer, and uses the same GPD2846A chip, so search on that for more details.

You can temporarily use some tweezers to short the pads together - e.g., doing this to the top two pads in a "long press" causes the volume to lower, for instance, but the sound volume reverts to full on next power up. Another way to control volume without needing an additional switch is to lower the amplitude of the recording to begin with using Audacity. (the Effects...Amplify option)

Pricing for this is $4.13 on Amazon, but it still ships from China. Size is smaller at 1.35 x 0.88 inches (35x23mm).


Fig. 5

The DFPlayer Mini - the above module is a barebones mp3 decoder to use when you want complete external control, like to use with a small form factor SBC like an Arduino Nano or Trinket, etc., or a Raspberry Pi Zero. The hookup wires are minimal - 3.5 to 5 volts, ground, two speaker wires to a < 3 watt speaker or stereo channels to a headphone or external amp, and two digital inputs to the cpu - one transmit, one receive. The SBC communicates with this device via a serial protocol, provided by a library, which allows the SBC to randomly access a track, control volume, etc. The SD card is expected to be formatted FAT32 and there are some restrictions on file naming - it wants simple 8.3 nomenclature and numerical naming of the tracks. This allows you complete control to play a particular mp3 file based on a sensor or switch input, or a timer going off.

The good news is that it works with the Arduino software serial library , and if you search on DFPlayer there are some example sketches to get you started. From there in the Arduino or Python program you can read switches, turn on LEDs, and play the mp3 files at will. You can specify which track to play at any given time, and the tracks may be organized in separate folders on the SD card.

The main chip on my DFPlayer mini is a YX5200-24SS but someone attempted to scratch that out before it shipped to me, so mine is a knock off! Current pricing is about $2, and the size is .825 x .800 inches (21x20 mm) without the SD card inserted. All seem to have the header pins already attached.

As you can see, the cost for all of these mp3 boards is within a couple of bucks of each other, so pick one based on the features you need.


Fig. 6

Now lets talk about sound quality. Space is always at a premium inside models, and better sound quality usually means a large speaker and sound cavity, and perhaps a more powerful amplifier if the larger speakers need it. Sound generation is fundamentally a matter of moving air, so bigger is definitely better for speakers. Model trains now emit accurate locomotive sounds, and hobby shops carry some of these smaller speakers, as well as selling them online. The biggest consideration is where can you place the speaker inside the model, how will the sound resonate and emerge, and will the result shake the model to pieces while playing.

A sampling of the more common speakers are shown above. Going left to right. the leftmost speaker is a 2 inch diameter traditional "transistor radio" speaker. It works, its cheap, thin, and can take some power, but the sound quality just isn't as good as others. The next one is a 4 ohm 3 watt 50mm (2 inch) diameter speaker for $1.56 and its sound is fair. The middle one is a smaller (1.25 inch diameter) version that is a 4 ohm 2 watt 40 mm (1.6 inch) speaker that I got on Ebay, 2 for $6. The next one is a 4 ohm 2 watt (1.25 inch diameter) speaker and its sound is as good as its neighbor, probably due to the neodymium magnet driver. I got the speaker from Parts Express for $3.45 (part no 285-103.) On the far right is an 8 ohm 5 watt speaker used in televisions that went for $7 on Ebay, and overall, has the best sound of all those above. Whether or not you can fit into your project depends on the available geometry of your project.

Also notable are the speakers used in model trains, which can have some surprisingly good sound. A good example of these are the Knowles Grand "sugar cube" speakers, although there are other brands available as well. These are usually rectangular and carry one watt or less, but are often used in pairs to double the sound. They often come with small enclosures designed to help resonate the sound. They are also a bit more expensive that those above, but worth looking into if sound fidelity is the prime requirement.

Speaking of enclosures, if your project has the room it is worth some experimentation to attempt to make a sound chamber for the speaker, depending on how it is to be housed in your project. These can really help direct and resonate the sound, turning a tinny experience into something with a bit more depth. I usually do this with some sheet styrene, an X-acto knife, and some CA glue. This makes for rapid prototyping and changes for immdediate feedback on how it affects the sound.


Fig. 7

The third main consideration is powering these systems. If you can live with a power cord to your project, then wiring it with a USB Type A plug on one end is the simplest approach. You can get such a USB cord cheap by buying an old mouse at a local thrift shop (they sell for $1 around here) and cutting off the mouse and throwing it away. Once the project has a cord, there are inexpense, portable 5v battery packs, normally used as a USB charger/auxillary power source for smart phones, that are widely available to power your project. Of course, a regular PC USB port can also be used, as these devices don't typically exceed the 1 amp limit.

Of course, a USB 5 volt regulated wall wart is also an option. In this option you don't need a cord as the wart supplies it, but be careful here, though. Never use any USB wall wart without measuring its output first - you can't trust what is stated on the wart. The ourput voltage can often be quite higher than stated, as it's intended to be used as the unfiltered input to a regulation circuit. Sometimes it is not even DC despite what it says on the wart. One really handy thing you can get is a USB testing device like this one. For just a few bucks, it shows both voltage and current draw for whatever you are plugging in to it. One other word of caution - the wires used in USB cords are often very tiny gauge, making them easy to break if pulled on. If your phone, sound project, or other USB item suddenly stops charging, suspect the cable first.

Interesting how a serial data exchange interface became the defacto low voltage power standard!

However, usually a corded project is less than desirable. Most of the boards above can be powered by a 1S Lipo battery (3.7 volts) or 5 volts, like from a USB cable. The problem with Lipos is how to charge them. There are Lipo charging boards (like the one shown above in Fig. 7) which allows a USB micro plug to be inserted, (or 5 volts In on either side of the socket) charging the battery, and then provides the 3.7 volts for the project. The IC on the board provides for over charging protection, auto cutoff once charged, and up to 1 amp of current. They are $1-2 when bought in quantities of 5 or more.

If you need a true 5 volts for the project, there is also a board (one from Adafruit, ($20) and one from Sparkfun, ($15)) that not only provides the charging and Lipo protections, but routes the output into a boost converter to supply a regulated 5 volts. These solve the problem of using a 3.7 volt battery to power a 5 volt project, but they are a bit more pricey.

Of course, you also need to add the cost of the battery. Typicallty a 1 amp hour 1S Lipo is around $6-10.


Fig. 8

This is an example project I did for my son, who wanted a base to play background music for a display miniature. I designed a 4 inch diameter base and 3D printed it that had a hole for a switch and some holes in the rear for the sound to escape. The base is shown from the rear in the left photo above. The base is normally turned around and the on/off switch is out of sight in the back.

The right photo shows the base upside down. A speaker has been epoxied to the base, and wired to the mp3 board, the GPD2846A Lite described above. The power toggle switch is wired to the package on the left, which consists of the Sparkfun power board mentioned above, and a Lipo battery. I added the block on the side of the base later so that the package could be mounted as shown so that the micro USB socket was accessible for charging. Both the battery, charging board, and the mp3 board are simply Velcroed onto the base for easy removal.


Fig. 9

Here is another example. This is the same photo as Figure 1, copied here for convenience. The power is a 5 volt supply (set to 4.8 in the picture) that drives both the mp3 player card - the blue PC board that is the board in Fig. 3- as well as a $7 sound flasher board - the tan one on the right. The flasher board is connected to an electret microphone (the silver circle above the blue card) that is amplified and flashes a blue LED (mounted on the circular white plastic sheet) as the sound level fluctuates. The 1 inch diameter speaker (hobby store purchase for $7, actually a bit over priced) is playing an mp3 file in the picture, causing the microphone to flash the LED. Room is tight in this model, but these small speakers are quite nice for their size. The $6 micro SD card shown on the lower right is an 8 gig card. Not counting the power supply, its about $27 total for the above components. If you just want to add sound with no flashing LED, it would be about $20.

For my project, I am happy to simply play each of the files, one after the other, when power is applied - which is what it does by default. Therefore, I don't need to worry about bringing out switches to the model surface. Also, I will adjust the volume during assembly, and I see no need to change that later which spares me from mounting a volume control knob.

Given the common availability of USB power from phone chargers, external phone battery packs, and computer ports, I don't think I'll bother with trying to fit a lipo battery and charging circuit inside. I'll just bring a USB type A socket to the surface to let power in. No other controls will be needed for this application.


Fig. 10

Above is the completed model with all the sound gear inside.


I hope this has given you some basic road map information about adding sound for your project. Tech marches on, so the types, availablity, and prices of all the pieces mentioned above will change over time. Don't hesitate to give it a try or experiement with something new!


Comments may be directed to gary at liming daught org.

Thanks for viewing this build log!