Buzzer Sounds and Patterns
Learn to create sounds, melodies, and alert patterns using active and passive buzzers with your Arduino Uno!
Understanding Buzzer Types
Active Buzzer
- Internal oscillator - produces sound automatically when powered
- Fixed frequency - typically ~2kHz tone
- Simple control - just turn ON/OFF with digitalWrite()
- Identification - often has a white sticker on top, sealed case
Passive Buzzer
- Like a tiny speaker - requires AC signal to produce sound
- Variable frequency - can create different tones and melodies
- Uses tone() function - Arduino generates the frequency
- Identification - open back, exposed PCB, green circuit board visible
Why Use a Transistor?
Current Limitations:
- Arduino pins can safely source 20mA continuous
- Maximum absolute limit: 40mA
- Buzzers typically draw 20-40mA or more
Solution: 2N2222 Transistor
The transistor acts as an electronic switch that can handle 100-500mA safely, providing:
- Louder sound output
- Protection for Arduino pins
- Ability to drive larger buzzers
Base Resistor Calculation:
For 30mA collector current with gain of 100:
Ibase ≈ 0.3mA minimum
1kΩ resistor provides ~4.3mA (safe with margin)
R = (5V - 0.7V) / IbaseFor 30mA collector current with gain of 100:
Ibase ≈ 0.3mA minimum
1kΩ resistor provides ~4.3mA (safe with margin)
Flyback Diode Protection
When a buzzer (inductive load) turns off, it creates a voltage spike that can damage the transistor.
The 1N4007 flyback diode provides a safe path for this energy:
- Cathode (silver band) connects to buzzer positive
- Anode connects to GND
- Diode is reverse-biased during normal operation
- Conducts only during voltage spike, protecting transistor
Interactive visualization — available in the full lesson