Introduction: RFI-DJ: MP3 Playing RFID Thing

About: I am a human being that enjoys to build things. I also say GNU/Linux instead of just Linux. Yeah, I'm that kind of person.

The RFI-DJ is a USB device for playing MP3 files from your computer. You have a set of RFID cards, each one with a song name written on it. You choose a card and place it on the RFI-DJ, and your computer will play that song. Its magic!

Actually, it's not magic. It uses an Arduino and an ID-12 RFID scanner, and a python script running on your computer.

The device is really fun to use, and it makes a great afternoon project. The parts it uses are owned by most DIY people, and if you don't have them, they're pretty cheap and easy to find. The number of tracks it can play is severely limited to the number of RFID tags you have, so don't plan on throwing away your i-pod.

Wait a minute, I think I've seen this before...
Yes, unfortunately, you have. After starting on this instructable I discovered that somebody had already done something very similar, which can be found here. There are still many differences in his approach, such has that his is not USB, it is standalone, and his is much bigger and is more difficult and time-consuming to make. His is also based off of an i-pod.
Also, this project was inspired by this instructable. I probably wouldn't have thought of this without it. It's basically the same thing, but that one was with websites, not songs.

Here's a video I made of me playing a song with it (with my cat yelling in the background):



How it works:
An RFID scanner scans your card.
An Arduino processes the reading.
Based on the reading, the Arduino sends a letter to the serial port.
A python script reads the letter, and plays a song based on what letter it receives.

Step 1: Supplies

Here's what you need:
1 Arduino
1 RFID Reader
1 RFID Reader Breakout
Many RFID Tags
1 Computer
Some MP3 Files (Don't pirate them, please.)
Wire

Optional:
1 LED
1 Box of sorts (I used a cereal box)

Step 2: Download ALL THE THINGS!

You have a lot of things to download. Okay, just two, but it felt like a lot when I was downloading them. Here's the list, complete with installation instructions:

pySerial - A python module for serial communication.
It can be found here.
1. Download and extract.
2. Use "cd" to change your directory to the pyserial folder.
3. Use "sudo su" to change into root. (Use your root powers for good, not evil)
4. Run "python setup.py install" to install it and stuff.

mpg321 - A program to play MP3 files and such.
1. Run "sudo apt-get install mpg321" and type in the root password.
To test:
2. "cd" into the directory of an MP3 file.
3. Run "mpg321 [mp3filename].mp3" and it should be working.

Step 3: Wire Up RFID Reader

Solder the RFID reader to the breakout board. Then, wire as follows:
RFID reader pin 1 to ground.
RFID reader pin 2 to 5v.
RFID reader pin 11 to 5v.
RFID reader pin 10 to LED. (Optional: for debugging purposes. Will light up when a card is scanned.)
RFID reader pin 9 to Arduino pin 6.
RFID reader pin 7 to ground.

Done!

Step 4: Prepare Box (Optional)

You should now take the time to prepare your box. A standard cereal box works great when cut in half and wrapped in duct-tape. Then you should insert your Arduino and RFID reader. Trace an RFID tag over the reader on the box. Feel free to draw any artwork you want on the box.

Step 5: Figure Out RFID Identifiers

Run this code:

#include <SoftwareSerial.h>

SoftwareSerial RFID = SoftwareSerial(6, 7);

void setup ()

  Serial.begin(9600);
  RFID.begin(9600); //Begins connection with the reader
}
char read;
void loop ()
{
   while(RFID.available() > 0)
   {
      read = RFID.read();
      Serial.print(read);
   }
}

While that code is running, open up the serial monitor. Now, scan some cards, and write down the characters that show up in the serial monitor. Write letters (such as 'a' or 'b') on each card. Make sure each card has its own letter. On the same paper you wrote down the IDs, write down the letter associated with that ID.

Step 6: Arduino Code

This is the BRAND NEW, SUPER AWESOME code that I used for my RFI-DJ, or it's at least more brand new, and more super awesome than when I first posted this instuctable. You must edit some lines to make it work for you.

#include <SoftwareSerial.h>

SoftwareSerial RFID = SoftwareSerial(6, 7); //RX is 6, TX is 7
String key; //The key that was scanned

void setup ()
{
  Serial.begin(9600);
  RFID.begin(9600); //Begins connection with the reader
}

char read; //The most recent character read

void loop ()
{
   while(RFID.available() > 0)
   {
      read = RFID.read();
      key += read;
      if(key.indexOf("4F0088AE355C") >= 0) {Serial.write('a'); key = "";} //Change to the ID of your key a
      if(key.indexOf("4F0088D4FCEF") >= 0) {Serial.write('b'); key = "";} //Change to the ID of your key b
      if(key.indexOf("4F0088FAFCC1") >= 0) {Serial.write('c'); key = "";} //Change to the ID of your key c
      if(key.indexOf("4F0088DA978A") >= 0) {Serial.write('d'); key = "";} //Change to the ID of your key d
      if(key.indexOf("4F0088F9E1DF") >= 0) {Serial.write('e'); key = "";} //Change to the ID of your key e
   }
}

Change the lines it says to change, and it'll work.



Step 7: Python Code

Here is the python script that I used:

#!/usr/bin/python

import os
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0) #First argument should be changed to your serial port, second should be your baudrate
while 1:
  x = ser.read() #Reads serial port
  if x == 'a':
    os.system("mpg321 come_together.mp3") #Change to your song a
  if x == 'b':
    os.system("mpg321 jumpin_jack_flash.mp3") #Change to your song b
  if x == 'c':
    os.system("mpg321 hey_jude.mp3") #Change to your song c
  if x == 'd':
    os.system("mpg321 my_generation.mp3") #Change to your song d
  if x == 'e':
    os.system("mpg321 stairway_to_heaven.mp3") #Change to your song e


Change that lines it says to change, and you'll be set.

Step 8: Playing Multiple Files at a Time

The python script shows how to play one song per card, but what if you want a certain card to play a full album? Or what if you want to play a certain playlist? The code can be easily changed to play a whole list of songs, and it is actually quite simple. First, you need to make a "list". Make a blank document and name it "playlist.lst". It could really be named anything ending in ".lst". In the file simply make a list of the songs you want to be on the playlist, such as:
asong.mp3
anothersong.mp3
yetanothersong.mp3


And that's all that needs to be in the file.
Change one of the os.system("mpg321 come_together.mp3") lines to:
os.system("mpg321 --list playlist.lst")
and it'll work now! The list can contain all the songs in an album, or all the songs by an artist, or it can even contain more lists!

Step 9: Use It!

You have now finished making your RFI-DJ. To use it, you must do the following:
Label your cards with the song that they correspond with.
Plug the device into your computer.
Open up terminal, and change you directory to the directory of your python script. (Make sure that that's also the directory of your music)
Run "./rfi-dj.py"
Scan a card.
The song should instantly play!

If you have any questions, comments, or angry rants, feel free to post them in the comments section. I'll try to get back to you quickly.
Have fun and happy music-listening!