I’d like to know how to use these speakers with my Arduino Uno

Hey everyone, so I’m trying s musical project with my arudino and I recently bought one speaker and scavenged another, was hoping someone could help me determine which will work with my curcuit better and how to wire it up/code it, if the code needs to change.

I only wish to play notes like A4, B4 etc., but may want to do chords later (I don’t need to press multiple buttons per chord, just one button per chord like a note).

The code is as follows:

const byte piezoPin = 8;
const byte buttonPin7 = 7;
const byte buttonPin2 = 2;
const byte buttonPin12 = 12;

void setup() {
  pinMode(piezoPin, OUTPUT);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin7, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin12, INPUT_PULLUP);
 
}//close setup
 
void loop() {
  if (digitalRead(buttonPin7) == LOW) {
    tone(piezoPin, 576);
  }
  else if (digitalRead(buttonPin2) == LOW) {
    tone(piezoPin, 440); 
  }
   else if (digitalRead(buttonPin12) == LOW) {
    tone(piezoPin, 131); 
  }
  else {
    noTone(piezoPin);
  }
}

Those are just speakers, you don't just connect them up to an Arduino and expect to here it. You connect it to an amplifier and the input of the amplifier to the Arduino's output.

That's perfect, this is the kind of information I need to learn. Would you mind explaining to me why speakers like this need to be wired in such a manner? Additionally, would you be able to inform me of a method to determine which amplifier I should use, or perhaps the place where I could find that information? I've checked google but I haven't found much for this.

Would you mind explaining to me why speakers like this need to be wired in such a manner?

From the ATmega chip datasheet, the "absolute maximum" allowable current from an output pin is 40mA (0.04 Amps).

It puts-out 5V (when high) and from [u]Ohm's Law[/u] we can calculate a minimum resistance (or impedance) of 125 Ohms.

If you connect a 4 or 8 Ohm speaker you'll get too much current (the output voltage will drop) and "bad things" can happen. The chip can overheat and worst case, you can fry it!

Additionally, would you be able to inform me of a method to determine which amplifier I should use, or perhaps the place where I could find that information?

Any audio "power amplifier" will work.

I have one [u]like this[/u] for "TV sound" through some small speakers in my bedroom.

but may want to do chords later

That's going to be a problem for the Arduino...

Ahhhh okay so when you say I need an amplifier, it has to be one like that, not one of those tiny electrical component things? Because I have some lm393s and wasn't sure if you meant that kind or not. Does it absolutely have to be an audio amp like that, or can it be one of those small ones/series of those?

Additionally, a circuit question: Why could I not just hook up some resistors totaling 125 ohms in series with the speaker?

Because I have some lm393s

A 393 isn't an amplifier but there are lots of audio power amplifier chips if you want to build it yourself. (You can't use a regular op-amp because they are also low current.)

But, I'd recommend you work on the "main part" of your project before you get bogged-down building an amplifier.

I forgot to mention - That amp I linked to doesn't come with a power supply. You have to buy it separately.

Okay thank you for the correction DVDoug, I think I will buy the amplifier and try to build on later once I understand the thing as a whole.

So I want to get this straight, currently I am using a 9 volt battery to make the device portable. If I get the audio amplifier though, I will need another power supply besides the 9 volt, or will the 9 volt work?

Additionally, I can just get two wires and connect the speaker directly to the amplifier?

Lastly, would you expect the Tone() Function to work with this system?

Additionally, a circuit question: Why could I not just hook up some resistors totaling 125 ohms in series with the speaker?

Because very little current will go through the speaker and you will have to put your ear to it to stand any chance of hearing anything.

Yes audio amplifiers can work at 9V, choose one that will.

Additionally, I can just get two wires and connect the speaker directly to the amplifier?

Yes.

would you expect the Tone() Function to work with this system?

Yes the tone function will work, it is not a pleasing sound because it is a square wave. But it will not do chords because only one tone can be produced at any one time. Their are other libraries and techniques to produce more tones at the same time.

As others have rightly said, you'll need an amp to drive the speakers.

It is difficult to be sure from the photo, but it could be the case that the smaller of the two speaker drivers is a tweeter, and if it is, it should be protected from low frequencies with a high pass filter. It may be worth doing a bit of reading on speaker crossover design before connecting the smaller of those units directly to an amplifier. Otherwise you may fry it's voice coil.

Also, most speakers are designed to operate in a enclosure, again you could probably do a bit of background reading on enclosure design. How far you go, depends what you're expecting audio wise.

Grumpy_Mike thank you so much for answering my sophomoric circuitry questions. I have a long way to go circuitry wise, but I am doing as much relevant research as I can and I appreciate you taking the time. From what I can tell Arduino can only create a square wave with PWM, but I may be wrong.

davetecc, I will definitely do some research on that to avoid frying anything. I will note that the small speaker I scavenged from a security PA system like you might have at your house gate to speak to guests before entering. I have looked into the enclosure design a bit too - not exactly sure where to go with it though, but I agree it probably needs one. I desire for it to play sound around a small room. Already the piezo buzzer can be heard in the room, but I'd just like the sound to be louder and clearer. I also intend to make it portable and the buzzer is nice for it's size but doesn't carry great sound multiple settings. So, my target setting is a small room, but my secondary setting is, perhaps a range of 15 feet to 20 feet around me when standing outside? More if possible.

From what I can tell Arduino can only create a square wave with PWM, but I may be wrong.

PWM is not normally used directly for sound generation, see below. The PWM signal is a variable duty cycle rectangular wave and it will sound by and large the same no matter what the duty cycle.

There are many ways an Arduino can generate sound but they are all a bit more complex than the tone function.
Search for "Arduino multiple tones".

Start here with this PDF from one of the founders of the Arduino project :- https://www.elektormagazine.com/files/attachment/331

Some systems involve more than one speaker but the signals can be mixed into one audio stream with resistors. If you want to change the wave forms to make the sound more pleasant then you need to use other techniques like using an A/D converter or using a timer to make a pseudo A/D.

My book covers several examples of tone generation. Arduino Audio

Damonswish:
davetecc, I will definitely do some research on that to avoid frying anything. I will note that the small speaker I scavenged from a security PA system like you might have at your house gate to speak to guests before entering.

In that case it probably won't be a tweeter, it will most likely be a very small full range speaker. I think you'd be better starting with the bigger of the two units, and add a tweeter later, should you need it.

A word of advice: Be careful how you connect more than one speaker to an amplifier, if you connect them in parallel without a crossover, the impedance seen by the amplifier will be quite low.

I've built quite a few speakers, starting with a similar experiment built from e-waste, You'll find it can be quite addictive! The website linked from my profile has a few I’ve built filed under audio.