Unit B - Inputs & Outputs

07. Digital Outputs, RGB LEDs & Buzzers

Control binary outputs and generate sound.

Estimated time 3 hours

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 Outputs, RGB LEDs & Buzzers instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

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

Breadboard wiring for lesson 07: Digital Outputs, RGB LEDs & Buzzers
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. RGB common cathode -> GND
  2. Red, green, blue legs -> 330 ohm -> D9, D10, D11
  3. Passive buzzer positive -> D6 and negative -> GND
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
const 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

  1. tone duration is in milliseconds.
  2. Each RGB color needs its own resistor.

Test and record evidence

Expected result: Red then green light appears while two different tones sound.

Practical evidence checklist

Common faults and checks
  • Verify the RGB LED pinout from its datasheet.
  • A common-anode LED needs inverted HIGH/LOW logic.
Extension challenge: Create a three-note status melody and a matching RGB color sequence.

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.