Picture of Music Playing Alarm Clock

This Instructable will be about designing a music player from using various building blocks. You will understand the communication between the microcontroller, memory, computer, LCD display, RTC, IR remote, and the music file decoder. I will try my best to to teach you in a way so that you can design your own projects using the skills you learn, without blindly following instructions.

I know most of you will simply glance at this first page and maybe skim through the rest. This Instructable has 18 steps and 5 appendices, with about 90 files and pictures. I sincerely hope you explore all my efforts.

Every step will be accompanied by a demonstration of that particular building block working. The source code will be provided. I will post the debug output, pictures, screenshots, USB device and packet analysis, and logic analyzer waveforms. NOTE: if the images look too compressed, don't worry, they are included inside my .ZIP files too.

To start off the project, set your goals. This will be a simple proof-of-concept music player. It will allow the user to load music as through USB as though it is a mass storage device, display the current song to the user, display the current time, set custom alarms for every day of the week, and allow the user to control it through a remote control. To accomplish these goals, you need:

* USB capable microcontroller
* LCD display
* Storage
* Sound output
* IR receiver and remote control (any)

This is the obvious overview, however, we also need a RTC (real time clock) to keep track of time using a backup battery, just in case the power goes out.

Note that with my collection of supplies, budget, and skills, I've decided to use a VS1033D decoder IC from VLSI Solutions, which integrates music file decoding and digital-to-analog output. So the item "sound output" in the above list expands into "decoder" and "speaker"

I will be using the following components during this Instructable (this is not a full part list, not even close, but these are major):

AT90USB1286 microcontroller (on a Teensy++ http://www.pjrc.com/store/teensypp.html ), datasheet is here: http://www.atmel.com/dyn/products/product_card.asp?part_id=3874
VS1033D music decoder http://www.vlsi.fi/en/products/vs1033.html on a breakout board http://www.sparkfun.com/products/8792
16x2 character LCD display, ST7066/HD44780 compatible, using 3.3V instead of 5V
DS1307 real time clock

Note that the entire circuit will run off 3.3V, if you are buying a Teensy or Teensy++, please buy http://www.pjrc.com/store/mcp1825.html and follow the correct procedures to solder it and use it (it involves a jumper). Please also note that you must also run the Teensy at 8 MHz instead of 16 MHz because of the reduced voltage.

I also hope that once you are done, you'll be able to apply the skills you learn here with other microcontrollers and devices.
1-40 of 76Next »
LukeR71 month ago

Alright I found my problem. It is with the hardware initialization. I can init the USB but the mcu stops when it goes to do the SDCardManager_Init();

Anyone else have this issue? Any idea what could be wrong? I have the SD card wired up according to the wiring picture above... Maybe im missing a library? but then i would expect a compile error and that is not the case...

Any ides out there? Thanks for your time.

LukeR71 month ago


Hello Frank, great tutorial here. I am focusing on the usb mass storage device section. I have the hex file generated and loaded onto my teensy++. Now what? Should my computer automatically treat the sd card as a MSD? Or do I need a scuzzy program in order to talk and get data off of the SD card? Please clear up how your USB MSD code is operating and how the computer recognizes and talks with the Sd card. Thank you for any help.

PS if any one else understands what needs to happen here I would greatly appreciate your 2 cents :)

SarahW310 months ago

I tried to compile the decoder_demo file you got here unfortunately there errors and can't be compiled.I am using studio 6.2. Can you please help me.

ankitdaf10 months ago

This is a brilliant tutorial, very well done and very thorough. Thanks a ton for this !


This project is AMAZING! Thank you for the documentation. It is inspiring. You are the only person that gives me hope that I could have the SD card in my ATmega32U4 based Arduino exposed as a Mass Storage Device. I'm a total beginner at hardware and any help you could offer would be GREATLY appreciated, praised, and credited.

What can you suggest I do to get your LUFA MSD into an ino? Unfortunately I'm pretty tightly bound to the IDE as I am not a C[++] programmer. (Quite a pain since I do all my coding in VIM!)

erthyop11 months ago

Hi Frank

I've been through your whole tutorial and have a working music playing clock. I would just like to say thank you for making this guide I really appreciate the time you've put into this and I have learned so much. Once again thanks and good luck for the future!

ahonda552 years ago
I have been trying to understand the technique of writing and reading, and the address of the RTC chip and so much, just now I got it.
Great work :)
Really, thank you a million :)
Greetings and keep the good work to make the planet better :)
NGamaya2 years ago
The-Rex3 years ago
chrwei3 years ago
what's the highest bitrate mp3 you've been able to smoothly play on this?
frank26080115 (author)  chrwei3 years ago
I think it can do 128kbps
but have you tested? There's theory and math, and then there's actual real world performance. Sometimes real world is better than the math, especially when dealing with human perception, and sometimes it's far worse.
chrwei3 years ago
Sparkfun seems to have fixed their VS1033D breakout board now, so hopefully Step16 is no longer needed for new builds
woow3 years ago
Hey, sorry for bothering you again:(
i am currently using a mbed to program the alarm clock, and I have successfully decode one song from sd card. Just wondering how can you decode the name of the song so the mbed can decode any song that I put in through USB. Currently I am using code like ' fopen("/sd/mp3/test1.mp3","rb");' so the title of the song must be test1. Thank you very much:)

Hello, I have purchased all parts for this kit and progressing on it. For IR Code Capture I am getting problem and stuck since very long time. Even for £1 valued IR diode I have spent £16 and for remote controls I have spent £40. I would appreciate if any body can guide me for Remote Control. Where can I get intented remote control (make / web link).

Please help. Your help is highly appreciated.

Best regards,
frank26080115 (author)  ankush_karche3 years ago
You are supposed to be able to use any remote control. Nobody sells the remote control I used.

You are supposed to try it out, and if it doesn't work, figure out why it doesn't work, and fix the problem. So what is the problem? What do you expect to see? What do you see instead?
Hello Frank,

I am using codes given by my remote controls in IRCodeInterpret module but not matching with and just displaying message Checking .... on Realterm.

As described by you, remote control should display same pattern that's what not happening.

Any other ways to overcome this problem ?

Please help.

Best Regards,
Hi Frank,

Thanks for your response. I am getting codes with IRCodeCapture module but each time for same button pressed on remote control codes displayed are different.

I put these codes in IRCodeInterpret module and check it. I get output on RealTerm screen as checking..

When I put ircodes in header file and check interpret module then I should get which button is pressed on remote control. But it is not showing due to codes not matching.

Hope the problem is resolved with your help.


xp3093 years ago
Great project! really helps a lot. I just got couple of questions wanna ask you about. Firstly if i decided to use an arm micro-controller, i would not need to use a music decoder right? Instead I need a DAC?
Secondly, how do u decide what size of RAM and frequency u need]?
Thirdly, is sd card originated formatted in fat16 and what does fatfs do exactly (the difference between it and fat16) ?
Lastly,why do you choose ADR instead of ARM? Is 8 bits AVR gonna be fast enough for playing mp3 file?
Cheers and look forward to hear from u

frank26080115 (author)  xp3093 years ago
Most ARM microcontrollers have DACs built-in

I did not really make a decision on RAM and frequency, I just knew what I had will work.

FAT16 is the format, FatFs is the software used to read the FAT16 format.

I simply like using AVR chips. It works... Developing for them is comfortable.
frank26080115 (author)  frank260801153 years ago
to determine RAM requirements, you can start by considering that FatFs requires a 512 byte cache at least

The frequency required can be determined by calculations using the MP3 file bitrate, and the maximum SPI bus transfer rate

I can use ARM if I wanted to, I have worked with AT91SAM7X, mbed, and STM32F4. Most ARM chip requires a custom designed PCB because they do not typically come in DIP form, and I didn't really want to spend the money on the custom PCB.
Thank you so much for the answer. I am trying to calculate the mp3 bit rate which is 100kbps (3mb/(5min x 60)) .however how do I relate it to the frequency of the microcontroller?

frank26080115 (author)  xp3093 years ago
frequency of the microcontroller will limit the speed of the SPI bus, which is used to transfer the data between the SD card, the mcu, and the decoder
thanks for the answer.,i think i wrote my question in the wrong way..i wanted to ask how do you calculate the minimum and maximum frequency that you need to have for the microcontroller
woow3 years ago
helllooo..thanks for this!
can i ask what other micro-controller and music decoder that i can use which would have the same functions but cheaper? Many thanks :)
frank26080115 (author)  woow3 years ago
I've seen designs that use the STA013 but you need a DAC to go with that, I don't know if it'll be cheaper but it's another option

Most ARM processors can probably decode the MP3 file without external help, the mbed already have an example program available for it, it also have a built in DAC. The mbed is kind of expensive at $60-ish but it's awesome, and the only people who say bad things about it are too stupid/lazy to compile offline for it.

A few weeks ago, STMicroelectronics were giving out free STM32F4Discovery kits, now they cost some money, but not too expensive, this board has a ton of audio features, it has a microphone built right in, and a I2S sound output thing with a headphone jack. The processor itself have DSP and FPU. It's a good candidate.
sorry for so many questions....i am really a beginner in this field..may i ask why you need music decoder for your design? i saw online that avr has mad library that could use to decode mp3. and also arm has the libmad library to decode the music without music decoder right?
frank26080115 (author)  woow3 years ago
show me a 8 bit (not 32 bit) AVR using MAD please.

I highly doubt a 8 bit AVR at 8 MHz can use MAD.
hey.i have decided to use a mbed.. however from my research, you still need a music decoder to go with it? also i couldn't get how sd card communicate with usb host and usb host with pc using mbed.thanks :)
frank26080115 (author)  woow3 years ago
you don't need a decoder, see http://mbed.org/users/Gruenfrosch/programs/madplayer/liih0r

Also, you are not being a USB host, you are being USB device, NOT host

You cannot communicate between SD card with MCU and SD card with computer at the same time
woow3 years ago
hey.sorry to bother u again.can i use vs1003b instead of vs1033d as the only difference is the i2s interface? And the I2S interface for external DAC function is not used in this case right?
Thanks :)
frank26080115 (author)  woow3 years ago
those two chips are compatible if you are simply playing MP3 to headphones

You can use almost any AVR microcontroller you want, if you want the USB mass storage capability then obviously you need one that features USB. Just make sure it has enough memory to do what you want, enough pins for everything, and a SPI bus to do the talking between the SD card and MP3 decoder.

I posted rough wiring schematics in the instructable, I'm sure you can adapt the circuit to whatever you are doing
So do that that mean if i wanna use a loudspeaker, then i must use the audio decoder with I2S interface? Thanks :)
frank26080115 (author)  woow3 years ago
no, you need an amplifier of some sort
sorry...i didn't quite understand..so i can use vs1003b connect to speaker but i need an amplifier to make the music sounds louder right? also, if i am now using sd card only, like what u did at the end, do i still need file system? thanks a lot :)
frank26080115 (author)  woow3 years ago
You can connect speakers directly to the VS1003b but only small speakers, if you need big speakers, you need an amplifier.

You should always use a file system, unless you have some sort of weird requirement
where to find teensy board ???
Is there a way to make the alarm start with a very low volume, then build up to regular volume over a few minutes?
frank26080115 (author)  diskincluded3 years ago
Of course, that should be easy

The function that plays out the data runs in a loop, just increase a variable in that loop and repeatedly set the volume using that variable
Well then, it would appear I have some parts to buy.
1-40 of 76Next »