Arduino - RFID MP3 Player

In this tutorial, we will explore the process of creating an RFID-based MP3 player using Arduino, an RC522 RFID reader, and an MP3 player module. The MP3 player module is equipped with a micro SD card where multiple songs are stored. Each RFID card represents for a song, and the number of RFID cards matches the number of songs.

By swiping an RFID card in front of the RFID reader, the Arduino plays the corresponding song associated with that specific RFID card.

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×RFID/NFC RC522 Kit (reader + tags)
1×RFID Key Fob
1×RFID Card
1×Serial MP3 Player Module
1×Micro SD Card
1×3.5mm Aux Speaker
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Recommended) Breadboard Shield For Arduino Uno
1×(Recommended) Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

About RFID/NFC RC522 Module and MP3 Player

If you do not know about RFID/NFC RC522 Module and MP3 player (pinout, how it works, how to program ...), learn about them in the following tutorials:

Wiring Diagram

Arduino RFID RC522 MP3 player wiring diagram

This image is created using Fritzing. Click to enlarge image

To simplify the setup, the pins of the RC522 module are directly connected to the Arduino pins. However, this direct connection may lead to issues, as the output pins of the Arduino provide 5V, while the RC522 module's pins are designed for a 3.3V operation. It is advisable to regulate the voltage between the Arduino pins and the RC522 module's pins to prevent potential problems. For more detailed guidance, please consult the Arduino - RFID RC522 tutorial. The provided diagram illustrates how resistors can be employed to regulate the 5V to 3.3V:

Arduino RC522 module with voltage regulated wiring diagram

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

The order of pins can vary according to manufacturers. ALWAYS use the labels printed on the module. The above image shows the pinout of the modules from DIYables brand.

Preparation

  • Pre-store a list of songs that you want to play to micro SD Card.
  • Insert the micro SD Card to the MP3 player module
  • Connect the MP3 player module to Arduino
  • Connect the speaker to the MP3 player module to a
  • Connect the speaker to a power source.
  • Connect the RFID reader to the Arduino.

Because UID is usually not printed on RFID Tag, The first step we need to do is to find out the tags' UID. This can be done by:

  • Copy the below code and open with Arduino IDE
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-rfid-mp3-player */ #include <SPI.h> #include <MFRC522.h> #define SS_PIN 10 // Arduino Pin connected to the SS of the RFID reader #define RST_PIN 5 // Arduino Pin connected to the RST of the RFID reader MFRC522 rfid(SS_PIN, RST_PIN); void setup() { Serial.begin(9600); SPI.begin(); // init SPI bus rfid.PCD_Init(); // init MFRC522 Serial.println("Tap RFID Tag on reader"); } void loop() { if (rfid.PICC_IsNewCardPresent()) { // new tag is available if (rfid.PICC_ReadCardSerial()) { // NUID has been readed // print NUID in Serial Monitor in the hex format for (int i = 0; i < rfid.uid.size; i++) { Serial.print("0x"); Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(rfid.uid.uidByte[i], HEX); if (i < (rfid.uid.size - 1)) Serial.print(", "); } Serial.println(); rfid.PICC_HaltA(); // halt PICC rfid.PCD_StopCrypto1(); // stop encryption on PCD } } }
  • Click Upload button on Arduino IDE to upload code to Arduino
  • Open Serial Monitor
  • Tap RFID card/keyfob one by one on RFID-RC522 module
  • Take note of UIDs on Serial Monitor, it looks like below:
COM6
Send
Tap RFID Tag on reader 0x51, 0x3D, 0xC1, 0xAC 0x6A, 0x4C, 0x12, 0x6D 0xB0, 0x1F, 0x92, 0x11
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

We will use these RFID UIDs to update the Arduino code below

Arduino Code - RFID Mp3 Player

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-rfid-mp3-player */ #include <SPI.h> #include <MFRC522.h> #include <SoftwareSerial.h> #define CMD_PLAY_NEXT 0x01 #define CMD_PLAY_PREV 0x02 #define CMD_PLAY_W_INDEX 0x03 #define CMD_SET_VOLUME 0x06 #define CMD_SEL_DEV 0x09 #define CMD_PLAY_W_VOL 0x22 #define CMD_PLAY 0x0D #define CMD_PAUSE 0x0E #define CMD_SINGLE_CYCLE 0x19 #define DEV_TF 0x02 #define SINGLE_CYCLE_ON 0x00 #define SINGLE_CYCLE_OFF 0x01 #define ARDUINO_RX 7 // Arduino Pin connected to the TX of the Serial MP3 Player module #define ARDUINO_TX 6 // Arduino Pin connected to the RX of the Serial MP3 Player module #define SS_PIN 10 // Arduino Pin connected to the SS of the RFID reader #define RST_PIN 5 // Arduino Pin connected to the RST of the RFID reader #define SONG_NUM 3 // 3 songs + 3 RFID cards, change it as your need MFRC522 rfid(SS_PIN, RST_PIN); SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX); byte RFID_UIDs[SONG_NUM][4] = { { 0x51, 0x3D, 0xC1, 0xAC }, // UPDATE THIS VALUE FROM PREPARATION STEP { 0x6A, 0x4C, 0x12, 0x6D }, // UPDATE THIS VALUE FROM PREPARATION STEP { 0xB0, 0x1F, 0x92, 0x11 } // UPDATE THIS VALUE FROM PREPARATION STEP // ADD MORE IF NEEDED }; void setup() { Serial.begin(9600); mp3.begin(9600); delay(500); // wait chip initialization is complete mp3_command(CMD_SEL_DEV, DEV_TF); // select the TF card delay(200); // wait for 200ms SPI.begin(); // init SPI bus rfid.PCD_Init(); // init MFRC522 Serial.println("Tap RFID Tag on reader"); } void loop() { if (rfid.PICC_IsNewCardPresent()) { // new tag is available if (rfid.PICC_ReadCardSerial()) { // NUID has been readed Serial.print("Tag UID:"); for (int i = 0; i < rfid.uid.size; i++) { Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(rfid.uid.uidByte[i], HEX); } Serial.println(); for (int index = 0; index < SONG_NUM; index++) { if (rfid.uid.uidByte[0] == RFID_UIDs[index][0] && rfid.uid.uidByte[1] == RFID_UIDs[index][1] && rfid.uid.uidByte[2] == RFID_UIDs[index][2] && rfid.uid.uidByte[3] == RFID_UIDs[index][3]) { Serial.print("Playing song "); Serial.println(index); mp3_command(CMD_PLAY_W_INDEX, index); // Play mp3 } } rfid.PICC_HaltA(); // halt PICC rfid.PCD_StopCrypto1(); // stop encryption on PCD } } } void mp3_command(int8_t command, int16_t dat) { int8_t frame[8] = { 0 }; frame[0] = 0x7e; // starting byte frame[1] = 0xff; // version frame[2] = 0x06; // the number of bytes of the command without starting byte and ending byte frame[3] = command; // frame[4] = 0x00; // 0x00 = no feedback, 0x01 = feedback frame[5] = (int8_t)(dat >> 8); // data high byte frame[6] = (int8_t)(dat); // data low byte frame[7] = 0xef; // ending byte for (uint8_t i = 0; i < 8; i++) { mp3.write(frame[i]); } }

Quick Steps

  • Copy the above code and open with Arduino IDE
  • Update UIDs you obtained in the preperation step to the above code.
  • Upload the code to Arduino
  • Tap an RFID Tag on RFID-RC522 module one by one
  • Check out the sound from MP3 Player
  • If the everything run smoothly, each RFID card will be associlated with a song.
  • You can mark the name of the song on each RFID card.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES