Build it step by step
0 of 8 doneRead the pins
Identify the middle pin and the two outer pins.
Wire the colours
D5 and D6 through 330 ohm to the outer pins.
Wire the common pin
Middle pin to GND.
Wire the button
D2 to GND.
Upload
Green shows at start.
Press the button
Orange, then blinking red, then green again.
Tune the orange
Change the 45 value until it looks right.
Test common anode
Set COMMON_ANODE true if the LED is that type.
How do you build a two-colour status light?
A bi-colour LED shows green, orange and a blinking red from two pins, to report three states of a small system. You need Arduino Nano, Bi-colour LED red/green (3-pin), Resistor 330 Ω × 2, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 1
- OptoelectronicsBuy
- PassivesBuyResistor 330 Ω × 2
- SwitchesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Nano D5 | 330 ohm resistor to the red anode | Red channel (PWM) |
| Nano D6 | 330 ohm resistor to the green anode | Green channel (PWM) |
| LED common pin (middle) | Nano GND | Common cathode |
| Button | Nano D2 to GND | Cycle the state |
Code
A three-pin bi-colour LED holds a red LED and a green LED in one 5 millimetre body with one pin shared. Most have the shared pin in the middle and use it as a common cathode, which is what this build assumes. If your LED lights only when the middle pin is on 5 volts, it is a common anode part, and you only need to set COMMON_ANODE to true in the sketch. Each colour has its own 330 ohm resistor and its own PWM pin, which lets you mix them: green alone for all good, red alone for an alert, and a lot of red with a little green for orange, because the eye blends the two colours. The button steps through three states, such as normal, warning and alert, and in the alert state the red blinks using millis so the button still responds. Do not use one resistor for both colours, because the brightness would then change depending on which is on. The idea is useful anywhere a device needs to report its state at a glance, such as a battery monitor, a plant monitor or a network status light, and you can combine it with a sensor by replacing the button with a threshold test. Because the red and green parts have different forward voltages and brightness, you may need to tune the orange numbers by eye.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int RED = 5, GREEN = 6, BTN = 2;
const bool COMMON_ANODE = false; // set true if the LED lights with its middle pin to 5V instead
int state = 0; // 0 OK, 1 warning, 2 alert
bool wasDown = false;
void colour(int r, int g) { // 0 to 255 for each colour
if (COMMON_ANODE) { r = 255 - r; g = 255 - g; }
analogWrite(RED, r);
analogWrite(GREEN, g);
}
void setup() {
pinMode(BTN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool down = (digitalRead(BTN) == LOW);
if (down && !wasDown) {
state = (state + 1) % 3;
Serial.print("State "); Serial.println(state);
delay(30);
}
wasDown = down;
if (state == 0) {
colour(0, 160); // green
} else if (state == 1) {
colour(255, 45); // red plus a little green looks orange
} else {
bool on = (millis() / 400) % 2; // blink red
colour(on ? 255 : 0, 0);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Start | Steady green |
| First press | Orange |
| Second press | Blinking red |
| Third press | Back to green |
| Wrong colours swapped | Swap the two outer wires |
If it does not work
Nothing lights
Check the pin order and that the common pin is on GND.
Only one colour works
Check each resistor and wire.
Colours are inverted
Set COMMON_ANODE true and wire the middle pin to 5V.
Orange looks yellow
Lower the green value.
Orange looks red
Raise the green value a little.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the two-colour status light?
Arduino Nano, Bi-colour LED red/green (3-pin), Resistor 330 Ω × 2, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the two-colour status light take to build?
About 60 minutes for a beginner maker, in 8 steps.
How do I know the two-colour status light works?
Start: Steady green. First press: Orange. Second press: Blinking red.
Nothing lights: what should I check?
Check the pin order and that the common pin is on GND.
Only one colour works: what should I check?
Check each resistor and wire.
Colours are inverted: what should I check?
Set COMMON_ANODE true and wire the middle pin to 5V.
Orange looks yellow: what should I check?
Lower the green value.
