I've got the code to play a little sound from an arduino. The song has been encoded from numeric values. but how do I make it play louder from the arduino?
#include <PCM.h>
int switchPin = 8;
const unsigned char sample[] PROGMEM = {
140, 124, 130, 126, 129, 126, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 128, 128, 128,
};
void setup()
{
pinMode(switchPin, INPUT);
}
void loop()
{
if(digitalRead(switchPin) == HIGH)
{
startPlayback(sample, sizeof(sample));
}
}
This sample code uses a subroutine that uses a PCM technique to control the intervals that the digital pins are turned on and off (and assuming that those output pins are connected to a simple speaker). Remember that sound's frequency is what makes the tones and the volume is the amplitude of those frequencies. So what you are asking is, to make a sound louder, how to increase the amplitude of the signal. But since this simple demo is only capable of changing the time the digital signals are toggled (frequency) and not the amplitude (a bit is either On of Off. a bit is never "REALLY ON" [caps denote yelling here :-) ] ) so your only choice here is to add another layer of hardware between the Arduino and the speaker to increase the tone's amplitude - aka an amplifier. This can be something simple like an opamp as described from this design tutorial or replacing the speaker with a jack to the input of a boombox.