Description
Here is a complete description of the 5 mm colored LEDs (not 5 cm) and a full guide for use with Arduino, including practical programming examples.
🔌 LED Description (5 mm Light Emitting Diode)
📏 General Characteristics
- Type: LED (Light Emitting Diode)
- Diameter: 5 mm
- Typical Operating Voltage:
- Red: 1.8–2.2 V
- Yellow: 2.0–2.2 V
- Green: 2.0–3.2 V
- Blue: 3.0–3.4 V
- White: 3.0–3.4 V
- Recommended Current: 10-20 mA
- Polarity: Anode (positive, longer leg) and Cathode (negative, shorter leg)
🎨 Available Colors
- Green LED: Used to indicate active state or OK.
- Red LED: Signifies warnings, errors, or power.
- White LED: For illumination or neutral signaling.
- Yellow LED: Attention or standby state.
- Blue LED: Modern, often used for power-on or special state.
🛠️ Guide for use with Arduino
🔧 Required Components
- Arduino UNO (or compatible)
- 220Ω or 330Ω resistors
- 5mm LED (color choice)
- Breadboard
- Jumper wires
📈 Connection diagram (single LED)
Arduino PIN (es. 13) ---> Resistenza (220Ω) ---> Anodo LED
|
Catodo ---> GND
- Connect the long leg of the LED (anode) through a 220Ω resistor to a digital pin of Arduino.
- Connect the short leg (cathode) to the GND of Arduino.
💻 Example code: turn on an LED
// Pin a cui è collegato il LED
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT); // imposta il pin come uscita
}
void loop() {
digitalWrite(ledPin, HIGH); // accende il LED
delay(1000); // attende 1 secondo
digitalWrite(ledPin, LOW); // spegne il LED
delay(1000); // attende 1 secondo
}
🧪 Example: turn on 5 LEDs of different colors
⚙️ Connection
| LED | Arduino PIN | Resistance |
|---|---|---|
| Red | 2 | 220Ω |
| Green | 3 | 220Ω |
| Yellow | 4 | 220Ω |
| Blue | 5 | 330Ω |
| White | 6 | 330Ω |
🔤 Arduino Code for LED Sequence
int ledRosso = 2;
int ledVerde = 3;
int ledGiallo = 4;
int ledBlu = 5;
int ledBianco = 6;
void setup() {
pinMode(ledRosso, OUTPUT);
pinMode(ledVerde, OUTPUT);
pinMode(ledGiallo, OUTPUT);
pinMode(ledBlu, OUTPUT);
pinMode(ledBianco, OUTPUT);
}
void loop() {
digitalWrite(ledRosso, HIGH);
delay(500);
digitalWrite(ledRosso, LOW);
digitalWrite(ledVerde, HIGH);
delay(500);
digitalWrite(ledVerde, LOW);
digitalWrite(ledGiallo, HIGH);
delay(500);
digitalWrite(ledGiallo, LOW);
digitalWrite(ledBlu, HIGH);
delay(500);
digitalWrite(ledBlu, LOW);
digitalWrite(ledBianco, HIGH);
delay(500);
digitalWrite(ledBianco, LOW);
}
📘 Practical Tips
- Use different resistances for each color to avoid damage: blue and white require higher values.
- If you want more control, consider using transistor o LED driver for higher current.
- You can combine these LEDs to create a traffic light, a status indicator, or simple light effects.
🧠 Advanced Experiments
- PWM (Pulse Width Modulation): Use
analogWrite(pin, valore)to adjust brightness. - Sensors: Turn on LEDs in response to light, temperature, or motion sensors.
- Light effects: Create breathing, random flashing, or music-synced effects.
Great! Here are 3 advanced examples of using 5mm LEDs with Arduino:
🚦 1. Street traffic light with LEDs
🔧 Components
- 1 Red LED (Pin 2)
- 1 Yellow LED (Pin 3)
- 1 Green LED (Pin 4)
- 3 Resistors (220Ω)
- Arduino, breadboard, jumper
💡 Diagram
Connect the LEDs through resistors to pins 2, 3, 4 respectively and GND.
🧠 Code
int ledRosso = 2;
int ledGiallo = 3;
int ledVerde = 4;
void setup() {
pinMode(ledRosso, OUTPUT);
pinMode(ledGiallo, OUTPUT);
pinMode(ledVerde, OUTPUT);
}
void loop() {
digitalWrite(ledRosso, HIGH);
delay(3000); // 3 secondi
digitalWrite(ledRosso, LOW);
digitalWrite(ledGiallo, HIGH);
delay(1000); // 1 secondo
digitalWrite(ledGiallo, LOW);
digitalWrite(ledVerde, HIGH);
delay(3000); // 3 secondi
digitalWrite(ledVerde, LOW);
}
🔘 2. LED Toggle with Button (on/off switch)
🔧 Components
- 1 LED (e.g., Blue, Pin 8)
- 1 LED Resistor (330Ω)
- 1 Button (Pin 7)
- 1 Pull-down Resistor (10kΩ)
- Arduino
🔌 Connection
- LED (Anode to Pin 8 through resistor, Cathode to GND)
- Button between Pin 7 and 5V, with pull-down between Pin 7 and GND
🧠 Code
int ledPin = 8;
int buttonPin = 7;
bool statoLED = false;
bool statoPrecedente = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
bool lettura = digitalRead(buttonPin);
if (lettura == HIGH && statoPrecedente == LOW) {
statoLED = !statoLED;
digitalWrite(ledPin, statoLED);
delay(200); // debounce
}
statoPrecedente = lettura;
}
📱 3. Control LED via Bluetooth (from App)
🔧 Components
- LED (Red – Pin 10)
- HC-05 Bluetooth module (TX/RX)
- Arduino UNO
📲 Recommended App: Serial Bluetooth Terminal (Android) or similar
🧠 Connection
- Red LED at Pin 10 (through 220Ω resistor)
- HC-05:
- TX ➝ RX (Pin 0 of Arduino)
- RX ➝ TX (Pin 1 of Arduino, with voltage divider)
- VCC ➝ 5V
- GND ➝ GND
🔥 Note: disconnect TX/RX when uploading the sketch to Arduino.
🧠 Code
int ledPin = 10;
char comando;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
comando = Serial.read();
if (comando == '1') {
digitalWrite(ledPin, HIGH);
} else if (comando == '0') {
digitalWrite(ledPin, LOW);
}
}
}
📲 Commands from the app
- Send 1 ➝ LED on
- Send 0 ➝ LED off
Perfect! The effect “breathing” (also known as fading LED) simulates the behavior of a light that slowly turns on and off, just like if it were “breathing”. It’s a great exercise to learn about PWM (Pulse Width Modulation) with Arduino.
🌬️ Project: LED with breathing effect (fading)
🔧 Required Components
- 1 LED (preferably White, Blue or Green for a nice visual effect)
- 1 Resistor 220–330Ω
- Arduino UNO
- Breadboard and jumper
🔌 Connection diagram
| Component | Connection |
|---|---|
| LED anode | Pin 9 (PWM) |
| LED cathode | GND (via 220Ω resistor) |
The Pin 9 of Arduino supports PWM (you can see it with the symbol
~).
💻 Arduino code: breathing effect
int ledPin = 9; // Pin PWM
int luminosita = 0; // Valore PWM (0-255)
int variazione = 5; // Incremento/decremento luminosità
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
analogWrite(ledPin, luminosita); // imposta la luminosità
luminosita += variazione; // cambia luminosità
// Inverti direzione al raggiungimento di estremi
if (luminosita <= 0 || luminosita >= 255) {
variazione = -variazione;
}
delay(30); // tempo tra i cambi (più alto = respiro più lento)
}
🧪 Additional experiments
- Modify
delay(30)to make the breathing effect slower or faster. - Change
variazionea1for a softer effect. - Try with a RGB LED to fade through multiple colors (want an RGB example? I can give it to you!)
🎨 Variant: “sinusoidal breathing” (more natural)
For a more realistic effect, you can use the sine function to model the brightness (requires the library math.h on some Arduino versions):
int ledPin = 9;
float x = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
float valore = (sin(x) + 1.0) * 127.5; // da 0 a 255
analogWrite(ledPin, int(valore));
x += 0.05;
if (x > TWO_PI) x = 0;
delay(20);
}
This creates a softer “breathing” effect, similar to that of Apple devices or smart devices.
Tutorial: How to use LED GREEN – Standard super bright green LED diode from 5 mm
These green LEDs are ideal for anyone starting with Arduino and wanting to add a bit of light to their projects. They are useful for signaling states, creating indicators, or simply illuminating the environment.
What you need
- Arduino Uno
- Jumper cable
- Breadboard
Steps
- Check the datasheet for the operating voltage and maximum current of the green LED. Generally, for a standard 5mm green LED, a resistor is used between the Arduino digital pin and the anode (cathode) of the LED.
- Connect the cathode (short pin on the LED housing) to the GND of the Arduino through a jumper wire.
- Connect the anode (long pin on the LED housing) to a resistor. Check the datasheet for the maximum current to choose the right resistor, generally between 220 and 330 ohms.
- Connect the end of the resistor not connected to GND to a digital pin on the Arduino (example: pin 13).
- Open Arduino IDE and upload the following sketch to your Arduino.
- Verify the correct illumination of the LED when the digital pin is activated. If the LED does not light up, reverse the polarity or check the resistors.
- If necessary, modify the sketch to test other digital pins and vary the illumination.
- Explore further projects such as creating an led timer or a lighting sequence.
Example code
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // Accende il LED verde collegato al pin 13
delay(500);
digitalWrite(13, LOW); // Spegne il LED
delay(500);
}
Mini project
Create an led timer that automatically turns on and off your green led every minute. Use a button to start or stop the timer.
Common mistakes
- Reverse connection of the led
- Too low or too high resistance
- Digital pin not properly configured as output.
- Modifying the sketch without testing the resistances and connections.
Recommended accessories
- Arduino Uno R3
- Rgb jumper cable
- Arduino prototyping board
Frequently asked questions
How can I control multiple leds from a single pin?
Use a multiplexer or a transistor as a switch to control multiple leds with a single pin.
What is the difference between a green led and a red one?
The main difference lies in the wavelength of the emitted light, which determines the color. Green leds have a different wavelength than red leds.
Can I use these leds without Arduino?
Yes, you can directly connect LEDs to batteries or other circuits for simple illumination.











Reviews
There are no reviews yet.