Hacking MP3 Players – Adding sound to Arduino

I’ve been wanting to add sound to quite a few of my projects, and have always found it way too cumbersome, too expensive or too expensive to add sound to my installations / projects, so a little while ago, I decided to try and hack a cheap MP3 player ( purchased from a roadside vendor) and trigger it from my Arduino to play pre-recorded MP3 tracks in sequence.

Here’s a picture of the MP3 player I am talking about, and what it looks like when opened up :

MP3 Player MP3 Player MP3 Player hacked

How the MP3 player works :

The MP3 player has 5 buttons: Play/Pause, Next, Previous, Volume Up and Volume Down.

As shown in the image below, each button consists of two pads, an inner pad and an outer pad. There is a metallic contact like a dome, covering the two pads, but not making contact. When you press the button, the metallic dome touches both path simultaneously and causes them to “short”. A short lasting for about 70 milliseconds will cause the action associated with that button to trigger. Note that a “short” of a small duration will not cause any trigger, and one of very long duration will cause multiple triggers, so it is important to time the delay right.


Each of the 5 buttons therefore has two pads, which must be shorted to trigger the five actions available. However, note that the pads on all the buttons are not unique i.e. there aren’t 10 unique pads, but merely 4 unique pads, scattered in different unique combinations. These 4 pads lead to 4 pins on a 16 pin IC, which I have drawn in the illustration above. The pins used are 6,7,8 and 16. To begin hacking the MP3 player, we must first solder 4 wires, either from the pads or from the pin on the IC (I find the latter easier), and extend them into multiple pinouts, so we can use them later.

In the illustration above is a table, which is a mapping of the combinations of wires which must be shorted for each action. So, to cause the MP3 player to pause/ play, we must short the pads / wires linking to pin 7 and 8 on the MP3 IC.

When we touch the buttons, those actions are easy enough to trigger. The question is, how do we short two pins (of which none might be ground), so as to simulate the MP3 function ? The solution is simple, really, we use relays. A relay is nothing but a mechanical switch that flips one way when powered on, and flips back when powered off. This is because each relay (drawn in the illustration) has a coil that creates a magnetic field when powered on, which flips a switch mechanically. The “COM” terminal which is normally connected to the “NC” (normally closed) flips and makes a connection to “NO” (Normally Open) when powered on, and we can use this to short a wire connected to COM with a wire connected to NO. Thus, each relay will short _two_ pads when powered, and will correspond to one pin on the Arduino that will power it on.

So, we’ll use a digitalWrite call from an Arduino to switch “ON” the Relay coil, thereby causing the wires to short. There is a slight problem, though. Chances are, your relay won’t trigger with the 5V that the Arduino supplies on its digital pin, and you’ll need to raise it to a level of 9V or 12V to trigger the relay coil. So, we’ll need to a buffer in between, here I have used the ULN2003. The complete arrangement for one MP3 function is mentioned in the illustration above.

This should mainly cover how to go about hacking the hardware of an MP3 player to work with an Arduino Uno. However, to make things a little easier on the Arduino side, I also wrote a simple library that lets you control the MP3 player just by specifying the pins on the Arduino that are connected to each relay.

Here is the link to the Github for the MP3 player library : https://github.com/ankitdaf/MP3Player

In the call to MP3Player, you just need to specify in the brackets which pins are connected to the relays corresponding to (Play , Next, Previous, Volume Up, Volume Down ) in order, and you should be up and running in no time !

If you are using only one button, you might want to skip the ULN2003 and use a simple transistor as switch instead as shown here (http://makezine.com/projects/arduino-mp3-player-hack/), but if you are going to use more than one button that is not advisable, since one of the pins that are shorted go to ground of the Arduino, and if you use another button with a different pad going to ground, those two will continuously trigger, messing up with your flow and possibly messing up the player itself.

If you have any questions, you can write to me at me@ankitdaf.com and I’ll be happy to help you out !

If you want to go get some Arduino supplies, you can get it from here : http://daflabs.com/

Cheers, until the next hack !

Data Visualization – GPS logs from Google Location History

It’s been 10 days since I am back from a 5 month stint in Europe, and its 10 days to move on to my next stint (more on that very very soon 😉 ). Being in Mumbai has its perks, with the alma mater, friends, vada pav and Marine Drive being high points. However, 20 days of doing nothing can really get to you, and you need to keep on doing something just to keep sane.

I had wanted to do a data visualization project for quite some time, and I had always wondered what data I could use. Being back from Europe and having travelled a few cities, and owning a tablet, gave me the spark I was searching for. I had 5 months of GPS data (recorded automatically by my trusty companion, the Nexus 7) logging my travels. That amounted to 73,000 recordings, spread over 5 months, 6 cities and a lot of geography.

Well, Google Location History exported all the data to a KML file readily enough, and there I hit the first hurdle. Too much data. I had data from all over, starting from India to my transit there via the Middle East, and those points just seemed like “outliers” (data which was much different from the rest). So, before I got around to plotting anything, I figured I ought to delete some data, and I set about to do it. Unfortunately, the KML exported by Google Location History isn’t exactly the most beautiful.  Data is split across two lines, one with time and one with co-ordinates, and needs a bit of work to be made into CSV, so one can do some mathemagic with the numbers. So, what do you do ?

I learnt vim. I went and talked to a friend, and showed him what I was doing. He fired up vi, typed in a few commands, and there was my data for one city, all cleaned up and ready to be analysed. So, I went home that night, fired up vimtutor, and learnt vim. Totally worth the two hours I put into it.

Discussing what I was doing also helped me brush up statistics and algorithms. Lots of ways come to mind about ways to “cluster” the data. Since a lot of points were pretty much the same location, with all the quirks of GPS measurements, they could be replaced with just one point. Additionally, I could take a city’s data , combine it with my knowledge of my walk in the city, and use k-means clustering to cluster it into a few places that I hung out. That raised the question, did I really want to cluster the places, when the aim I had in keeping logging turned on was to record everywhere I had been and to later see and show all the streets that I had walked ? Ought I just show all the data points, or would it be nicer to show the path I followed, step by step, and with insights into how much time I spent where along the way, maybe for some other traveller looking for something like I had ?

Too many questions, or rather decisions and tests to make, and not too many answers. So, while I figured it out, I went ahead and plotted a few of the cities I visited on a map, using Google Fusion Tables (incredibly easy and handy). Here are a couple of those maps, until I decide to (and/or) finish this project. And if you want to play with this dataset yourself, you can get it here : http://imojo.in/gpsdataset

Also, some terms that you might like to look up, that I came across while working on this : [ clustering, k-means clustering, elbow method, visual block mode in vi, Manhattan distance, curse of dimensionality, forward difference, second forward difference, normalisation, outliers ]