ELM Home Page

Motion Controlled MP3 Player

January 19, 2008

Photo 1

This is the third MP3 player project in succession. In this project, I designed it as a simple and small audio player compared to previous large scale graphic MP3 player project and implemented an additional strange gimmick. The MP3 player does not have any buttons nor dials that shown in right photo and it has an acceleration sensor instead of the mechanical switches. Therefore all playback commands to the player are given in defined motions, such as inclination, tilt and shock. The player detects the motion with the built-in acceleration sensor and recognize it as a playback control command. As the result, it came to not seem an audio player in appearance.


Figure 1. Block Diagram
Figure 1
Figure 2. Circuit Diagram

Figure 1 shows the block diagram, Figure 2 shows the circuit diagram and the followings describe the functions of each part.


An Atmel AVR microcontroller that my favourite MCU family is used for embedded controller. The controller chip chosen for this project is ATmega644. It has large memories (64K bytes flash memory and 4K bytes RAM) considering its pin count. The operating clock source is internal 8 MHz oscillator.


A KXM52-1050(Kionix) ultra small (5mm sq.) 3-axis acceleration sensor is used. The working acceleration range is ±2G but it is too high sensitivity for this purpose. Especially the working range for direction of lower (it is most significant) becomes only 1G due to an offset by gravity. If output voltage is saturated, the acceleration cannot be integrated with accurate so that any consideration may be required to the motion analyzing process. ±5G will be proper for this use when any other one is selectable.

Recording Media

SD Memory Card is the de facto standard in flash memory card. It can be attached to the microcontroller via a few signal lines. FAT format is used to store data files in it so that the project using the memory card must implement the FAT file system. Fortunately, there are various FAT libraries on the web as freeware so that everybody can use the memory card in their project with ease.

Power Supply

Because the MP3 player is a portable equipment, it has two RCR123A(3.6V, 650mAh) Li-Ion cells in parallel for power supply. The playback time became approx. 20 hours when fully charged but it depends on the volume. To avoid risk of fire, the charging and discharging of Li-Ion cell must be controlled properly so that a BQ2057C(Texas Instruments) Li-Ion charger and a voltage detector MN1382SLP(Panasonic) are used for control circuit to protect Li-Ion cells.

The main power is switched with a media detection contact of the memory card socket. When a memory card is inserted into the socket, the power is on and start to playback, and remove the card to stop. The voltage from cells (3.5-4.2V) directly is distributed to power amplifier and regulated voltage (3.0V) is for controller.

Decoder and Amplifier

To decode MP3 audio data stream into PCM data, I used a VS1011e(VLSI Solutions) which integrates a DSP, a D-A converter and a headphone amplifier on a chip. It can be obtained easy and can achieve decent audio performance. It is often used as many as ST's STA013 for home-built MP3 projects. The drive capability of built-in headphone amplifier is insufficient to drive loudspeakers so that I put an external power amplifier after the decoder chip. The loudspeakers are driven with a high efficiency D-class audio amplifier TPA2012D2(Texas Instruments).


The MP3 player is built into an existing PC speaker which is separated in left and right channel. I built it whole functions in the right speaker. When left speaker is disconnected, left audio channel is automatically mixed to right channel as a monaural output.

Building MP3 player

Building a case

Photo 2.Post process to the case
Photo 2

I chose a PC speaker MS-77 manufactured by Elecom for this project. It is separated in left and right channels and the amplifier was built into the right one. To built the MP3 player into the case, open the case and remove the amplifier. The rear panel was fixed in ultrasonic welding. I drilled some holes to the rear panel, and pulled and remove it. The internals are held by only rear panel and there was nothing to fix inside the case so that I bonded four studs to the corners to fix a rear panel (Photo 2a). A slot (2.5 x 25mm) is required on the case to insert a memory card. Because the material is acrylic resin, it should work with care of crack and chip (Photo 2b). The indicator lamp (two color chip LED) is embedded into a hole that drilled at bottom of the case.

Building Circuit Boards

Photo 3. Built Circuit Boards
Photo 3

The inner dimensions of the case to build the MP3 player in is already determined because an existing case is used. The circuit boards and Li-Ion cells to be embedded are laid out and composed like shown in Photo 3. The effective inner dimensions becomes pretty tight due to a jut out of loudspeaker. Figure 3

To wire on the circuit board, UEW (urethane enameled wire) that I usually use is used. However this MP3 player is always tapped due to its control method so that any fixable may be required to prevent disconnection of the wire. The composed circuit boards are fixed to the rear panel (FR-4 plane PCB) and it is fixed to the studs.


Track Management

Figure 3. Directory Tree
Figure 3

The audio tracks are managed in unit of album which is a sub-directory placed at the root directory like shown in right image. Maximum number of albums is defined to 50, and number of tracks (.mp3 files) in an album is 99. Each albums and tracks are sorted in their file name.

The FAT file system used in this project does not support long file name, however it can access the files with alternative short file name (8.3 format). The files can be sorted correctly even if named in long file name, by numbering the files in heading two numeric characters. When a playlist (.m3u file) exists in the directory, the listing order follows the play list. In this case, the file names listed in the play list must be short name.

Playback Control

After power is on, the playback control routine scans all directories placed in the root directory and registers valid albums into the album list. When there is no change to the memory card, resume from interrupted track at previous stop. If any difference is detected, it starts from the first album. When it finished to play a last track in an album, which track is played next, first track in current album or next album, is depends on the loop mode (all tracks or within an album).

The data transmission to the DSP is done with the f_forward function extended to the FatFs module. It is similar to the f_read function but a pointer to the data transmission function is specified instead of a data buffer. Therefore it can transmit the audio data to the MP3 decoder without temporary storage.

Power Management

The media detection contact of the memory card socket controls the main power. After a card removal, there is a delay time about 100 milliseconds until power down. When the card removal is detected, the playback control saves current settings and playback state into the non-volatile memory.

The cell voltage is always checked and the status is displayed to the LED. When the voltage lowers below 3.65 volts for a time, low battery status is displayed. When the voltage lowers below 3.4 volts, the player enters shut-down state.

Motion Detection

This is the most important function of the MP3 player. It is driven in timer interrupt process. Each outputs from the acceleration sensor are sampled in frequency of 2000 Hz and analyzes the motion from detected vector and its change. In this project, six different motions are discriminated and sent it to playback control task as playback command like NEXT, PREV or PAUSE.

How to Use

When a memory card is inserted, power is on and start to playback. To stop to playback, remove the memory card. The playback control commands are given in motion applied to the player that described below. You might not understand clearly with only the sentence so that please refer also the demo movie.

Next Track
Tap right bottom corner on the desk and go to next track. When last track in the album is playing, which track is played next follows the loop mode.
Next Album
Enter two Next Track commands within 400 milliseconds and go to first track of the next album.
Previous Track
Tap left bottom corner on the desk and go to previous track. When first track in the album is playing, which track is played next follows the loop mode.
Previous Album
Enter two Previous Track commands within 400 milliseconds and go to first track of the previous album.
Lay down this side and put it front down. Put normal direction to resume.
Volume Up
Increases volume while tilted right.
Volume Down
Decreases volume while tilted left.
Set Loop Mode
Tap on the desk at Pause state. One tap sets all loop mode and two taps sets album loop mode. When the command is accepted, the green LED flashes one or two times.

Correspondence of LED and Status

The current status is displayed to the LED lamps embedded bottom of the case.

Green (continuous)
In playback.
Green (blink)
In pause. This status while playback means low-battery.
Red (continuous)
Charging. When lit with green LED, it looks yellow.