Sound Output Devices

 General audience classification icon  General audience classification icon

Speaker

Speakers are electroacoustic devices that convert electrical signals into sound waves. A speaker uses a permanent magnet and a coil attached to the membrane. Sound signal flowing through the coil creates an electromagnetic field with variable strength; the coil attracts a magnet according to the strength of the field, thus making a membrane vibrate and creating a sound wave.
Another widely used speaker technology, called piezo speaker, uses piezoelectric materials instead of magnets.
Speakers are used to create an audible sound for human perception and ultrasonic sound for sensors and measurement equipment. Some speakers are designed to generate a single, fixed-frequency acoustic tone. Such elements are called buzzers and have a built-in generator to emit sound if the voltage is on. Elements without built-in generators should be controlled with the frequency signal coming from the microcontroller. Sound-generating devices require more power than LED, so there is a need to check if the operating current is lower than the maximum current of the microcontroller's pin as specified in technical documentation. In the case of the overcurrent, an additional amplifying element is required, e.g., a transistor. Sample speaker is present in the figure 1 while connection of the piezoelectric one is present in the figure 2.

 Electromagnetic speaker
Figure 1: Electromagnetic speaker, 8 Ω 0.5 W
 Arduino Uno and piezo speaker schematics
Figure 2: Arduino Uno and piezo speaker schematics
const int speakerPin = 9;      //Define the piezo speaker pin
 
void setup()
{
  pinMode(speakerPin, OUTPUT); //Set spekaer pin as an output
}
 
void loop()
{ 
  tone(speakerrPin, 1000);     //Send 1 kHz sound signal
  delay(1000);                 //For 1 s
  noTone(speakerPin);          //Stop sound
  delay(1000);                 //For 1 s
}