Output Components
LEDs, RGB LEDs, buzzers, servos, motors, relays, displays and NeoPixels: wiring and code for each. Each entry explains what the part does, what it looks like in CircuitBench, how to wire it and, where relevant, an Arduino code example you can paste into the code panel. New to electronics? Start with the electronics basics and the Arduino tutorial.
LED
OutputWhat it does. A light-emitting diode. It glows when forward current flows and is damaged without a series resistor.
What it looks like. A coloured dome; the longer leg is the anode (+).
How to use it. The A leg (anode, +) goes through a 220 Ω resistor to a board pin, and the K leg (cathode) goes to GND.
Code example.
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);RGB LED
OutputWhat it does. Three LEDs (red, green, blue) in one package, mixed to make any colour. Common-cathode or common-anode.
What it looks like. A clear dome with four legs.
How to use it. It has four legs: R, G, B and the common leg COM. Connect COM to GND (for common cathode) and put a resistor between each colour leg and a board pin. Use PWM pins to blend colours.
Code example.
analogWrite(9, 255); // red
analogWrite(10, 120); // green
analogWrite(11, 0); // bluePiezo buzzer
OutputWhat it does. Makes sound when driven with a changing signal; the frequency sets the pitch.
What it looks like. A small black disc with two leads.
How to use it. Connect the + lead to a board pin and the − lead to GND, then use tone().
Code example.
tone(8, 440, 500); // A4 for half a secondServo SG90
OutputWhat it does. A motor with position feedback that turns to an angle between 0° and 180°.
What it looks like. A blue box with a horn and three wires (signal, power, ground).
How to use it. Signal (S) to any digital pin, + to 5 V and − to GND.
Code example.
#include <Servo.h>
Servo s;
void setup(){ s.attach(9); }
void loop(){ s.write(0); delay(800); s.write(180); delay(800); }DC motor
OutputWhat it does. Spins when current flows and reverses when the polarity flips. It draws far more current than a pin can supply.
What it looks like. A silver can with two terminals.
How to use it. Drive it through a transistor with a diode across it, powered from a separate supply.
Code example.
analogWrite(5, 180); // ~70% speed via transistorRelay module
OutputWhat it does. An electrically operated switch that lets a small signal control a separate load.
What it looks like. A blue box with a screw terminal.
How to use it. Connect VCC to 5 V, GND to GND and IN to a board pin. The load you are switching goes through the COM and NO (normally open) terminals: it is only connected while the relay is on.
Code example.
digitalWrite(6, HIGH); delay(1000); digitalWrite(6, LOW);7-segment display
OutputWhat it does. Seven LED bars (plus a dot) that form digits. Common-cathode or common-anode.
What it looks like. A rectangular block with a figure-eight of segments.
How to use it. Each segment needs a resistor and a pin. Light segments a–g to draw a number.
Code example.
const byte two[7] = {1,1,0,1,1,0,1};
for (int i=0;i<7;i++) digitalWrite(2+i, two[i]);NeoPixel strip
OutputWhat it does. Addressable RGB LEDs on a single data line; each pixel has its own colour.
What it looks like. A long strip of eight small square LEDs.
How to use it. Data pin through a 330 Ω resistor, plus 5 V and GND. Use the Adafruit NeoPixel library.
Code example.
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel px(8, 6, NEO_GRB + NEO_KHZ800);
void setup(){ px.begin(); px.setPixelColor(0, px.Color(0,150,0)); px.show(); }
void loop(){}LCD 1602 (I²C)
OutputWhat it does. A 16-column, 2-row text display driven over I²C, using only two wires (SDA, SCL).
What it looks like. A green panel with two lines of character cells.
How to use it. SDA and SCL go to the I²C pins of the board (A4 and A5 on the Uno, D21 and D22 on the ESP32), VCC to 5 V and GND to GND. Pick the same I²C address in the inspector (0x27 or 0x3F) as in your code.
Code example.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup(){ lcd.init(); lcd.backlight(); lcd.print("Hello!"); }
void loop(){}