Board and part

Arduino Nano LED Simulator: Wiring, Code and a Live Circuit

This is a red LED with a 220 ohm resistor, wired to an Arduino Nano and blinking live in your browser. The serial monitor prints LED on and LED off as the pin changes.

  • 5 V logic
  • No library
  • Pin pin 2
  • 220 ohm resistor
Arduino Nano · LEDlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Connections

Wiring the LED to the Arduino Nano

Two connections matter: the pin to the resistor and the resistor to the LED’s anode, then the cathode to ground. The pin is pin 2 and the supply behind it is 5 V.

Every connection in the circuit above, with the board’s own pin names.

LED pinArduino Nano pinWhy
A (anode)pin 2The long leg. Current flows in here, so it takes the signal, with the resistor in the way.
C (cathode)GNDThe short leg, on the flat side of the lens, goes to ground.
220 ohm resistorIn series with the anodeLimits the current. Without it the LED, the pin or both burn out.

Power

A red LED drops about 2 V, so with 220 ohm in series a 5 V pin pushes about 14 mA through it: bright enough to see and gentle on the pin. The resistor can sit on either side of the LED; what matters is that it is in the loop.

Pins to leave alone on the Arduino Nano

A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.

On a real bench

The Nano plugs into the breadboard itself, straddling the center channel, so the LED goes in a few columns along and every connection is a short jumper. The silkscreen labels its pins D2 to D13 and A0 to A7; in code D2 is simply 2. A Nano clone with a CH340 USB chip needs that driver on a real computer.

The sketch

The code, and what it does.

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

Blinking an LED on Arduino Nano pin 2
const int LED_PIN = 2;   // pin 2, through a 220 ohm resistor to the LED

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED on");
  delay(500);
  digitalWrite(LED_PIN, LOW);
  Serial.println("LED off");
  delay(500);
}

pinMode(LED_PIN, OUTPUT) makes pin 2 drive its level instead of listening to it. digitalWrite(LED_PIN, HIGH) puts 5 V on the pin, which pushes current through the resistor and the LED to ground, and LOW takes it away.

delay(500) holds each state for half a second, so the LED blinks once a second. While delay() waits the board does nothing else; a sketch that must also do other work times itself with millis() instead.

Serial.begin(9600) opens the serial monitor. Serial is the USB port, as on the Uno; a clone with a CH340 chip needs that driver on a real computer, which the simulator does not.

Pitfalls

Common mistakes with the LED on the Arduino Nano

Putting the LED in backwards

An LED passes current one way only. Backwards it stays dark and nothing is damaged. If it never lights, swap its two legs: the long leg, the anode, faces the signal.

Leaving out the resistor

An LED has almost no resistance once it conducts, so the only limit on the current is the pin. At 5 V that is far more than the LED’s 20 mA rating. The simulator burns the LED out and shows it dark for good, as a real one goes.

Picking A6 or A7

A6 and A7 look like the other analog pins but are inputs to the ADC and nothing else. the LED on either of them never sees a digital level. Any of D2 to D13 or A0 to A5 works.

FAQ

Questions and answers

How do I connect an LED to an Arduino Nano?

Wire pin 2 to a 220 ohm resistor, the resistor to the LED’s long leg, and the LED’s short leg to GND. In the sketch call pinMode(2, OUTPUT) and digitalWrite(2, HIGH).

What resistor value should I use?

Subtract the LED’s drop, about 2 V for red, from the pin’s 5 V and divide by the current you want. For 10 mA that is 300 ohm; 220 ohm is the common value because it is safe for any color.

Can I run an LED without a resistor on a pin?

No. The pin has no way to limit the current, so the LED or the pin is damaged. Always put a resistor in series.

Why does my LED stay dim?

Either the resistor is too large, or the pin is being driven with PWM at a low duty. A 220 ohm resistor with digitalWrite(HIGH) gives full brightness.

Build your own LED project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.