I've looted this speaker from my old PC and trying to understand how to connect it to Arduino to produce simple sound notification (and not fry anything in the process).
As far as I understand this is a piezo speaker, there is no markings on it. Here is how it looks:
speaker front speaker back
How do I connect\control it?
Should I connect it to PWM pin? If so, what are the safe values to output on PWM pin?
Should I use resistor when connecting speaker? What resistor should I use?
-
Take a look at the tone() function, it may suit your purpose.Paolo Zanchi– Paolo Zanchi03/13/2015 15:40:04Commented Mar 13, 2015 at 15:40
-
As far as connections go, I would connect the red wire to a PWM pin and the black one to a GND pin, but I'm not sure if a resistor is needed, wait for someone more expert than me to answer. :)Paolo Zanchi– Paolo Zanchi03/13/2015 15:43:57Commented Mar 13, 2015 at 15:43
1 Answer 1
No need for a resistor. Just connect black to ground, and red to a IO pin. Use the tone function to specify a frequency.
-
I'd recommend using a resistor. The piezo conducts quite well and might fry the pin. arduino.cc/en/Tutorial/Tone Also see uchobby.com/index.php/2007/11/11/arduino-sound-part-1Mr Jones– Mr Jones03/13/2015 19:07:37Commented Mar 13, 2015 at 19:07
-
@MrJones A resistor might be needed for (electromagnetic) speakers, not for piezos. A piezo is more like a capacitor, and doesn't conduct any current.Gerben– Gerben03/13/2015 20:34:04Commented Mar 13, 2015 at 20:34
-
Why is no resistor needed? I don't exactly know OP's speaker, but my speaker says 8 Ohm. 8 Ohm at 5V is much more than an Arduino can handle, isn't it?Thomas Weller– Thomas Weller10/10/2021 09:37:44Commented Oct 10, 2021 at 9:37
-
@ThomasWeller OPs "Speaker" is actually a piezo. A piezo you can drive with an Arduino pin. With a (8-ohm) speaker, you can't do that.Gerben– Gerben10/10/2021 12:29:33Commented Oct 10, 2021 at 12:29