Using MCP4131 digital potentiometer to adjust volume of a speaker

Hi all,

I’m trying to drive a speaker with an Arduino Uno through a digital potentiometer MCP4131 (datasheet here: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/General%20IC/22060b.pdf). I found this helpful tutorial (http://uduino.com/tutorials/1) that had the same goal, but with an LED. I build my circuit exactly like it is depicted there. Because the speaker needs to be driven by a pwm tone, I added this to the program. When I try it, however, there is no sound from the speaker. If I hook up an LED it works. It seems that somehow the PWM signal is not working together with the SPI interface. Doea anyone have an idea how to solve this?

#include <SPI.h>
 
const int slaveSelectPin = 10; // i.e. the Piezo pin
 
void setup()
{
  pinMode (slaveSelectPin, OUTPUT);
  SPI.begin(); 
}
 
void loop()
{
 // this should play a tone at 3 KHz for 5 seconds, then again with lower volume
     digitalPotWrite(127);
     tone(slaveSelectPin, 3000);
     delay(5000);
     noTone(slaveSelectPin);
     digitalPotWrite(63);
     tone(slaveSelectPin, 3000);
     delay(5000);
     noTone(slaveSelectPin);

}
 
 
int digitalPotWrite(int value)
{
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(0);
  SPI.transfer(value);
  digitalWrite(slaveSelectPin, HIGH); 
}

The smallest of these pots had a 5k resistance so the minimum value it can have (not counting 0) is 19.5 ohms.

Add the say 4/8 ohms for the speaker and you are trying to drive about 20-30 ohms with an Arduino pin. Increase the pot value and that helps the Arduino but not the speaker.

Either way you don't have a chance of driving that speaker.

Note the resistor in series with the LED in that tutorial? It looks like 220R (I can't really read the colours but that would be reasonable). That's way higher and appropriate for a LED.

That circuit is not appropriate for a speaker.


Rob

Thanks for your answer. So if I understand you correctly, the circuit cannot generate enough current to drive the speaker?
And what if I used a transistor in between to protect the Arduino pin? Then I could use much higher currents.

the circuit cannot generate enough current to drive the speaker?

Correct.

What type of signal are you driving the speaker with? A square wave from tone() or something?

If so then

And what if I used a transistor in between to protect the Arduino pin? Then I could use much higher currents.

Yes you would use a transistor, but in that case you don't need the digital pot, just drive the speaker from the transistor. (Maybe through a cap to stop any DC buildup, we're getting a bit analog for me now).


Rob

Yes you would use a transistor, but in that case you don't need the digital pot, just drive the speaker from the transistor. (Maybe through a cap to stop any DC buildup, we're getting a bit analog for me now).

Yes, but the purpose was to have some kind of digital volume control. Or is there a way to achieve that with the transistor?

I am trying to work on a similar project but I'm using ther Mega2560 to have more outputs for other circuits to be integrated.....so anyhows...with the PWM of the LED you mentioned, you realize an LED is lit off of DC right in this type of project. The speaker would need to be controlled via some type of amplifier circuitry like an LM386 or LM358.

I am trying to use the DS1803 dual Pot.

Still researching on it though.....I found this on Embedded-lab.com using a PIC, but obviously I want something with Arduino..