LED and Buzzer
What you'll build¶
Hold button A to switch on an LED (or sound a buzzer) connected to pin 0.
Wiring¶
| Part | Part pin | micro:bit pin |
|---|---|---|
| LED or active buzzer | + (long leg) | P0 (through a 220 Ω resistor for an LED) |
| LED or active buzzer | − (short leg) | GND |
Code¶
| led-buzzer-example.py | |
|---|---|
How it works¶
pin0.write_digital(1) sets pin 0 to 3 V (on); write_digital(0) sets it to 0 V (off).
The same code drives an LED or an active buzzer, since both just need power to work.
Try this next¶
- Blink the LED with
sleep()instead of holding the button. - Use
pin0.write_analog(0–1023)to dim the LED. - Combine with the PIR sensor to make a motion alarm.