Raspberry Pi Based RFID Music Robot




A couple of weeks ago, I saw this really cool Raspberry Pi based RFID-enabled cassette player. It ran PiMusicbox and the maker created a module to control PiMusicbox via RFID. This would be perfect for my three year old daughter. Ok, as she's clearly not familiar with cassette players, I needed something simpler. She already had a KNG Andrew MP3-player, that plays MP3's from an SD-card and is controlled via touch buttons. For those who are not familiar with this player, it's simply an SD-card based MP3-player with built-in speakers that looks like a robot.

So, the idea was born, an RFID controlled Raspberry Pi based music robot, or short RFID Music Robot (that's how we refer to it at home). My daughter really loves her music robot, when she wants music, she chooses the tag she wants, holds it near the robot and it will play her favourite music!

Although PiMusicBox is a very easy to install music player for the RaspberryPi with many installation guides, I could not find a guide how to make PiMusicBox respond to RFID's. Therefore, I decided to create something similar to the RFID cassette player. As my Python programming skills are around beginner's level area, building a PiMusicbox module was clearly a bridge too far for me.

That it's not that difficult to connect an RFID-reader to a Raspberry Pi, I learned this from another great instructable: https://www.instructables.com/id/Attendance-system-...

My instructable will show how simple it is to create a Python program that plays music triggered by RFID-tags, so you can make one as well!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials/tools

For this instructable, you'll need the following:

  • KNG Andrew Home Invader
    • Note that you actually only need an amplified speaker to connect to the headphones output
    • So it should work with any amplified speaker with an input that you can connect to the Raspberry Pi
    • For better sound quality, have look at the cool hifi audio DACs
  • Raspberry Pi A+ incl. Wifi Dongle and a micro SD card (4 GB minimum)
    • Note that I needed the smallest Raspberry Pi, so it would fit in the KNG Andrew
    • Any other Raspberry Pi can be used as well
    • Actually, a 'B' might be easier, as you can connect a keyboard and wifi dongle simultaneously (for an A you could use a powered USB-hub of course)
  • Mifare RC522 Card Read Antenna
    • Around $3 on ebay including blank card and key ring tag
  • Extra tags
    • Choose Mifare 13.56MHz tags/tokens/cards
    • You'll need one tag per function / playlist / audiostream / action
      • So, decide for yourself how many you need
      • Currently, I already have 12 tags in use
      • Initially, I figured 5 would be enough
  • Dupont female-female cables
  • Power supply for the Raspberry Pi
    • I used a Micro USB Host Cable Male to USB Female ( < $1 on eBay)
    • A regular Raspberry Pi power supply is also ok, downside is that you most probably have two power supplies, one for the Raspberry Pi and one for the amplified speakers
  • 3.5mm Auxiliary cord male to male
    • To connect Raspberry Pi to the amplified speakers

Tools used:

  • Soldering station
  • Glue gun
  • Drill
  • Screw driver
  • Tape

Step 2: Electronics

The electronics are actually very simple, as there are only four major components:

  • Raspberry Pi
  • MF RC522 reader
  • Power supply
  • Amplified speakers

In the Fritzing diagram, you can see how to connect the Raspberry Pi to the RC522 reader. I connected the two using regular Dupont wires. After making sure all components work as expected (always test the electronics before you put it into a case), I used tape to combine the single headers. This will make it much more easy to reconnect when you glued the components in place.

Step 3: Assembly

The music robot looks quite large on the outside, however, the speakers take up a lot of space. That's why a Raspberry Pi A+ has been used for this build, as it fits perfectly. In the future, I might decide to use the Raspberry Pi for another project, so all connections are made via the regular connectors. The headphones output is connected to the audio input of the KNG Andrew (or any other amplified speaker set). For this, I used a short 3.5mm male-to-male cable and cut off one of the connectors. The wires in the cable are connected to the audio input connector (black is ground, white left channel, red right channel). Note that the tip is the left channel, the middle the right channel and last one is the ground.

A very short micro-USB to USB cable provides power to the Raspberry Pi. With a sharp knife, I cut open the regular USB connector, so I could connect wires to the power pins. As the KNG Andrew is powered via a regular (mini-) USB connector, it was very simple to find a +5V and GND on the internal KNG Andrew PCB.

There was not enough room in the belly of the music robot to simply connect the audio and power connectors. Therefore, two holes at the top should fix this issue (so the rest of the connector/cable ends up in the head of the robot). Using a permanent marker to indicate the exact spots for the holes, made it easier to drill the holes. As I didn't want to make the hole too large, I started with a small drill bit and used larger drill bits until the hole was large enough.

The RFID reader is glued in place with a glue gun. Note that the header is soldered on to the back of the reader. This makes it possible to put the reader the closest to the outside as possible. Then, connect the taped Dupont wires to the reader and the other ends to the Raspberry Pi. Last steps are gluing the Raspberry Pi in place, connect the audio and power connectors and close up the case!

Step 4: Installing the Raspberry Pi

First of all, you need a recent version of Raspbian installed to the Raspberry Pi.

In the raspi config, activate the audio output via headphones and enable the SPI interface (both can be found in the Advanced options menu).

Make sure the Raspberry Pi is connected to the internet. For setting up a wifi connection, please check the following link.

It's always good to be up-to-date, using:

sudo apt-get update

For installing Python modules, the development packages are required:

sudo apt-get install python2.7-dev

For the MFRC522-python interface, SPI-Py has to be downloaded and installed:

git clone https://github.com/lthiery/SPI-Py

Enter the SPI-Py directory and install it via:

sudo python setup.py install

Next up is the MFRC522-python module:

git clone https://github.com/mxgxw/MFRC522-python

Enter the MFRC522-python directory and install it via:

sudo python setup.py install

Finally, as this solution is made around mplayer, you'll need mplayer of course:

sudo apt-get install mplayer

Please check whether mplayer works fine on the Raspberry Pi when it's connected to the speakers.

Step 5: RFID Enabled Player

In the previous step, MFRC522-python was cloned. This resulted in a new folder named MFRC522-python. Put the rfidmp3player.py file into this folder. Make sure the file is executable:

chmod +x rfidmp3player.py

One of my tags makes the robot tell it's IP-address (or the time, or what ever sentence you like). For this, I use festival, a very simple to use text-to-speech program. You can install it on the Raspberry Pi using:

sudo apt-get install festival

This is a good moment to try whether the rfidmp3player script works. For this, mplayer should be in slave-mode. And to be able to control mplayer, a named pipe is required. What the rfidmp3player program does, is write commands to the named pipe. To test the script, this is what you'll need to do:

sudo mkfifo /tmp/mplayer-control
sudo mplayer -slave -input file=/tmp/mplayer-control -idle
sudo ./rfidmp3player.py

Now, when you hold (a Mifare) RFID-tag to the reader, the Python script will show it's card ID. This ID is an array of 5 integers. In the screenshot, you'll notice that the tag I used for my testrun, triggered an audio stream. What a RFID-tag triggers is defined in the rfidconfig.txt, which will be explained in the next step.

As -in my setup- no screen or keyboard is connected to the Raspberry Pi, it's important that rfidmp3player.py is started from startup. Edit /etc/rc.local (don't forget sudo for this) and add the following before the exit 0 statement:

# Create named pipe for mplayer
mkfifo /tmp/mplayer-control

# Start mplayer in slave mode
mplayer -slave -input file=/tmp/mplayer-control -idle &

# Tell host IP
hostname -I | festival --tts # Start Python RFID-reader-mplayer-control script
/home/pi/MFRC522-python/rfidmp3player.py &

The 'hostname -I | festival --tts' statement will read the current IP-address out loud. This helps you in two ways, first, you know the IP-address to connect to and second, you know that the Raspberry Pi is now up-and-running!

Step 6: Rfidconfig.txt

All RFID triggered actions are defined in the rfidconfig.txt file.

Each RFID tag has the following attributes:

[aaa,bbb,ccc,ddd,eee] Unique tag Id
Description:Description, so you know what this tag should trigger
FileUrlFunction:This is either a file (single file or playlist), URL or function (for either mplayer or OS)
ActionType:Either OS, URL, File, Playlist or Function
TagType:This is actually ignored. I simply numbered my tags with a permanent marker and then I entered that number in this attribute.

Example rfidconfig.txt file can be found below.

ActionType: OS
Use OS for triggering an activity on your Raspberry Pi. Please note, that the commands will be run as root, so be careful! Use this action type for letting the robot tell it's IP address, telling the current time or shutting down the Raspberry Pi.

ActionType: File / URL
Simply put the location of a media file or stream. Note that you cannot use relative paths, so include the full path for a file.

ActionType: Playlist
Simply put the location of a playlist. Same as with a file, provide an absolute path. Within the playlist, you can use a relative path.

ActionType: Function
Use this for sending a specific command to mplayer. For all commands, please check https://www.mplayerhq.hu/DOCS/tech/slave.txt
Examples are: pause, pt_step 1 (next song in playlist) and pt_step -1 (previous song in playlist)

Step 7: Enjoy!!!

Now it's time to enjoy your RFID-music player! Initially I just wrote a number on each tag, but that's not very helpful for a three year old. So, I pimped the tags with nice stickers, using a label writer.

You could also crack open a tag and put the actual RFID-antenna and IC into an object, for example a CD case! How cool would it be to just simply hold a CD case to the reader and the music of that CD's starts playing?

As the range of the reader is not that good, I put a sticker with an RFID-logo on the outside of the robot. This is also the only change to the KNG Andrew you can see from the outside. All standard functions still work, so I can play MP3's from an SD card and also use the robot as speakers for phone. This may look like a 'clean hack', which is a good thing. However, when I demo it, not everyone is convinced that the RFID functionality has been added by me... :-)

Ok, at night, you can see the red reader LED through the white plastic.

The best thing is that my daughter loves it and I hope you like it too!

Raspberry Pi Contest

Second Prize in the
Raspberry Pi Contest

First Time Author Contest

Participated in the
First Time Author Contest

Remix 2.0 Contest

Participated in the
Remix 2.0 Contest

1 Person Made This Project!


  • Assistive Tech Contest

    Assistive Tech Contest
  • Reuse Contest

    Reuse Contest
  • Made with Math Contest

    Made with Math Contest

29 Discussions


3 years ago

Hey there, thanks for a great instructable... just setting up a system including elements of yours... struggling with mplayer though...when setting up the slave mode, it complains about not being able to open two files: .mplayer/input.conf in my home directory and /etc/mplayer/input.conf. Any ideas?

I am running Jessie (Raspbian 8.0) on my Pi so when I installed mplayer it automatically installed mplayer2 - should not make a difference I hope but just in case.

Thank you and best regards,


6 replies

Reply 3 years ago

me again... I discovered that mplayer has been discontinued. Hence I am now using VLC for my purposes... have fun building everyone!


Reply 3 years ago

Hi, I actually have the same problem with the mplayer. Could you help me getting the vlc player to work? What did you change in your software setup? Thanks so far


Reply 3 years ago

Hi there, I am planning to publish my setup as an instructable as well... but not sure when I will get around to it. So a bit of help here to get you started: you have to get the python VLC Library and stick the files vlc.py and vlc.pyc into the same directory as your program (https://pypi.python.org/pypi/python-vlc/1.1.2). Then you need to call VLC instead of sending commands to mplayer. Important commands are:

import vlc # import the library
player.stop() # use this to stop a file being played (player needs to
# be initialised once first with the next command)
# tell the player which file... you need to call this once
# before calling player.xxx() to initialise the variable
player.play() # play the song you assigned to the player earlier.

Please send me a personal message with your email address if you would like me to send you my python program.

I hope this helps. Good luck!


Reply 7 months ago

Hi there, do you still have the python program?


Reply 3 years ago

Hi there. I finally solved the mplayer problem by compiling an old version - the 1.1 mplayer. The codec and program dependencies where horrible and the compilation time on the RaspberryPi is almost endless (approximately 5 hours per run). But now everything works! If anyone needs help just send me a pm and I can give advice. Regards, Markus


7 months ago

Very nice project!
I am attempting to use your instructions and code here. So far I can make the thing actually play something.
However currently it seems mplayer only is able to play mp3 files. Playlists and url's seem to be non-functional completely.
Is this actually working in your setup, or has something changed in mplayer's slave mode?




1 year ago

nice post man, i had a problem when i run this command

sudo mplayer -slave -input file=/tmp/mplayer-control -idle

maybe you can know the reason of that, thanks.

1 reply

Reply 7 months ago

Hi ElmerF9,

I had the same issues, turns out that on raspian, lirc is expected to be "on".
Start with: mplayer -slave -nolirc -input file=/tmp/mplayer-control -idle
That should get you up and running!


Question 9 months ago on Introduction

Hey Roald, nice work. I got one question about this setup: Does the original SD-Card MP3 player still work after the raspi was built in?

1 answer

Answer 8 months ago

Well, it should still work fine, as I've connected the Raspberry Pi to the audio input. It's the same as when you would connect your phone with a 3,5mm connector to the speaker (but I did it internally, so it looks nice. ;-)


2 years ago

i make the robot like yours, but i can't open playlists.
in the "rfidconfig.txt" i put


Description: Frozen Soundtrack

FileUrlFunction: /home/pi/music/playlists/1_2_3_Wir_singen_mit.pls

ActionType: Playlist

TagType: Tag_3

and the raspberry says:

Playing /home/pi/.....mp3.

File not found: '/home/pi/.....mp3'

Failed to open /home/pi/.....mp3.

Can someone help me please


3 years ago

So in Step 4 it says Enter the SPI-Py Dir and install it via Sudo python setup.py.

But there isn't a file in the dir...

Any suggestions?

2 replies

Reply 3 years ago

Didn't the git clone command create a folder containing a number of files?

You can visit the url with a regular browser and download the files manually: https://github.com/lthiery/SPI-Py


Reply 3 years ago

Sorrry, my bad it is the git clone https://github.com/mxgxw/MFRC522-python that doesn`t contain a setup.py file.


3 years ago

Thank you for this great post! I guess I should use this table for the RasPi3 GPIO, right? Thanks



4 years ago

Just simple and cool idea.


4 years ago on Introduction

Cool! All 3-year-olds must be jealous of your daughter ;-)

It is a very nice project - it looks like you just bought it like this. Nicely done! Looking forward to your other project(s).

1 reply