> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Buzzer

> Piezoelectric buzzer for sound generation

A piezoelectric buzzer.

## Pins

<ParamField path="1" type="signal">
  Negative (Black) pin
</ParamField>

<ParamField path="2" type="signal">
  Positive (Red) pin
</ParamField>

## Attributes

<ParamField path="mode" type="string" default="smooth">
  Buzzer operation mode: "smooth" or "accurate"
</ParamField>

<ParamField path="volume" type="string" default="1.0">
  Volume (loudness) of the sound, between "0.01" and "1.0"
</ParamField>

### Operation modes

The buzzer can operate in two modes: "smooth" (the default) and "accurate".

**Smooth mode** sounds better and is suitable for simple, single-frequency tones. Use it when playing a melody or playing tones with Arduino's `tone()` function. Complex and polyphonic sounds may not play correctly (or not play at all) in smooth mode.

**Accurate mode** should be used when you need to play complex sounds. It will accurately play the sound you feed in. However, it'll add audible click noises to your sound. These noises are due to fluctuations in the simulation speed - it's not always able to provide the complete sound buffer in real time.

## Arduino example

Connect pin 1 of the buzzer to Arduino GND pin, and pin 2 of the buzzer to Arduino pin 8. Then use the `tone()` function to play a sound:

```cpp theme={null}
tone(8, 262, 250); // Plays 262Hz tone for 0.250 seconds
```

## Simulator examples

* [Simon game](https://wokwi.com/projects/344891334169985618) - A memory game with 4 push buttons
* [Diatonic piano](https://wokwi.com/projects/291958456169005577) - An 8-note piano, use keys 1-8 to press the buttons and play the notes.
* [Alarm clock](https://wokwi.com/projects/297787059514376717) - Uses the buzzer to play the alarm sound
