Car speaker unable to play 3 kHz via tone() function

Hi everyone,

I'm working on a project that requires tones of frequencies 3 to 12 kHz to play via a speaker. To this end, I'm using the tone() function on an Arduino Mega and a car speaker. To be able to adjust the volume of the tones, I'm using an Adafruit amplifier. These are all connected via connections I found on the Adafruit amplifier webpage. I have attached links to each of the components.

The speaker I'm using produces a low rumble or distortion for the lower (EDIT:) higher frequencies I need (i.e. 8 to 12 kHz), instead of the actual tones. My question is: is this likely because of the speaker, or does it have anything to do with the tone() function/amplifier? Has anyone done a similar project before, and if yes, could you please give suggestions for a better speaker if that's the likely problem?

Note: I have attached the code I'm using, as well as a rough representation of the circuit. I am a beginner at Arduino and I do not have a formal background in electronics, so please excuse the "circuit diagram". Please let me know if you need more information.

Link to speaker

Link to Adafruit amplifier

#include <Wire.h>

// 0x4B is the default i2c address
#define MAX9744_I2CADDR 0x4B

// Setting the volume is very simple! Just write the 6-bit
// volume to the i2c bus. That's it!
boolean setvolume(int8_t v) {
  // cant be higher than 63 or lower than 0
  if (v > 63) v = 63;
  if (v < 0) v = 0;
  
  Serial.print("Setting volume to ");
  Serial.println(v);
  Wire.beginTransmission(MAX9744_I2CADDR);
  Wire.write(v);
  if (Wire.endTransmission() == 0) 
    return true;
  else
    return false;
}

void setup() {
  Serial.begin(9600);
  pinMode (A0, OUTPUT);
  Wire.begin();

  while (! setvolume(23))
    Serial.println("Failed to set volume, MAX9744 not found!");
}

void loop() {
  setvolume(27); //roughly 80 dB
  tone (A0, 3000,500);
  delay(1000);

  setvolume(21); //roughly 70 dB
  tone (A0, 6000,500);
  delay(1000);

  setvolume(28); //roughly 60 dB
  tone (A0, 12000,500);
  delay(1000);

}

That amp wants an absolute maximum of 3V peak-to-peak input, but tone produces 5V peak to peak.
You need to attenuate the output from A0 before if goes into the amp.

Thank you for your response! How should I attenuate the output from A0? I apologize if the answer to this question has a fairly obvious answer. I'm a beginner and I would appreciate all the help I can get!

How should I attenuate the output from A0?

A potential divider. Using identical values will half the output. Use any value of resistors between 220R and 1K.

Thank you so much for replying!

I tried adding a resistor to attenuate the output from A0, but it didn't work. Upon later inspection I realized that I had made an error in the post I made in the forum...

The higher frequencies (>5 kHz), and not lower as I had mentioned earlier, are not playing properly. Could you suggest what might be wrong in that case? I read a tutorial that said a speaker must have 50% lower power rating than the amplifier it is being used with it - so I replaced my speaker to a 10W speaker to match the 20 W amplifier I'm using. This has improved the situation slightly; now tones upto 8 kHz are playing without distortion. However, I still need tones that are between 8 kHz and 12 kHz to play for my project.

Any help will be greatly appreciated!

I tried adding a resistor to attenuate the output from A0, but it didn't work.

A [u]voltage divider[/u] is two resistors. In this application, resistor values that add-up about 10K should be OK. Or better yet, use a 10K potentiometer (volume control).

I read a tutorial that said a speaker must have 50% lower power rating than the amplifier it is being used with it.

That's a good rule-of thumb with regular voice or music. Speakers are rated for regular program material and an an amplifier playing voice or music at 20W on the peaks might be putting-out 2W or 5W average. With constant tones you may need a speaker rated for 40W or more (if you're running the amplifier at full power). Guitar speakers (which are often driven hard into distortion) are usually rated for twice the amplifier power because the average power is higher under those conditions.

But the power rating for a speaker is where it burns-out. It's not related to frequency response.

High frequencies are normally reproduced by a tweeter and your "full range" speaker may be weak at 12kHz. Your hearing is also less sensitive at the higher audio frequencies so a 12kHz tone doesn't sound as loud as a 1 or 2kHz tone at the same power.
But tweeters are even less able to handle high power because they are smaller and there is not a lot of high frequency energy in regular program material. For example, if you have a 3-way speaker rated for 100W the tweeter might burn-out with 20W high frequency test tones. Even a "100W" tweeter is only designed to handle the high frequency part of the audio with most of that 100W going to the woofer & midrange.

I read a tutorial that said a speaker must have 50% lower power rating than the amplifier it is being used with it

I suspect you misunderstood what was being said, that is simply rubbish. It could be 50% higher for the speaker or the amplifier should be 50% lower.

tried adding a resistor to attenuate the output from A0, but it didn't work

Then you did something wrong. If you want us to be able to find out what that was we need a schematic of what you did along with a clear photograph of how you implemented it.

DVDdoug:
A voltage divider is two resistors. In this application, resistor values that add-up about 10K should be OK.

Thanks for the clarification! I tried adding a voltage divider (I have attached a rough circuit diagram), but this unfortunately had no effect on the low rumble produced with the high frequency tones.

Thank you also for your insights on speakers and amplifiers. This is a lot more complicated than I had anticipated! Am I right in assuming that a tweeter may be unable to play the low frequency tones well? How do I play the whole range of frequencies without distortion...?

Do you think it would be worth trying a 40W full-range speaker? (Sorry, lots of questions!) You have mentioned that the power has nothing to do with frequency response, so I'm not sure. However, I have noticed that when I swapped a 20 W speaker with a 10 W speaker, upto 8 kHz played without distortion, as opposed to the earlier 6 kHz. Here are the technical specifications of both the speakers:
1) 10 W speaker
2) 20 W speaker

Grumpy_Mike:
If you want us to be able to find out what that was we need a schematic of what you did along with a clear photograph of how you implemented it.

My apologies. I have attached a rough circuit diagram and a couple of photographs of the circuit. Please let me know if any detail is not sufficiently visible, I will be happy to provide more information.

Modified_circuit_with_voltage_divider.png

Yes that voltage divider is wrong. A0 should go to a resistor, the other end to L input. Then another resistor from L to ground. That will cut the output by half. What is the value of those resistors?

Here are the technical specifications of both the speakers:

  1. 10 W speaker
  2. 20 W speaker

#1 is specified 80-20,000Hz and the frequency response graph shows good output up to 20kHz with a peak above 10kHz.

I don't see any frequency response information for #2.

Do you think it would be worth trying a 40W full-range speaker?

Only if the lower-power speaker burns-up. :wink:

There is another spec called sensitivity or efficiency and it tells you how loud the speaker is. Your speaker with the specs shows 83dB at 1 Watt and 1 Meter. A doubling of power is +3dB. and 10 times the power is +10dB. That's amplifier power. The speaker's power rating is the power it can take.

Thank you Grumpy_Mike and DVDdoug for your patience, and continued help.

Grumpy_Mike:
Yes that voltage divider is wrong. A0 should go to a resistor, the other end to L input. Then another resistor from L to ground. That will cut the output by half. What is the value of those resistors?

Voltage divider - Wikipedia

Ah, thanks! I tried with 220 ohms, 1K ohms and 5K ohms. I initially had both R values as the same, and then I tried with 1K or 10K and 220 ohms between Vin and Vout, and Vin and Gnd respectively. I tried with a potentiometer as well (as DVDdoug had suggested) but there was distortion in the higher frequencies throughout. Unfortunately, none of those worked.

Update: I put a 100 ohm resistor between the amplifier and the 10W speaker, and this considerably reduced (but not removed completely) the rumble accompanying the high frequency tones. I'm not exactly sure why that worked, I'd appreciate it if someone could explain and/or point me in the right direction on how to improve further.

As you are using a 10W speaker and a 20W amplifier as mentioned before you could be overloading the speaker. Adding a series resistor reduces the amount of current through the speaker, thus not overloading the speaker as much.

I put a 100 ohm resistor between the amplifier and the 10W speaker,

That's also a voltage divider. With an 8-Ohm speaker that's an 8/108 voltage reduction and it brings your 20W amplifier down to around 1/10th of a Watt! Power (Wattage) is proportional to the square of the voltage.

When you reduce the volume it may reduce the distortion down to the point where you can't hear it. Just like when you listen to a music file at low volumes you can't hear some of the details.

Just as an experiment you might try some test-tones on the computer. [u]Audacity[/u] can generate and play sine wave or square wave files. The tone() function generates square waves.

If you have a pair of headphones you should be able to get good-clean loud sounds across the frequency range. But, you can also try computer speakers.

Or, you can connect the Adafruit amplifier and your speaker to the computer. And, you can try some music to see if you are getting "clean amplification".


Something that's "interesting"... Regular [u]clipping[/u] distortion that you get when you over-drive an amplifier is harmonic distortion and it's only the odd harmonics. If we assume you are young person with good hearing and you can hear up to 20kHz that means you can't hear clipping above 6.7kHz. i.e. At 8kHz clipping doesn't give you a 2nd harmonic (even) at 16kHz and 3rd (odd) is above the hearing range at 24kHz. Next odd harmonic is the 5th at 40kHz, etc.

The speaker could be rattling/buzzing or you could be getting some other kind of distortion but you can't hear clipping with an 8kHz signal.

Clipping with a real amplifier isn't always nice or symmetrical. Rail-sticking is one way even harmonics
can be generated by clipping, and generally the behaviour is messy, not theoretical.