Introduction: Arduino Audio Amplifier

This is a tutorial for a Arduino Audio Amplifier using an 8 Ohm speaker.


Our audio input comes from the Arduino DAC. Audio files are stored as .wav on an SD which is read by the Arduino. The audio data needs to be stored in 8-bit integer values. Somewhere in the conversion process from mp3 to 8-bit wav the data is sometimes lost on conversion. We found that when converting the mp3 audio files to wav files a sampling rate of 8000 Hz, a bit depth of 8 bits (as mentioned before), and a mono audio channel worked best in getting a clean output from the speaker. Audio with very low frequencies (such as drums or low voices) were more noisy than higher pitches. We tried low pass and band pass filters in many different locations such as at the input and output of the signal but found that it was very difficult to create a filter that worked well with all sounds. When testing these filters, we also made sure to try different resistor and capacitor values to try and find the optimal attenuation range and corner frequency for certain sounds. The difficulty in getting a clear sound for all our audio files makes sense given the constraints of our system, such as the fact that the speaker is not very large (larger speakers make it easier to actually hear bass sounds).

Supplies

  • LM386 Operational Amplifier
  • Arduino Nano
  • Arduino SD Card Module
  • 8 Ohm Speaker
  • 10 µF Capacitors (4x)
  • 100 µF Capacitor
  • 220 µF Capacitor
  • 10 Ohm Resistor
  • 1 Ohm Resistor
  • 10 kOhm Resistor

Step 1: Make the Circuit

Use the images below to make the circuit on a breadboard.

Step 2: Write the Code

//https://onlinetonegenerator.com/

//https://conversiontools.io/convert/mp3-to-wav

//Use 8 bit at 8000 sampling


#include <SD.h>                          //include SD module library

#include <TMRpcm.h>                      //include speaker control library


#define SD_ChipSelectPin 4               //define CS pin


TMRpcm tmrpcm;                           //crete an object for speaker library


void setup(){

 tmrpcm.speakerPin = 9;                 //define speaker pin.

                                         //you must use pin 9 of the Arduino Uno and Nano

                                         //the library is using this pin

 while (!SD.begin(SD_ChipSelectPin)) {     //see if the card is present and can be initialized

   Serial.println("SD fail!");

 }

 tmrpcm.setVolume(5);                   //0 to 7. Set volume level

 tmrpcm.play("1.wav");        //the sound file "1" will play each time the arduino powers up, or is reset

}

Step 3: Play Around With Audio!

We started by testing the audio without the high pass filter at the output as shown in the video below:

Step 4: Play Around With Audio!

Here is what adding the high pass filter does to the same audio, you can hear a clear improvement!

Step 5: Play Around With Audio!

We also tested it with other audios like piano and high pitched themes with drums: