07. Digital Outputs, RGB LEDs & Buzzers
Control binary outputs and generate sound.
Learning outcomes
- Drive LEDs within safe current limits
- Explain common-anode and common-cathode RGB LEDs
- Generate tones with a passive buzzer
- Recognise when an output needs a driver
Parts and preparation
Uno, red LED, RGB LED, 4 x 330 ohm resistors and passive piezo buzzer.
Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.
Digital output
OUTPUT pins switch between LOW and HIGH. A pin is suitable for logic and small LEDs, not motors, relays, lamps or heaters.
RGB LED
An RGB LED contains red, green and blue dies. Common-cathode devices share GND; common-anode devices share 5 V and use inverted logic.
Active versus passive buzzer
An active buzzer sounds from DC. A passive piezo needs a square-wave frequency; tone(pin, frequency) generates it and noTone stops it.
Wiring and safe build sequence

- RGB common cathode -> GND
- Red, green, blue legs -> 330 ohm -> D9, D10, D11
- Passive buzzer positive -> D6 and negative -> GND
Worked sketch
Download .ino sketchconst byte redPin = 9;
const byte greenPin = 10;
const byte bluePin = 11;
const byte buzzerPin = 6;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
digitalWrite(redPin, HIGH);
tone(buzzerPin, 440, 200);
delay(500);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
tone(buzzerPin, 660, 200);
delay(500);
digitalWrite(greenPin, LOW);
}How the code works
- tone duration is in milliseconds.
- Each RGB color needs its own resistor.
Test and record evidence
Practical evidence checklist
Common faults and checks
- Verify the RGB LED pinout from its datasheet.
- A common-anode LED needs inverted HIGH/LOW logic.
Check your understanding
Q1. Why does each RGB channel need a resistor?
Show answer
Each LED die requires independent current limiting.
Q2. What does tone control?
Show answer
The frequency of a square wave sent to a passive buzzer.