Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(26) Music Machine – An Arduino MP3 player with amplifier and two speakers

Because of working memory space constraints in Arduino microcontroller boards, production of sound with these boards is normally limited to creative application of beeps. Connecting a SD card based MP3 player to an Arduino overcomes the memory limitation and opens the world of real digital audio. Here we discuss a Music Machine consisting of a simple stereo MP3 player that is controlled by an Arduino Nano. A connected PAM 8403 mini amplifier powers two mini speakers.

The Arduino Uno and its little brother Nano are microcontroller boards equipped with a very limited amount of on board memory. The ATmega328 chip has a minuscule 32 kB of addressable RAM memory available plus 2kB of SDRAM. Memory constraint is nevertheless a charming aspect because it forces the user to be very efficient and creative with programming. At the same time it limits what can be achieved with this microprocessor board. Playing music is not directly possible because even a short stereo music track in MP3 format has a size of close to 2 MB, or far too much exceeding the amount of memory available in the Uno or Nano. A solution is as old as computer science: use external storage. A popular external storage device is the SD card. These are cheap and they offer gigantic amounts of storage. Here we experiment with a 16 GB micro-SD card and a MP3-TF-16 MP3 player that is equipped with a SD card slot.

MP3 player
The MP3-TF-16 MP3 player is a versatile, low cost device that can be operated standalone or with an Arduino, with two-channel (stereo) output under software volume control. Output is to an earphone (SPK_1, SPK_2, see figure 1) or an amplifier (DAC-R, DAC_L). The amount of music controlled is 100 folders each containing up to 255 songs (maximum supported capacity is a 32 GB SD card). That makes a total of 2,550 pieces of music!

Figure 1. Pin layout of a stereo mini-SD card MP3 player for Arduino.

This MP3 player is, for its low price, quite a performer. It supports MP3 sampling rates 8/11.025/12/16/22.05/24/32/44.1/48 (kHz), it has 24 -bit DAC output and support for 90 dB of dynamic range. The card reader fully supports the FAT16 and FAT32 file systems.

Music Machine
The Music Machine described here has the following five main components: Arduino Nano, MP3 player, stereo amplifier, speakers, and auxiliary power supply. All these components, except the speakers, are mounted on a base soldering board with dimensions 120×85 mm (43×30 perforations). The speakers (not shown in figure 2) are plugged with male jack connectors into the female sound outlet jacks soldered onto the base board. Figure 2 shows the components and the general wiring diagram. I have chosen to mount the Nano, MP 3 player and the auxiliary power supply onto female pin headers that are soldered on the base board. This makes it easy to replace these devices in case of malfunction.

Figure 2. Components and wiring diagram of the Music Machine. The amplifier is a PAM8403 chip based design, Arduino compatible. Output to the speakers is served by the (female) breakout jacks marked ‘R’ for the right channel and ‘L’ for the left channel. SPK1 and SPK2 are auxiliary parallel mono sound outlets (testing purposes).

Electronics and supplies
1x soldering board 120×85 mm (43×30 perforations), 1x Arduino Nano, 1x MP3-TF-16 MP3 player, 1x PAM8403 5V, 3W micro amplifier, 2x 3W 4Ω speakers, auxiliary 5V power supply, 2x 4-pin breakout female audio jacks, 2x 1000 Ω resistor, 2x 10 Ω resistor, female pin headers, wire, 4x M3 nylon spacer length 10mm, 3 mm audio cord with on both ends a male jack (to be used to connect the speakers)..

The wiring is quite straightforward. The MP3 player serially communicates via its pins marked TX and RX with the Nano. In the current design pins D10 and D11 of the Nano act as programmable TX and RX under the Software Serial library. Note that a 1000 Ω resistor is mounted in series in each of these two connecting wires of the MP3 player.
The output pins DAC_R and DAC_L of the MP3 player supply signal to the amplifier’s input pins L and R, while the amplifier’s input pin G is connected to common GND. The amplifier has its own Power + (5V) and Power – (GND) power supply pins, while output to the speakers is supplied by pins Rout + and – and Lout + and -. The Rout + and Lout + pins are connected to the ‘tip’ pin of their respective output jacks, and the Rout – and Lout – pins to the ‘sleeve’ pins of the output jacks. For the sake of reducing current load of the output channels and to reduce shrill sounds somewhat I soldered a 10 Ω series resistor in the wires carrying the Rout + and Rout + signals to their respective jacks.

Figure 3. The PAM8403-based Arduino compatible microamplifier with pinout and wiring diagram. The PAM8403 is a 5V, 3W device (at 4 Ω speaker impedance). With the big pot meter the output volume is governed.

Auxiliary power supply
An amplifier that produces peak sound levels of 3W at 5V and through a speaker with an impedance of 4Ω gobbles up a lot of current: 0.6A. It is possible to run a Nano/MP3-TF-16 MP3 player combination completely on the usb power supply to the Nano, that is with output to earphones. However, the prospect of a power hungry amplifier heavily drawing power from the Nano made me worry. This extra load could overwhelm the modest Nano’s resources. Hence I applied as a precaution an auxiliary power supply (a regulated 5V device connected to all 5V components, including pin Vin) of the Nano. As soon as the Nano is programmed and the music plays, the usb connector to the computer can be detached from the Nano. From that moment the auxiliary power supply provides all the power necessary to keep the MP3 player and amplifier working and, as a consequence, music playing.

The sketch that I used was the Arduino_mini_MP3 sketch acquired from the url https://www.instructables.com/id/Tutorial-of-MP3-TF-16P/.
The sketch needs three libraries: “Arduino.h”, “SoftwareSerial.h” and “DFRobotDFPlayerMini.h”.
After copying some sound files to the SD card and uploading the sketch a red led on the MP3 player started to blink and the music started to play.


Figure 5: Music Machine assembled and working!

The current project was started with the aim to creater an Arduino Nano controlled music machine. Although the end product is according to expectations, it was basically started as a project that will be integrated with a previously designed and manufactured timer/countdown timer. The ultimate aim is that a display on the timer/countdown part shows remaining time. An additional, 8×8 dot led matrix displays the final ten seconds. When the moment ‘zero’ is reached, the music machine part must start to play pleasant or annoying music.
After finishing this project I noticed that Arduino offers the 3.3V Arduino MKR Zero which has an Atmel SAM D21 ARM Cortex processor on board as well as a SD card reader. This little powerful miracle is equipped with dedicated SPI interfaces (SPI1) that would allow the owner to play music files with no extra hardware. For that microcontroller board a new library has been developed: the Arduino Sound Library.

Arduino_Mini_MP3_Player.ino – for download, click here