This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:hardware2:actuators_sound [2023/10/03 13:40] – pczekalski | en:iot-open:hardware2:actuators_sound [2023/11/23 12:39] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Sound Output Devices ====== | ||
| + | {{: | ||
| + | == 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' | ||
| + | |||
| + | <figure speaker1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure speaker2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <code c> | ||
| + | const int speakerPin = 9; //Define the piezo speaker pin | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | pinMode(speakerPin, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | tone(speakerrPin, | ||
| + | delay(1000); | ||
| + | noTone(speakerPin); | ||
| + | delay(1000); | ||
| + | } | ||
| + | </ | ||