4.4 Controlling LEDs
4.4.1 Light Emitting Diode
An LED (Light Emitting Diode) is an electronic component that produces light when current flows through it in the correct direction.
LEDs are commonly used in Arduino projects as indicators or simple output devices.
A typical LED circuit requires:
- Arduino board
- LED
- Current-limiting resistor
- Jumper wires
- Breadboard
The resistor is used to limit current and protect the LED.
4.4.2 Basic LED Control
Example:
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
4.4.3 Controlling LED Brightness
PWM can be used to control LED brightness.
int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
analogWrite(ledPin, 50);
delay(1000);
analogWrite(ledPin, 150);
delay(1000);
analogWrite(ledPin, 255);
delay(1000);
}
The LED will produce different brightness levels.
4.4.4 Applications of LEDs
LEDs can be used to indicate:
- Power status
- Sensor activation
- Warning conditions
- System errors
- Communication status
- Alarm conditions
- Device operating modes


