A Light-Emitting Diode (LED) is a semiconductor light source that emits light when current flows through it. Electrons in the semiconductor recombine with electron holes, releasing energy in the form of photons. This effect is called electroluminescence. LEDs are widely used in a variety of applications ranging from simple indicator lights on electronic devices to advanced lighting solutions in homes, offices, and outdoor areas.
Pin Number | Name | Description |
---|---|---|
1 | Anode (+) | Connects to the positive supply voltage |
2 | Cathode (-) | Connects to the ground (0V) |
Identify the Anode and Cathode: The longer leg of the LED is usually the anode (positive), and the shorter leg is the cathode (negative). The flat side of the LED lens casing also indicates the cathode side.
Current Limiting Resistor: Always use a current limiting resistor in series with the LED to prevent it from drawing too much current and burning out. The value of the resistor can be calculated using Ohm's law: R = (Vsupply - Vf) / If
.
Connecting to Power Source: Connect the anode of the LED to the positive side of the power source through the current limiting resistor, and the cathode to the negative side (ground).
// Define the LED pin
const int ledPin = 13; // Most Arduino UNOs have an onboard LED on pin 13
void setup() {
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH);
delay(1000); // Wait for 1 second
// Turn the LED off
digitalWrite(ledPin, LOW);
delay(1000); // Wait for 1 second
}
Q: Can I connect an LED directly to a battery? A: No, you should always use a current limiting resistor to protect the LED from excessive current.
Q: How do I choose the right resistor for my LED?
A: Calculate the resistor value using Ohm's law: R = (Vsupply - Vf) / If
, where Vsupply
is the supply voltage, Vf
is the forward voltage of the LED, and If
is the desired forward current.
Q: Can I use a variable resistor to adjust the brightness of an LED? A: Yes, a potentiometer can be used in series with the LED to vary the current and adjust brightness. However, ensure that the current does not exceed the maximum rating.
Q: How do I know if my LED is working if it doesn't light up? A: You can test an LED with a multimeter set to the diode function. The multimeter should show a forward voltage drop when the anode and cathode are connected correctly.