Supplier photo of an assembled radio kit with a purple circuit board, telescopic antenna and clear case.
Supplier photo
Temu affiliate offer ยท Project idea

Build a radio

Soldering required. Check the supplied parts and board revision.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

How to Connect an LED to an Arduino Correctly

Connecting an LED to an Arduino is simple, but there are best practices to ensure safe operation and proper brightness control. Below are different ways to connect an LED to an Arduino while avoiding common mistakes.


๐Ÿ”น 1. Basic LED Connection (with a Resistor)

๐Ÿ›  Required Components

  • 1x Arduino (Uno, Mega, Nano, etc.)
  • 1x LED (any color)
  • 1x Resistor (220ฮฉ – 1kฮฉ)
  • Jumper wires

๐Ÿ›  Wiring:

ComponentConnection
LED Anode (+, long leg)Arduino Digital Pin (e.g., D7)
LED Cathode (-, short leg)Resistor (220ฮฉ – 1kฮฉ) โ†’ GND

๐Ÿ“Œ Why use a resistor?

  • Limits current to prevent LED burnout.
  • Typical LED current should be 5mA – 20mA.
  • For a 5V Arduino, a 220ฮฉ – 1kฮฉ resistor is recommended.

โœ… Example Arduino Code: Blink an LED

#define LED_PIN 7  // LED connected to pin 7

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

void loop() {
    digitalWrite(LED_PIN, HIGH);  // Turn LED ON
    delay(1000);  // Wait 1 second
    digitalWrite(LED_PIN, LOW);   // Turn LED OFF
    delay(1000);
}

๐Ÿ“Œ What happens?

  • The LED blinks ON and OFF every second.

๐Ÿ”น 2. Controlling LED Brightness with PWM (Analog Output)

๐Ÿ“Œ PWM (Pulse Width Modulation) allows brightness control by adjusting how long the LED is ON vs. OFF.

๐Ÿ›  Wiring (Same as Basic Setup)

  • Connect the LED to a PWM-capable pin (D3, D5, D6, D9, D10, D11 on Arduino Uno).
  • Use a 220ฮฉ – 1kฮฉ resistor.

โœ… Example Arduino Code: LED Fade Effect

#define LED_PIN 9  // PWM-capable pin

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

void loop() {
    for (int brightness = 0; brightness <= 255; brightness++) {
        analogWrite(LED_PIN, brightness);  // Increase brightness
        delay(10);
    }
    for (int brightness = 255; brightness >= 0; brightness--) {
        analogWrite(LED_PIN, brightness);  // Decrease brightness
        delay(10);
    }
}

๐Ÿ“Œ What happens?

  • The LED gradually increases and decreases in brightness.

๐Ÿ”น 3. Connecting Multiple LEDs to Arduino

๐Ÿ“Œ You can control multiple LEDs individually or in a sequence.

โœ… Example: Blinking Multiple LEDs

#define LED1 5
#define LED2 6
#define LED3 7

void setup() {
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
}

void loop() {
    digitalWrite(LED1, HIGH);
    delay(500);
    digitalWrite(LED1, LOW);

    digitalWrite(LED2, HIGH);
    delay(500);
    digitalWrite(LED2, LOW);

    digitalWrite(LED3, HIGH);
    delay(500);
    digitalWrite(LED3, LOW);
}

๐Ÿ“Œ What happens?

  • Each LED blinks in sequence every 0.5 seconds.

๐Ÿ”น 4. Using a Transistor to Control High-Power LEDs

๐Ÿ“Œ If you want to control a high-power LED (e.g., 12V LED strips or 1W/3W LEDs), an Arduino cannot directly provide enough current.

๐Ÿ›  Required Components

  • 1x NPN Transistor (e.g., BC547, 2N2222, TIP120)
  • 1x 1kฮฉ Resistor (Base Resistor)
  • 1x High-Power LED or LED Strip (12V)
  • 1x External 12V Power Supply

๐Ÿ›  Wiring

ComponentConnection
LED Anode+12V Power Supply
LED CathodeTransistor Collector
Transistor EmitterGND
Transistor BaseArduino PWM Pin (through 1kฮฉ Resistor)

โœ… Example Code: PWM Control for High-Power LED

#define LED_PIN 9  // Connect to transistor base via 1kฮฉ resistor

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

void loop() {
    analogWrite(LED_PIN, 128);  // 50% Brightness
    delay(2000);
    analogWrite(LED_PIN, 255);  // 100% Brightness
    delay(2000);
}

๐Ÿ“Œ Why use a transistor?

  • Arduino cannot handle high-current loads.
  • A transistor allows the Arduino to control high-power LEDs with an external power source.

๐Ÿ”น 5. Using a MOSFET for Controlling LED Strips

๐Ÿ“Œ For RGB LED strips, a MOSFET (IRLZ34N, IRF540N) is a better option than a transistor.

๐Ÿ›  Wiring for MOSFET Control

ComponentConnection
LED Strip +12V Power Supply
LED Strip –MOSFET Drain
MOSFET SourceGND
MOSFET GateArduino PWM Pin (through 220ฮฉ Resistor)

โœ… Example Code for RGB LED Strip

#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11

void setup() {
    pinMode(RED_PIN, OUTPUT);
    pinMode(GREEN_PIN, OUTPUT);
    pinMode(BLUE_PIN, OUTPUT);
}

void loop() {
    analogWrite(RED_PIN, 255);  // Full Red
    analogWrite(GREEN_PIN, 0);
    analogWrite(BLUE_PIN, 0);
    delay(1000);

    analogWrite(RED_PIN, 0);
    analogWrite(GREEN_PIN, 255);  // Full Green
    delay(1000);

    analogWrite(RED_PIN, 0);
    analogWrite(GREEN_PIN, 0);
    analogWrite(BLUE_PIN, 255);  // Full Blue
    delay(1000);
}

๐Ÿ“Œ What happens?

  • The RGB LED strip cycles through Red, Green, and Blue colors.

๐Ÿ”น 6. Common Mistakes When Connecting LEDs

โŒ Connecting an LED without a resistor โ†’ Can burn out the LED or damage the Arduino pin.
โœ… Always use a resistor (220ฮฉ – 1kฮฉ) to limit current.

โŒ Connecting a high-power LED directly to an Arduino โ†’ Can overload the Arduino’s pin.
โœ… Use a transistor or MOSFET to control high-current LEDs.

โŒ Using a wrong MOSFET (high gate threshold voltage) โ†’ Will not turn on fully with Arduino’s 5V.
โœ… Use a logic-level MOSFET (e.g., IRLZ34N) that works with 5V logic.


๐ŸŽฏ Conclusion

  • Basic LEDs can be connected with a resistor directly to Arduino.
  • PWM allows brightness control (use analogWrite for smooth fading).
  • For multiple LEDs, use sequential programming or shift registers.
  • For high-power LEDs, use a transistor (BC547, TIP120) or MOSFET (IRLZ34N, IRF540N).
  • For LED strips, use a MOSFET to control brightness and color.
๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.

Supplier product photo

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu