0

How to Connect an LED to Arduino (Your First Circuit)

Lighting an LED from an Arduino pin is the first real circuit almost everyone builds. It takes three parts — an LED, a resistor and a jumper wire — and teaches the two rules you’ll use forever: polarity and current limiting.

In short: Connect the LED’s long leg (+) to an Arduino pin through a 220–330Ω resistor, and the short leg (−) to GND. The resistor is essential — without it the LED (and possibly your pin) can burn out.

What you need

LED polarity: which leg is which

An LED only works one way round. The long leg is positive (anode) and goes toward the Arduino pin; the short leg is negative (cathode) and goes to ground. There’s also a flat edge on the rim next to the short leg. Wire it backwards and it simply won’t light — no harm done, just flip it.

Why the resistor matters

An LED will greedily pull as much current as it’s given, and too much destroys it — and can stress the Arduino pin (rated ~20 mA). A 220–330Ω resistor limits the current to a safe level. Never connect an LED straight to a pin without one. It doesn’t matter which LED leg the resistor sits on.

The wiring

ComponentConnect to
LED long leg (+)Resistor β†’ Arduino pin 9
LED short leg (−)Arduino GND
ResistorBetween pin 9 and the LED’s + leg

The code

void setup() {
  pinMode(9, OUTPUT);       // LED connected to pin 9
}

void loop() {
  digitalWrite(9, HIGH);    // turn the LED on
  delay(500);
  digitalWrite(9, LOW);     // turn the LED off
  delay(500);
}

This blinks the LED on pin 9 twice a second. Upload it and your first circuit comes to life.

Make it dim (bonus)

Pin 9 is a PWM (~) pin, so you can fade the LED instead of just on/off. Replace digitalWrite(9, HIGH) with analogWrite(9, 128) for half brightness — try values from 0 to 255.

Troubleshooting

  • LED won’t light: it’s probably backwards — swap the legs (long leg toward the pin).
  • Very dim: resistor value too high, or low PWM value.
  • Nothing at all: check the GND wire and that the code uploaded.

Frequently asked questions

What resistor value should I use?

220Ω or 330Ω is ideal for a 5mm LED on 5V. Higher values make it dimmer but are still safe.

Can I skip the resistor?

No — it protects both the LED and the Arduino pin. Always include it.

Which pin should I use?

Any digital pin works. Use a PWM (~) pin like 9 if you want to dim the LED.

Related guides

Get the parts

Everything here is in stock at Smart Home | Arduino Corner — Shaheen Market, DAV College Road, Rawalpindi — with same-day delivery in the twin cities and cash on delivery across Pakistan. Grab LEDs, a breadboard and jumper wires — or the Starter Kit which has them all. Browse LEDs and components.

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us on WhatsApp