Micro blink
The Arduino Micro’s RX lamp, which lights when its pin goes low, blinking beside an LED on pin 9 that lights when it goes high. The whole build, an Arduino Micro and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $29. On Mokxi they're free.
What you'll learn
- LEDs that light on LOW versus on HIGH
- The RX and TX lamps on 32U4 boards
- Special macros for the board's built-in LEDs
- Blinking two LEDs together
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Arduino Micro
- Parts: 4
How it works
The Arduino Micro has an RX lamp and a TX lamp, each wired from 5 V through a resistor to a pin. That means the pin has to go LOW to light one. This sketch blinks the RX lamp, and it also blinks an LED on pin 9 that you wire with a 220 ohm resistor to ground.
The two are opposite ways round. When the RX lamp is on, pin 9 is HIGH and your LED is on too. Both turn on for half a second and off for half a second, so you can see lights-on-LOW and lights-on-HIGH side by side.
Parts list
4 parts, plus the jumper wires. They retail for about $29; on Mokxi they're free.
- 1 × Arduino Micro
- 1 × Full-size breadboard
- 1 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Resistor, 220 Ω pin 1 | Arduino Micro pin 9 |
| LED, red pin C | Arduino Micro pin GND |
| LED, red pin A | Resistor, 220 Ω pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// RX blink: the lamp a board with no pin 13 still has.
//
// Every ATmega32U4 board has an RX and a TX LED, and both are wired from 5 V
// through a resistor to a pin: RX to PB0, TX to PD5. So the pin has to go LOW
// to light one. RXLED1 does that and RXLED0 lets it go dark again.
//
// On a Leonardo or a Micro this blinks the RX lamp beside L. On a SparkFun Pro
// Micro, which does not bring pin 13 out at all, it is the only way to see a
// blink without wiring anything: LED_BUILTIN is still 13 there, and blinking
// it lights nothing.
//
// Pin 9 blinks at the same time the ordinary way round, HIGH for on, so an
// LED and a resistor from pin 9 to GND show the difference side by side.
const int WIRED = 9;
void setup() {
TX_RX_LED_INIT;
TXLED0;
pinMode(WIRED, OUTPUT);
}
void loop() {
RXLED1; // lamp on: PB0 low
digitalWrite(WIRED, HIGH); // wired LED on: pin 9 high
delay(500);
RXLED0; // lamp off: PB0 high
digitalWrite(WIRED, LOW);
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
TX_RX_LED_INIT sets up the two lamp pins as outputs. TXLED0 lets the TX lamp go dark, and pinMode sets the WIRED pin (9) as an output.
void setup() {
TX_RX_LED_INIT;
TXLED0;
pinMode(WIRED, OUTPUT);
}loop sketch.ino
RXLED1 lights the RX lamp by pulling its pin low, and pin 9 goes HIGH to light your LED. After 500 ms, RXLED0 turns the lamp off and pin 9 goes LOW. Then it waits another 500 ms.
void loop() {
RXLED1; // lamp on: PB0 low
digitalWrite(WIRED, HIGH); // wired LED on: pin 9 high
delay(500);
RXLED0; // lamp off: PB0 high
digitalWrite(WIRED, LOW);
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Your LED never lights This project
Check its direction: the cathode goes to GND, and the resistor connects pin 9 to the anode. - You expected `LED_BUILTIN` to work This project
On this kind of board the RX lamp is the one to blink, which is why the sketch usesRXLED1andRXLED0. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED. - Serial prints do nothing. Arduino Micro
On the Micro, USB is on the chip. Use Serial for USB, which needs a wait for it to open. Use Serial1 on pins 0 and 1 for hardware UART. - Upload fails or the port disappears. Arduino Micro
A bad sketch can crash USB. Double tap reset to enter the bootloader and upload again. Pins give 20 mA each, and logic is 5 V.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.