Buzzer Raspberry Pi (GPIO Guide)

Buzzer Raspberry Pi 1. Introduction

A buzzer is a simple and effective output device used to generate sound alerts. By interfacing a buzzer with Raspberry Pi, you can create alarms, notifications, and warning systems in your projects.

There are two types:

  • Active Buzzer (easy – just ON/OFF)
  • Passive Buzzer (needs PWM for tones)

2. Components

  • Raspberry Pi 4 Model B
  • Buzzer (Active or Passive)
  • Resistor (100–220Ω recommended)
  • Jumper wires
  • Breadboard (optional)

3. Circuit and Connections

Raspbery Pi
Raspberry Pi Pinout Diagram

Pinout Diagram of Buzzer
Pinout Diagram of Buzzer

Connection Table

Buzzer PinRaspberry Pi
Positive (+)GPIO18
Negative (–)GND

👉 Place a resistor in series with the buzzer for safety.


4. Detailed Step By Step Circuit Working

  1. Raspberry Pi sends HIGH signal to GPIO pin.
  2. Current flows through buzzer → produces sound.
  3. LOW signal stops sound.
  4. For passive buzzer, PWM signal generates tones.

5. Libraries to be Included

pip3 install RPi.GPIO

6. Code (Active Buzzer)

import RPi.GPIO as GPIO
import time

buzzer = 18

GPIO.setmode(GPIO.BCM)
GPIO.setup(buzzer, GPIO.OUT)

try:
while True:
GPIO.output(buzzer, GPIO.HIGH)
print("Buzzer ON")
time.sleep(1)

GPIO.output(buzzer, GPIO.LOW)
print("Buzzer OFF")
time.sleep(1)

except KeyboardInterrupt:
GPIO.cleanup()

7. Detailed Step By Step Code Working

  • GPIO.setup() → Sets buzzer pin as output
  • GPIO.output(HIGH) → Turns buzzer ON
  • GPIO.output(LOW) → Turns buzzer OFF
  • Loop creates beeping sound

For Passive Buzzer (Tone Generation)

import RPi.GPIO as GPIO
import time

buzzer = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(buzzer, GPIO.OUT)

pwm = GPIO.PWM(buzzer, 1000) # 1kHz frequency
pwm.start(50)

time.sleep(2)

pwm.stop()
GPIO.cleanup()

8. Tips

  • Use active buzzer for simple alerts
  • Use passive buzzer for music/tones
  • Avoid direct high current
  • Always use resistor
  • Test GPIO pin before connecting

9. Uses

  • Alarm systems
  • Notification alerts
  • Security systems
  • Timer alerts
  • IoT warning systems

10. Conclusion

Interfacing a buzzer with Raspberry Pi is one of the simplest ways to add sound output to your project. It is widely used in automation, robotics, and IoT systems.

Popular Posts

തുടക്കക്കാർക്കായുള്ള ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.