DEV Community

Cover image for The Ultimate Guide to LEDs for Raspberry Pi: Types, Colors, Resistors and Fun Facts
IgorIOT
IgorIOT

Posted on

The Ultimate Guide to LEDs for Raspberry Pi: Types, Colors, Resistors and Fun Facts

Story Horse?

LEDs are everywhere.

From the tiny status LEDs on a Raspberry Pi to massive displays in stadiums and modern smart lighting systems, LEDs have completely transformed the way we produce and use light.

If you’re building projects with Raspberry Pi, Java, Pi4J, Arduino, or electronics in general, understanding LEDs is one of the most important skills you can learn.

In this guide, we’ll explore how LEDs work, the different sizes and colors available, SMD LEDs, resistor calculations, brightness ratings, common beginner mistakes, and some fascinating facts about these amazing components.

What is an LED?

LED stands for Light Emitting Diode.

An LED is a semiconductor device that emits light when an electrical current flows through it.

Unlike traditional incandescent bulbs, which generate light by heating a filament, LEDs convert electrical energy into light much more efficiently.

Because of their efficiency, low power consumption, and long lifespan, LEDs are used in countless applications, including:

  • Raspberry Pi projects
  • Consumer electronics
  • Automotive lighting
  • Home lighting
  • Traffic signals
  • Industrial equipment
  • Digital displays


Picture 01: Led anatomy

For more details

How Does an LED Work?

An LED is a type of diode, meaning it only allows current to flow in one direction.

Every LED has two terminals:

  • Anode (+) – positive terminal
  • Cathode (-) – negative terminal

When connected correctly, current flows through the LED and light is produced.

If the LED is connected backwards, it will not light up.

For traditional through-hole LEDs:

  • The longer leg is usually the anode.
  • The shorter leg is usually the cathode.
  • The flat edge on the LED body typically indicates the cathode.


Video 01: How LED Works

Common LED Colors and Forward Voltage

Different LED colors require different forward voltages.


Table 01: Led colors

This is why resistor calculations may differ depending on the LED color you are using.


Picture 02: Led color

Common LED Sizes

The most popular LEDs used by hobbyists are through-hole LEDs.

3 mm LEDs

Small and compact.

Commonly used for:

  • Status indicators
  • Small electronic projects
  • Low-profile designs

5 mm LEDs

The most popular LED size.

Commonly used for:

  • Raspberry Pi projects
  • Breadboard circuits
  • Educational electronics kits

8 mm and 10 mm LEDs

Larger LEDs with greater visibility.

Commonly used for:

  • Decorative lighting
  • Signage
  • High-visibility indicators

The size refers to the diameter of the LED's lens and primarily affects its appearance, viewing angle, and perceived brightness rather than its electrical behavior. Smaller 3 mm LEDs are compact and ideal for indicator lights, while 5 mm LEDs are the most widely used due to their balance of size and visibility. Larger 10 mm LEDs offer increased visibility and are often chosen for projects where the LED needs to be seen from a greater distance. Regardless of size, LEDs should always be used with an appropriate current-limiting resistor, and their electrical specifications should be verified using the manufacturer's datasheet.


Picture 03: Led sizes

LEDs in a variety of shapes


Picture 04: Formats

What Does SMD Mean?

SMD stands for Surface Mount Device.

Unlike traditional LEDs that have wire leads passing through a circuit board, SMD LEDs are soldered directly onto the surface of a PCB.

Because they are smaller and easier to manufacture in large quantities, SMD LEDs are found in nearly every modern electronic device.

You can find SMD LEDs in:

  • Smartphones
  • TVs
  • Computer monitors
  • Raspberry Pi boards
  • LED strips
  • Smart lighting systems

Popular examples include:

  • 3528
  • 5050
  • 2835
  • 5730

The numbers usually represent the physical dimensions of the LED package.

For example:

  • 5050 = 5.0 mm × 5.0 mm
  • 3528 = 3.5 mm × 2.8 mm


Picture 05: SMD

LED Brightness: Lumens, Millicandela and Viewing Angle

One of the most confusing LED specifications for beginners is brightness.

Lumens (lm)

Lumens measure the total amount of visible light produced by a light source.

The higher the lumen rating, the more light the LED produces overall.

Millicandela (mcd)

Millicandela measures light intensity in a specific direction.

A high mcd value does not always mean the LED is brighter overall.

Sometimes it simply means the light is concentrated into a narrow beam.

Viewing Angle

The viewing angle describes how widely the light is distributed.


Table 02: Viewing Angle

A narrow-angle LED often appears brighter because the light is concentrated into a smaller area.

Clear vs Diffused LEDs

In addition to different sizes, LEDs are also available with different lens finishes, the most common being diffused and clear (transparent). Diffused LEDs have a frosted lens that scatters light in multiple directions, producing a softer and more uniform glow that is visible from a wider viewing angle. Clear LEDs, on the other hand, use a transparent lens that focuses the light more directly, often making them appear brighter when viewed head-on. Because of this focused beam, clear LEDs are commonly used when maximum brightness or visibility is desired, while diffused LEDs are often preferred for indicators and projects where an even distribution of light creates a more pleasing visual effect. The choice between the two is usually based on the desired appearance rather than electrical characteristics, as both types are connected and controlled in the same way.

Clear LEDs

Characteristics:

  • Transparent lens
  • Focused beam
  • Higher apparent brightness
  • Better for long-distance visibility

Diffused LEDs

Characteristics:

  • Frosted lens
  • Softer light output
  • Wider distribution
  • Better for indicators and decorative projects

For Raspberry Pi projects, diffused LEDs are often easier on the eyes.

RGB LEDs

RGB LEDs combine three colors in a single package:

  • Red
  • Green
  • Blue

By controlling the brightness of each color, thousands of color combinations can be created.

RGB LEDs are commonly used in:

  • Decorative lighting
  • Gaming setups
  • Smart home projects
  • Raspberry Pi projects

Examples include:

  • Standard RGB LEDs
  • WS2812B LEDs
  • NeoPixels
  • SK6812 LEDs


Picture 06: Led types

Why Do LEDs Need Resistors?

One of the most common beginner mistakes is connecting an LED directly to a power source.

Without a resistor, too much current can flow through the LED, causing permanent damage.

A resistor limits the current to a safe value.
The resistor value can be calculated using:

R = (Vsupply − Vled) ÷ I

Where:

  • Vsupply = power source voltage
  • Vled = LED forward voltage
  • I = desired current

For example:

  • Supply Voltage = 5V
  • Red LED Voltage = 2V
  • Current = 20mA

Result:

150 Ω resistor

In practice, hobbyists often use:

  • 220 Ω
  • 330 Ω

Both values work well for most Raspberry Pi LED projects.


Picture 07: Resistor


Video 02: LED Circuit Design

ledcalculator

Recommended Resistors for Raspberry Pi

Since Raspberry Pi GPIO pins operate at 3.3V, a 220 Ω resistor is often a safe and simple choice.


Table 03: Resistors

Always verify the specifications of your LED before connecting it.

LED Polarity Tricks

Not sure which side is positive or negative?

Here are some easy ways to identify the cathode:

  • The shorter leg is usually the cathode
  • The flat edge indicates the cathode
  • The larger internal metal piece is usually connected to the cathode

Always double-check before powering a circuit.

Why Do LEDs Come in Different Colors?

Many people assume the color comes from a colored plastic lens.

In reality, the color is determined by the semiconductor material used inside the LED.


Table 04: colors

This is why different LED colors require different forward
voltages.

Infrared and Ultraviolet LEDs

Not all LEDs produce visible light.

Infrared LEDs (IR)

Infrared LEDs emit light outside the visible spectrum.

Common applications:

  • TV remote controls
  • Security systems
  • Motion sensors
  • Communication devices

Ultraviolet LEDs (UV)

UV LEDs emit ultraviolet light.

Common applications:

  • Currency validation
  • Sterilization equipment
  • Resin curing
  • Scientific instruments

Connecting Multiple LEDs

When building larger projects, you may need multiple LEDs.

Series Connection

LEDs are connected one after another.

Advantages:

  • Same current flows through all LEDs
  • Efficient use of power

Disadvantages:

  • If one LED fails, the entire chain may stop working

Parallel Connection

LEDs are connected side by side.

Advantages:

  • Individual LEDs operate independently

Disadvantages:

  • Current balancing becomes important
  • Each branch may require its own resistor

For many projects, series connections are preferred when possible.


Picture 08: Series & Parallel

How Much Power Does an LED Consume?

LED power consumption depends on the type of LED.


Table 05: power consume

Modern LEDs are often much more efficient than older designs.

LEDs and Raspberry Pi GPIO Limits

When using LEDs with a Raspberry Pi, it is important to understand GPIO limitations.

GPIO pins:

  • Operate at 3.3V
  • Can only provide limited current
  • Should not drive large loads directly

For larger LED arrays, LED strips, or high-power LEDs, use:

  • Transistors
  • MOSFETs
  • Dedicated drivers

This protects both the Raspberry Pi and your LEDs.


Picture 09: Raspberry PI

Special Types of LEDs

Not all LEDs are simple indicator lights.

Flashing LEDs

These LEDs contain an internal circuit that automatically flashes the light.

Bi-Color LEDs

Contain two colors inside a single package.

Examples:

  • Red/Green
  • Red/Yellow

RGB LEDs

Contain three LEDs in one package and can create millions of colors.


Picture 10: RGB

Addressable LEDs

Each LED can be controlled individually.

Examples:

  • WS2812B
  • NeoPixel
  • SK6812

These are perfect for animations and visual effects.

High-Power LEDs

Standard LEDs typically consume around 20mA.

High-power LEDs can operate at:

  • 1W
  • 3W
  • 5W
  • 10W
  • 50W or more

These LEDs often require:

  • Heat sinks
  • Constant-current drivers
  • Thermal management

Applications include:

  • Floodlights
  • Automotive lighting
  • Industrial illumination

The Evolution of LEDs

LED technology has evolved dramatically over the last few decades.

1962

The first practical red LED was developed.

1970s

Yellow and green LEDs became available.

1990s

Efficient blue LEDs were invented.

2000s

White LED lighting became commercially viable.

Today

Smart RGB LEDs, addressable LED strips, and highly efficient lighting systems dominate the market.

LED Applications You Use Every Day

You probably interact with LEDs hundreds of times per day.

LEDs can be found in:

  • TVs
  • Monitors
  • Smartphones
  • Cars
  • Traffic lights
  • Routers
  • Raspberry Pi boards
  • Keyboards
  • Smart watches
  • Home appliances

Modern life would look very different without LEDs.

LED Myth Busting

Myth: All LEDs Need 20mA

False.

Many modern LEDs operate perfectly at lower currents.

Myth: Bigger LEDs Are Always Brighter

False.

Brightness depends on efficiency, design, and viewing angle.

Myth: LEDs Never Burn Out

False.

LEDs gradually degrade over time and eventually lose brightness.

Fun LED Facts

LEDs Can Last Over 50,000 Hours

A quality LED can operate continuously for years before failing.

Blue LEDs Changed the World

The invention of efficient blue LEDs made modern white LED lighting possible.

This breakthrough earned the inventors the 2014 Nobel Prize in Physics.


Video 03: Why It Was Almost Impossible to Make the Blue LED

LEDs Are Extremely Efficient

Modern LEDs convert much more energy into light than traditional incandescent bulbs.

This results in:

  • Lower power consumption
  • Less heat generation
  • Longer lifespan

LEDs Can Also Detect Light

A little-known fact is that LEDs can act as primitive light sensors under certain conditions.

While not as effective as photodiodes, they can detect changes in light levels.

Common Beginner Mistakes

When starting with LEDs, avoid these common errors:

  • Connecting LEDs backwards
  • Forgetting the resistor
  • Using the wrong resistor value
  • Exceeding Raspberry Pi GPIO current limits
  • Miswiring RGB LEDs
  • Assuming all LEDs have the same voltage requirements


Picture 11: Mistakes

What’s Next?

To help you continue experimenting, all of the code from this tutorial is available as part of the Pi4J LED Playground project, a collection of LED-based examples designed to demonstrate different GPIO concepts and Pi4J features.

The project serves as a hands-on playground where you can explore progressively more advanced scenarios, including different blinking patterns, multiple LEDs, traffic light simulations, animations, and other creative ways of interacting with Raspberry Pi hardware.

Whether you're new to physical computing or looking to deepen your understanding of Pi4J, the playground provides a practical environment for learning through experimentation.

You can find the project on GitHub: Pi4J LED Playground

Feel free to clone the repository, modify the examples, and create your own LED effects. The best way to learn GPIO programming is by experimenting, and this project is designed to be a starting point for exactly that journey.

Stay tuned for the upcoming Pi4J LED Playground project series.

Links

https://en.wikipedia.org/wiki/Light-emitting_diode

https://en.wikipedia.org/wiki/LED_circuit

https://ledcalculator.net/

https://www.digikey.ie/en/resources/conversion-calculators/conversion-calculator-led-series-resistor

https://www.omnicalculator.com/physics/led

https://uk.rs-online.com/web/content/discovery/tools-and-calculators/led-resistor-calculator

Top comments (0)