MP3 shield VS1053 on Arduino

FunduinoPublished on

MP3-Dateien vom Arduino abspielen lassen

Das MP3-Shield VS1053 wird auf den Arduino UNO gesteckt und spielt MP3-Dateien von einer Micro-SD-Karte ab. Eine zusätzliche Verkabelung braucht es nicht, nur einen Kopfhörer oder Aktivlautsprecher am Klinkenanschluss.

Die Anleitung zeigt zuerst, wie eine einzelne Datei abgespielt wird. In der Erweiterung misst ein Temperatursensor LM35 die Temperatur, und das Shield spielt die passende Ansage dazu ab – das Prinzip lässt sich auf jeden anderen Sensor übertragen.

The MP3 shield VS1053 with microSD slot and headphone jack
The MP3 Shield VS1053

You need this

VS1053 MP3 Shield - microSD slot, 3.5 mm jack, for Arduino UNO R3 VS1053 MP3 Shield - microSD slot, 3.5 mm jack, for Arduino UNO R3 10,61 € *Item no. F23108448About the product — VS1053 MP3 Shield - microSD slot, 3.5 mm jack, for Arduino UNO R3
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino

All 2 parts together 21,73 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

The MP3 Shield VS1053

With the VS1053 Shield, an Arduino can play MP3 files stored on a microSD card. The shield simply plugs into the UNO - no additional wiring is required.

To listen, connect headphones or powered speakers using an audio cable.

The MP3 shield VS1053 with microSD slot and headphone jack
The MP3 Shield VS1053

Prepare the SD card and libraries

The Micro-SD card must be formatted as FAT32 . In Windows, right-click the removable drive and select “Format.” Then choose FAT32 under File system.

Two libraries are required:

  • Arduino_Library-vs1053_for_SdFat – the library for the shield, available on GitHub
  • SdFat – for accessing the memory card

You can create your own MP3 files for free using a text-to-speech service. The filenames are important: track001, track002, and so on.

In Windows, open the context menu with “Format” by right-clicking.

Play a file

The first sketch plays a single file and repeats this every six seconds. The number in playTrack().

The number in parentheses is the file number: playTrack(3) plays track003.

Play an MP3 file on a loop
#include <SPI.h>      // libraries
#include <SdFat.h>
#include <vs1053_SdFat.h>
SdFat sd;       //Name the SD card
vs1053 MP3player;   //Name the MP3 Shield "MP3Player"
int t=6000;       //The value of "t" specifies the time interval between playing the file in the code.
void setup() {
  if(!sd.begin(SD_SEL, SPI_FULL_SPEED)) sd.initErrorHalt(); //Read the SD card containing the MP3 files
  if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
  MP3player.begin();    //Start the MP3 Shield
  MP3player.setVolume(10,10); //Set the volume
}
void loop() {
  MP3player.available();
  MP3player.playTrack(3);     //The MP3 Shield now plays the MP3 file named "track001". For a file named "track002", use "2" instead of "1" in these parentheses.
  delay(t);               //Previously specified pause
}

Extension: Announce temperature

The add-on uses a LM35 to measure the temperature, and the shield plays the corresponding announcement. The sensor is connected via a screw terminal adapter: black to GND, red to 5V, yellow to A0.

To do this, create a separate file for each temperature value - track012 for 12 °C, track013 for 13 °C, and so on. The map-command converts the sensor reading to degrees and passes the number directly to playTrack().

playTrack() is called during every loop iteration. If the temperature stays the same, the same announcement restarts every six seconds.

LM35 temperature sensor via a screw terminal adapter on the MP3 shield
LM35 on the VS1053 via screw terminal adapter
Play the sound file corresponding to the measured temperature
#include <SPI.h>      // libraries
#include <SdFat.h>
#include <vs1053_SdFat.h>
SdFat sd;       //Name the SD card
vs1053 MP3player;   //Name the MP3 shield "MP3Player"
int LM35 = A0;      //Connect the sensor to analog pin A0. From now on, we’ll call this pin "LM35"
int sensorwert;     //Create a variable for the sensor reading
int temperatur = 0;   //The temperature value will later be stored in the variable "temperatur".
int t=6000;       //The value of "t" specifies the time intervals between individual measurements in the code.
void setup() {
  Serial.begin(9600);   //Start the serial connection
  if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();  //Read the MP3 files from the SD card
  if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
  MP3player.begin();    //Start the MP3 shield
  MP3player.setVolume(10,10); //Set the volume

}
void loop() {
  MP3player.available();
sensorwert=analogRead(LM35);        //Read the sensor value.
temperatur= map(sensorwert, 0, 307, 0, 150);  //Convert the sensor value using the "map" command.
  Serial.println(temperatur);       //Display the temperature in the serial monitor
  MP3player.playTrack(temperatur);      //The MP3 shield now plays the file with the matching filename, depending on the measured temperature.
  delay(t);             //Previously specified pause
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.