Appearance
Buzzer
Overview
The AlphaBot V2 includes a passive buzzer, which is a simple audio output device that can generate tones, beeps, and melodies when controlled by a microcontroller (like Arduino or Raspberry Pi).
Key Feature
- Passive Buzzer (Requires External Signal)
- Unlike an active buzzer (which has an internal oscillator and produces sound with just a DC voltage), a passive buzzer needs a PWM (Pulse Width Modulation) signal to generate different tones.
- This allows for variable frequency control, enabling musical notes and custom sound effects. Connected to a Digital/PWM
- Connected to a Digital/PWM Pin
- Typically wired to a PWM-capable pin.
- Common Uses in Robotics
- Alerts & Notifications (e.g., obstacle detection, low battery).
- Simple Melodies (e.g., startup sound, error beeps).
- User Feedback (e.g., button press confirmation).
Working
- PCF8574 I/O Expander
- The PCF8574 is an 8-bit I/O expander that communicates via I²C (Arduino’s Wire library).
- Buzzer Control Logic
- The buzzer is controlled by bit manipulation of the PCF8574's output register.
- beep_on → Sets a specific bit (0xDF mask) to activate the buzzer.
- beep_off → Clears the bit (0x20 mask) to deactivate the buzzer.
- PCF8574Write(byte data)
- Sends a byte (data) to the PCF8574 to update its output pins.
- PCF8574Read()
- Reads the current state of the PCF8574's input/output pins. Returns a byte representing the pin states.
- beep_on = PCF8574Write(0xDF & PCF8574Read())
- Masks the current state with 0xDF (binary 11011111), clearing the buzzer-control bit.
- beep_off = PCF8574Write(0x20 | PCF8574Read())
- Masks the current state with 0x20 (binary 00100000), setting the buzzer-control bit.