Past Posts of this series:
Tinkering Tuesday – Playmobil Stage – Einführung
Tinkering Tuesday – Playmobil Stage – Introduction
Tinkering Tuesday – Playmobil Stage – Playmobil parts
Tinkering Tuesday – Playmobil Stage – LED Stage Lights
Tinkering Tuesday – Playmobil Stage – Disco Ball with stepper motor
Tinkering Tuesday – Playmobil Stage – LED Rings
The most important thing a stage needs is sound! As I want to keep costs down I want to use one of the several cheap Arduino copies I have lying around. That will be not the best quality sound but it will work. In the following post I will describe my way to Arduino sound.
microSD card to Arduino
I bought some cheap microSD card modules from eBay (1 EUR for 2 pcs) to save the audio files on.
MicroSD cards work with 3.3V serial communication, the Arduino with 5V. As I had a spare LLC (Logic Level Converter) from my HUEify project lying around I decided to use that one. I couldn’t find much about using one with a microSD adapter on the web (here is a german site: http://physudo.blogspot.de/2013/09/sd-karten-mit-dem-arduino-beschreiben.html) but in the end it is straight forward. The only I issue I had (which made me nearly giving up) was that connecting everything through the LLC always resulted in the Arduino not being able to initialize the card. Directly connecting the MISO (Master In Slave Out) pin from the SD to the Arduino finally solved it. There is no issue in voltage level as this pin only sends data from the SD card to the Arduino (Master=Arduino in, Slave=SD card Out) so it communicates with 3.3V which is enough for the Arduino.
This is the schematic I came up with (the fancy colors are a result of my jumper wires on the breadboard, see picture below):
If you even want to save the microSD adapter, you can build your own adapter for normal SD cards. In this picture shown by Nathan Chantrell on flickr, you can also see the connections that have to be made.
Using the sample code from https://www.arduino.cc/en/Tutorial/listfiles you can test whether your connections are working. My first attempts always showed „initialization failed“ until I connected MISO directly to the Arduino and not via the LLC. You also need to format the card in FAT16 or FAT32. I had a 2GB card lying around and my bigger cards did not work. So just try different ones if it is not working.
Making the audio connection
I had no Amplifier or something (but I ordered it) at first, so I searched for a way to hook up the Arduino directly to a speaker. I had a small battery powered Bluetooth speaker which also had a 3.5 input jack. So I used that one. It is pretty much crap but for testing it is sufficient. Mainly I followed the instructions at apcmag, building the Auduino. Only with some adjustments to match what I have on hand.
The connection to audio is also shown very simply in the following screenshot:
The setup can be seen in the following image:
For coding I used the Auduino code from apcmag. Try setting the cardType variable to newCard if working with newer cards (they provide a modified SD card library). You also need to convert your audio to compatible WAV files. Just follow the instructions on apcmag.
What should I say: There is sound!
But as you can hear in the video the output has much noise. The speaker has no volume control so this might be the problem.
Using LM386 amplifier module with passive speaker
To attach a normal speaker, I ordered some cheap LM386 modules from ebay (5pcs 3.79 EUR). Specifications can be found on www.petervis.com. It is rated for 5V-12V power so can be powered directly from the Arduino.
I had an old Logitech speaker set lying around which I don’t need anymore so I cut the passive speaker off the other part to serve as a speaker.
The connection is also very easy:
The second ground pin is for use with external power. You need then to connect the IN and GND from the sound source and the VCC and second GND pin from your power source.
The result can be seen in the following picture and the sound quality is already much better than the crappy bluetooth speaker:
The only thing that is not working is the volume control. On the left of the small potentiometer there is a small space where it gets a little more quiet and finally silent but everywhere else it is nearly the same volume.
Using PAM8403 amplifier module with passive speaker
Just out of curiosity I ordered another cheap amplifying module based on the PAM8403. This one is stereo and has a bigger potentiometer. It is 1 EUR on ebay for one piece. It is also rated for 5V power (2.5V-5V) and has a maximum output of 2x3W (5V, 4 Ohm)
The pinout is as easy as from the LM386 but for stereo. I soldered the pin headers. You need 3 for input, 2 for power and 4 for the output to the speakers. I used only mono output for the test:
From left to right:
- input L
- input GND
- input R
Input GND and power- are connected so you only need one if powering directly from the Arduino.
The setup of the module looked like this:
The sound is slightly better and also louder. By using the volume control the sound goes to mute smoothly but is also clipping at about half the way.
The PAM I felt was slightly better at sound quality but only at the right volume. The advantage would be an adjustable volume but as half of the potentiometer causes distortion I can’t expose it to the user. So in the end I think I will stick with the LM386 for the build because the sound quality was good and the volume was also acceptable so it doesn’t have to be adjusted.
Here are some more links on the topics:
Audio on an Arduino nano: http://apcmag.com/play-wav-filesn-arduino-nano.htm/
Extensive post using SimpleSDaudio library, building SD card adapter, connecting speakers http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio
Builiding an adapter for microSD cards (and some other useful breadboarding tips): https://protostack.com.au/2011/09/8-breadboard-hacks/
SD card connection to arduino: https://www.flickr.com/photos/nathanchantrell/6323290363/in/photostream/
Connecting SD card to Arduino with LLC: http://physudo.blogspot.de/2013/09/sd-karten-mit-dem-arduino-beschreiben.html
SD/MMC From the ground up: http://forum.arduino.cc/index.php?topic=8314.0
Another great instruction from sparkfun – MicroSD Shield and SD Breakout Hookup Guide: https://learn.sparkfun.com/tutorials/microsd-shield-and-sd-breakout-hookup-guide