SupportContact
Allpanga
•Home•Marketplace•Blogs•Nexus HubLive•Origins
Students studying
Students outdoors
school

Allpanga

The ultimate peer-to-peer marketplace and community hub designed exclusively for students to trade, learn, and grow together.

Our LocationAllpanga HQ — View on Google Maps

Explore

  • Marketplace
  • Student Blogs
  • Nexus Hub
  • How It Works

Support

  • Help Center
  • Contact Us
  • Community Guidelines
  • Selling Guidelines
  • Origins

Legal

  • Privacy Policy
  • Terms of Service
  • Community Guidelines

© 2026 ALLPANGA. All rights reserved.

Privacy PolicyTerms of Service
How to connect LED with Arduino
Electronics

How to connect LED with Arduino

avatar
Malik Husnain
calendar_todayJul 13, 2026
schedule4 min read
visibility 1favorite0chat_bubble 0
Homechevron_rightBlogschevron_rightElectronicschevron_rightHow to connect LED with Arduino
avatar
Malik Husnain
National Textile University Electronics

I'm a student of Computer Engineering Technology in National Textile University (NTU) .

1 Works
1 Followers

How to Connect an LED to Arduino Connecting an LED to Arduino is one of the simplest and most fundamental projects you can build. It teaches the basic...

How to Connect an LED to Arduino

Connecting an LED to Arduino is one of the simplest and most fundamental projects you can build. It teaches the basics of digital output, current-limiting resistors, and how Arduino code controls hardware.


LEDs with Arduino

An LED (Light Emitting Diode) only lights up when current flows through it in one direction, and it needs a current-limiting resistor in series with it — without one, too much current can burn it out almost instantly.

Arduino controls the LED through one of its digital pins, which can be set to either:


  • HIGH (5V) — turns the LED on
  • LOW (0V / GND) — turns the LED off

If you want to control brightness instead of just on/off, you can use one of the PWM-capable pins (marked with a ~ on the board, e.g. 3, 5, 6, 9, 10, 11) with analog Write() instead of digital Write().


Hardware Required

  • Arduino board (Uno or similar)
  • LED
  • 220 ohm resistor
  • Breadboard
  • Jumper wires


Circuit

To wire your LED to your board, connect the following:


  • LED anode (long leg) to digital pin 13 through a 220 ohm resistor
  • LED cathode (short leg) to GND

The resistor can go on either leg of the LED, as long as it's somewhere in the path between the digital pin and GND.



Schematic (described)

Pin 13 ── 220Ω ── LED(+)
                   LED(–) ── GND

Blink Example

This is the classic first Arduino sketch — it turns the LED on and off once per second.


// Basic LED Blink example
// LED (through 220 ohm resistor) connected to pin 13

const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH); // turn LED on
  delay(1000);                // wait 1 second
  digitalWrite(ledPin, LOW);  // turn LED off
  delay(1000);                // wait 1 second
}

Fading Example

This example smoothly fades the LED in and out using analogWrite(). The LED must be connected to a PWM-capable pin (marked with ~) for this to work.


// LED Fade example
// LED (through 220 ohm resistor) connected to pin 9 (PWM)

const int ledPin = 9;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // fade in
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(ledPin, brightness);
    delay(10);
  }
  // fade out
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(ledPin, brightness);
    delay(10);
  }
}

Button-Controlled Example

This example adds a pushbutton so you can turn the LED on and off manually.

Additional hardware: pushbutton, 10k ohm resistor

Additional wiring:


  • One side of the button to 5V
  • Other side of the button to digital pin 2 and to one leg of a 10k resistor
  • Other leg of the 10k resistor to GND
// LED controlled by a pushbutton
// LED (through 220 ohm resistor) connected to pin 13
// Button connected to pin 2, with 10k pull-down resistor

const int ledPin = 13;
const int buttonPin = 2;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH); // button pressed, LED on
  } else {
    digitalWrite(ledPin, LOW);  // button not pressed, LED off
  }
}

Notes

  • Always use a resistor in series with an LED — connecting it directly to a digital pin without one can damage the LED or the Arduino pin.
  • Not sure which leg is the anode? The longer leg is usually the anode (+), and the flat edge on the LED's rim marks the cathode (–) side.
  • Pin 13 has a built-in resistor and LED on most Arduino boards, so it's a safe default for testing even without a breadboard.


Topic:
Electronics
Share:

Comments (0)

U
chat_bubble

No comments yet. Be the first to start the discussion.

avatar
Malik Husnain@malikhusnain47

I'm a student of Computer Engineering Technology in National Textile University (NTU) .

Posts

1

Followers

1

0
View Full Profile

In this blog

01LEDs with Arduino02Hardware Required03Circuit04Schematic (described)05Blink Example06Fading Example07Button-Controlled Example08Notes
Appreciate work
0
Share project

Quick discussion

Related Blogs

How to Connect LCD to Arduino
How to Connect LCD to Arduino