top of page

Interfacing an LED with Arduino



Connecting an LED (Light Emitting Diode) to an Arduino is one of the simplest circuits you can build and is ideal for learning how to control outputs.

Components:

  • Arduino (any model, like Uno)

  • LED

  • Resistor (220Ω or 330Ω recommended to limit current)

  • Breadboard (optional)

  • Jumper wires

Understanding the LED:

  • Anode (long leg): Connects to the positive voltage (e.g., an Arduino digital pin).

  • Cathode (short leg): Connects to ground (GND).

Circuit Connections:

  1. Connect the anode (long leg) of the LED to a digital pin on the Arduino (e.g., D13) through a 220Ω resistor.

  2. Connect the cathode (short leg) of the LED to the GND pin on the Arduino.

Wiring Diagram:

  • Digital Pin 13 (D13) → Resistor (220Ω) → LED anode (long leg)

  • LED cathode (short leg) → GND


Code Example:

int ledPin = 13; // Pin where the LED is connected


void setup() {

pinMode(ledPin, OUTPUT); // Set the LED pin as output

}


void loop() {

digitalWrite(ledPin, HIGH); // Turn the LED on

delay(1000); // Wait for 1 second

digitalWrite(ledPin, LOW); // Turn the LED off

delay(1000); // Wait for 1 second

}



How the Code Works:

  • pinMode(ledPin, OUTPUT): Configures the pin connected to the LED as an output.

  • digitalWrite(ledPin, HIGH): Turns the LED on by providing a HIGH signal.

  • digitalWrite(ledPin, LOW): Turns the LED off by providing a LOW signal.

  • delay(1000): Waits for 1 second (1000 milliseconds) between turning the LED on and off.

Testing:

  1. Upload the code to your Arduino using the Arduino IDE.

  2. The LED should blink on and off at 1-second intervals.

This simple setup can be adapted for more complex projects, such as controlling multiple LEDs or using PWM (Pulse Width Modulation) to adjust brightness.

49 views0 comments

Recent Posts

See All

What is Arduino?

Arduino is an open-source electronics platform that makes it easy to create interactive projects. It consists of both hardware (a...

Comentários


bottom of page