3 Options for Playing Audio on Arduino
All of these methods have some advantages and disadvantages displayed on the screen. Now lets get started with the first option. You go to file Music examples tone melody in here. You change the pin to pin 3.. This will be the digital pin were using Music plug in your arduino and connect the speaker to pin 3 and ground. The only thing you have to do now is upload it Music. If you want a different song, you can go to the first link in the description, and here you just copy all the code into your arduino. You just have to make sure that you always change the buzzer or speaker or sound, pin to pin 3 or at least the pin youre using lets upload that Music and there you go Music for the second option. We will use this greeting card module by connecting a micro usb. We can upload our own music file Music in music. I saved audio test Music test test. One two: three, please subscribe one two three: this will be the file that were going to upload. So lets drag it over to our usb drive and then we can disconnect it again. Now we have to connect the plus and minus to the plus and minus of the arduino, because this board should run on 5 volts the place where previously a button was soldered. When we push that together, it starts playing our sound, so now we only have to establish that same connection using the arduino one of the wires is ground.
So if we put that same wire to a digital pin and pull it down to low, then it will start playing music. So lets look at that in code. We use the example file button that we can find in the digital tab. We change the led pin to pin 3.. This is the pin that we will be pulling to low to start playing music and turn around the low and high also note that the button pin is pin 2, so we will connect the button to that bit. Music. The loose wire should be connected to pin 3, and the button should be connected to pin 2. realize that you dont have to use a button for this. Anything that digital right, subscribe to low will work to make the music play for the third method. We have to do some more prep work. First off, take the audio and put it into the audio converter. Here we change it to 8, bit 16, 1600, hertz mono and u8. Now we start converting and download our file Music. Make sure you rename your waff file to something with four characters or less? I have no idea why, but for me it didnt work. When i used more than four characters. We are going to format the sd card so put in your sd card and download the zip file. Also in the description of this video, and here we can open the sd card. Formatter Music. When we open up the sd formatter, you will see the drive and it should be the same drive as your sd card, just click format and a few times, ok to be done with formatting the sd card.
After this, you can drag your waff file to your usb drive and disconnect it safely, get the micro sd card out of the sd card and put it into the micro sd card reader Music now lets install this library, drag it over to a folder where you Can remember: go to your arduino sketch include library, add the zip library navigate to that place and add the zip library. When that is done, you can open the audio pgm example in here i like to set the volume to 5 because that works way better. For me, and we change the name of the wav file to our file name, i used abcd, so i filled that in after this. I am ready to upload the program. Now we can start building the arduino board Music when youve done this. Every time you hit the reset button, it should start playing the music Music Music. If you want to start playing music at a different place, you can just copy the dmr pcm.playline and place it inside the loop after some. If statement, i hope this video was helpful and one of these three options fit your project.