A Light Emitting Diode (LED) is a semiconductor device that emits light when an electric current flows through it. LEDs are highly efficient, long-lasting, and require low power to operate. They are widely used in various applications such as indicator lights, digital displays, lighting, signage, and as components in electronic devices.
Pin Number | Name | Description |
---|---|---|
1 | Anode (+) | The positive side of the LED, longer lead |
2 | Cathode (-) | The negative side of the LED, shorter lead |
R = (Vsource - Vf) / If
, where Vsource
is the supply voltage.// Define the LED pin
const int ledPin = 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 prevent damage to the LED.
Q: How do I choose the right resistor for my LED? A: Calculate the resistor value using Ohm's law, considering the supply voltage and the LED's forward voltage and current.
Q: Can I use one resistor for multiple LEDs? A: It's best to use individual resistors for each LED to ensure they all receive the correct current.
Q: What happens if I reverse the polarity of the LED? A: The LED will not light up if the polarity is reversed, and prolonged reverse voltage may damage the LED.