In our day-to-day life, we generally use several electrical and electronic devices or gadgets such as mobile phones, tablets, laptops, music players, and so on. Listening music is considered as a sense of enjoyment, comfort, and the best way of recreation irrespective of age. Hence, music players are most frequently used electronic gadgets for recreation purpose. There are different types of music players such as phonographs, gramophones, victrola model record players, vinyl record music players, tape recorders, cassette players, compact disc music players, digital music players, and MP3 players. Due to advancement in digital electronics, the technology has been developing at an enormous pace; as a result, most advanced music players are making their way in the market. For instance, an Arduino music player with several amazing features has already marked its presence felt. In this article, we are going to discuss about building an arduino music player with arduino based electrical projects.
Arduino Music Player
Arduino is one of the major open-source platforms, which is used for building electronics projects using microcontroller or any other physical programmable circuit board along with software for programming the physical circuit boards. Arduino music player is a simple arduino-based electronics project that develops a music player, which can be used for listening to our favorite music with the help of Arduino music code and Arduino ethernet.
4-Steps to Build Arduino Music Player
The following are a few simple steps of the Arduino based electronics project that will help you to build an Arduino music player.
Step 1: Required Hardware Components
The required hardware components for designing the Arduino music player are collected based on the estimated design of the project circuit and an external audio amplifier circuit. The required components include:
- Arduino board
- Speaker or Headphones
- Arduino shield with SD card (Ethernet shield)
- LM386 low power audio amplifier
- Potentiometers
- Resistors
- Capacitors
- Miscellaneous components
Arduino Board
Arduino board can be built at home on your own or can be directly purchased along with all other required electronics components for your projects from the online shopping sites like www.efxkits.com. Arduino board was founded in the year 2005 by Massimo Banzi and David Cuartielles, and such boards are frequently used in communication systems, and for controlling or operating several devices. These are also used for designing embedded systems based projects. Here, we are using the Arduino board for designing a simple electronic project Arduino music player for listening music either by using headphones or speakers.
SD Card
Secure digital card also called as a SD card is used for storing data (music or videos or files or etc.). SD card provides high-capacity memory in an ultra-small flash memory card. Here, SD card is used for storing music files. These files can be transferred from computer to the SD card using a separate device called as an SD card reader. The data stored in the card can be formatted based on the requirement and speed of transferring files from the computer – depending on the features or characteristics of the SD card. The music files must be stored in the specific format, namely .wav and must have 44100 Hz, 16-bit stereo quality.
The figure shows SD card and Arduino board wherein the SD card reader or holder is soldered to an arduino board according to the connections.
Step 2: Designing Hardware Circuit
For designing the hardware circuit, the circuit has to be primarily tested using the software system for checking the expected results and to rectify errors if any. Then, these hardware components are assembled to form the arduino music player project circuit. The circuits are shown in the figure below. The following procedure shows how to build the circuit using the LM386 and a bunch of discrete components.
The circuit consists of LM386 low power audio amplifier; speaker, capacitors, and resistors are connected as shown in the figure.
This circuit is mounted on bread board and is connected to the Arduino board as shown in the schematic figure.
Step 3: Arduino Music Player Description
The hardware circuit sits on top of the arduino due with a micro-SD card in the slot. A .wav file that is named as “test.wav” is in the card’s root directory. For testing purpose, you can attach headphones directly to the ground and DAC0, respecting the polarity. For connecting a speaker to the arduino board, you have to add an amplification circuit that is to be connected between the DAC0 pin and the speaker. This amplification circuit is used for increasing the volume of the speaker.
There are several audio amplifiers that are available currently and the most commonly used audio amplifier is LM386. Power supply to the LM386 is provided by connecting the Vs pin with different voltage sources (for example, the +5 V present on the 5V pin of the Arduino or an external 9V battery). The amplifier gain is given by the capacitor which is connected to pin 1 and 8 of the LM386. The gain is set to 200 using 10 µF and the gain is 50 if the capacitor is not used. The volume of the amplifier can be controlled using the potentiometer.
Step 4: Coding
Program code required for designing arduino music player
#include <SD.h>
#include <SPI.h>
#include <Audio.h>
void setup()
{
Serial.start(9600); // debug output at 9600 baud
Serial.print(“Setting SD card…”); // setup SD-card
if (!SD.strart(4)) {
Serial.println(“fail!”);
return;
}
Serial.println(“ready.”);
SPI.setClockDivider(4); // hi-speed SPI transfers
Audio.start(88200, 100); // 44100 Hz stereo => 88200 sample rate // 100 mSec of prebuffering.
}
void loop()
{
int x=0;
File myFile = SD.open(“test.wav”); // open wave file from sdcard
if (!myFile) // if the file didn’t open, print an error and stop
{
Serial.println(“error opening test.wav”);
while (true);
}
const int E=1024; // Number of examples to read in block
short buffer[E];
Serial.print(“Playing”); // until the file is not completed
while (myFile.available())
{
myFile.read(buffer, sizeof(buffer)); // read from the file into buffer
int volume = 1023; // Prepare examples
Audio.prepare(buffer, E, volume); // Feed examples to audio
Audio.write(buffer, E);
x++;
if (x == 100) // Every 100 block print a ‘.’
{
Serial.print(“.”);
x = 0;
}
}
myFile.close();
Serial.println(“End. Thank you!”);
while (true);
}
There are many more advanced digital music players with numerous amazing features. But, if you want to design microcontroller based projects (music player kit), then you can download our free eBook, which will help you to design projects on your own at home. You can approach us for any technical help by posting your comments in the comments section below.
Photo Credits
- Connecting SD Card and Arduino Board by martin-gardner
- LM386 Schematic Diagram byblogspot
- Arduino Music Player Schematic Circuit Diagram by arduino
Thanks for this informative piece. It is really helpful for the student who loves micro-controlling and studying it.
Hi Rifat Parveen, Thank you for your appreciation. Also, please check the user friendly website http://www.edgefxkits.com for project ideas on all the latest technologies. You can download project abstract and seminar presentation also from the website. Please check the website for complete details in the kit content section: http://www.edgefxkits.com/kitdetails/ and go through the FAQ: http://www.edgefxkits.com/contact-us/#faq. Further if you have any queries you can call us on the toll free no. 1800 108 7475 for clarifications/personal counseling. Niveditha (Mobile: +91 9959178000)
Hi Rifat Parveen
Thanks for your appreciation
And once again please visit our International website http://www.efxkits.com/
For more details please contact to Mr. Niranjan on +91 9908518885 or you can email us on info@edgefxkits.in
Please, where can I get the Audio.h file to insert on the Arduino library ?
Thanks.
Hi Edson Stedile
Please be specify in your query so that our technical team can guide you
And once again please visit our website http://www.edgefxkits.com/
For more details please contact our customer support on +91 9959178000
Thanks.
Thanks for the tutorial, but I still confuse When I seeing the amplifier circuit using lm386 Are you use arduino dicilemia or arduino due?.
Hi Dian, yes this is an arduino board based music player.
Thank you so much for your feedback
And once again please visit our International website http://www.efxkits.com/
For more details please contact to Mr. Niranjan on +91 9908518885 or you can email us on info@edgefxkits.in