Hi everyone, this is a general overview on LED basics and how to use them in your projects. I’m not going to go very deep into technical details but after reading this I hope you will be able to quickly get up and running with a Light Emitting Diode.
This article is mostly aimed at DIP LEDs – the type that you can see in the below image (a hard plastic case with two connecting pins), and not the small surface mounted (SMD) type.

If you want to read more detailed information on the physics of a these devices, how do they work and much more, there’s a great Wikipedia page at this link: https://en.wikipedia.org/wiki/Light-emitting_diode

Note: All references to Forward Voltage in this article refer to the forward voltage that is dropped on the LED (that can be observed by using a voltmeter on the LED pins) at a specific current (for example at 20mA).

A LED is a current controlled light source. What this means is that you will have to control the current in order to make it light up, and the forward voltage is just something that can be observed.

To follow this tutorial, you will need:

  • Breadboard
  • LED
  • 150 Ω Resistor
  • +5V power source or 9V and 350 Ω resistor instead of the 150 Ω one OR a 5V regulator such as L7805 or LM723CN

The characteristics or properties of a typical LED and how to power it.

LED with anode connected to Anvil

Some LEDs have their Anode (+) connected to the Anvil rather than to the Post.

LED Basics, the short version:

  1. You have to use a Resistor to limit the amount of current that flows through a LED, otherwise it will just burn out and you’ll not be able to use its 25.000 hours of lifespan. Yes, that’s right. Typical Light Emitting Diodes can last for 25.000 up to 100.000 hours.
  2. Calculate the resistance: (VCC – Led Voltage) / Led Current in Amperes or R=U/I where R is the resistance that you are calculating, U is (VCC – Led Voltage) and I is the current that you want flowing through the LED
    • Currents may be specified in miliamps (mA), so divide the mA value by 1000 to get the value in Amps. 20mA in Amps is 20/1000 = 0.02 Amps
  3. Terminals: Anode(+) and Cathode(-).
    • How to visually determinine (+) and (-): The Anode(+) is longer and is usually connected to the smaller metal piece inside the LED, called the Post.
  4. Typical characteristics: Voltage = 2V, Current = 20mA = 0.02 Amps

This image shows a different convention. Although I haven’t encountered that many LEDs to follow this one, for some of them the Anode (+) is connected to the Anvil inside the LED, and not to the Post.

Led powered by Arduino 5V pin

You can power a led by simply connecting it to Arduino’s 5V pin.

+5V from Arduino

As shown in the image, you can use Arduino’s 5V VCC pin to light up a LED. Just be careful not to source too much current from this pin, as its limit is 200mA or 400mA if your Arduino board has 2 GND pins.

Only the VCC has this high limit.

Regular I/O pins have an absolute limit of 40mA and the recommended usage is 20mA


Arduino digital pin turns on LED

You can control a LED directly through a digital pin on Arduino.

Control a LED through a I/O pin on Arduino

Connecting it directly to Arduino’s 5V VCC pin, though it works, it’s not that interesting, right? You want to decide when a led is turned on or off. Well you can do that by directly connecting to an I/O pin.

Either connect 1 led or 2 leds in series to an Arduino I/O pin because the recommended current is 20mA on these pins

It’s ok to connect 2 in series because the you don’t need twice the current when you connect them in series. If you were to do it in parallel, then you would need 40mA which is the absolute limit for an I/O pin, and it’s not recommended to use a pin at its maximum limit.

An example skectch is this:

#include arduino.h;
int ledPin = 8; // set the pin that you're connecting the LED to
unsigned long timeTracker = 0; // variable to help us track time without delay()
bool isOn = false; // variable to store the current state of the LED
unsigned long interval = 1000; // how many milliseconds should pass between changing the states on/off

void setup(){
  pinMode(ledPin, OUTPUT);

void loop(){
  uint8_t writeState = LOW;
  if(millis() - timeTracker interval){ // if the interval has passed
    isOn = !isOn;
    if(isOn) { writeState = HIGH; }
    digitalWrite(ledPin, writeState);
    timeTracker = millis();


What is a led and what is it good for?

You probably already know this since you’re here, but LED stands for “Light Emitting Diode”. These components can be used in many ways and for many purposes:

A very common use of LEDs is in flashlights.

Bring light to dark places

You can simply use a Light Emitting Diode to light dark places, and this is probably the most simple way to use a Light Emitting Diode.

This 7 segment display is used to output the value that a voltmeter reads – Off(left) and On(Right)

Display Stuff

You could also use them to display letters, numbers or images.

I’m not only talking about displays such as the 7 segment display, but also about taking a pile of LEDs, arranging them in the form of a rudimentary display and then individually turning on the ones that you need to form the letter, number or image.

An IR Led transmitting a simple ON/OFF

Wireless Communication. Oh Yeahhhh, this is getting interesting

Another great way for making use of Light Emitting Diode is wireless communication. You can transmit a simple ON/OFF or you can transmit and even receive general data (though using a LED at the receiving end is not common) . More on this subject in a future article.

Light Emitting Diodes are also used for proximity sensors, photogates, measuring speed using LEDs, detecting movement, mouse scroll wheels, light detectors and much more.

How to use a LED

Ok, so now you know that there are many interesting ways in which a Light Emitting Diode can be put to good use. But how do you actually use one, how do you make it light up?

LED and its symbol

A LED and the symbol that is used to represent it in circuiat diagrams or schematics

A regular LED has two terminals, an Anode(+) and a Cathode(-) and only conducts electricity in one direction.

The thing is that you can’t just directly connect a battery or a power source to a LED because it needs a specific setup in order to be used safely.

For example, watch what can happen when it is connected directly to a battery, without using a current limiting resistor:

Correct way to connect a LED

A correct way to connect a LED in a circuit, using a limiting resistor.

A correct way to connect a led is to use a resistor to limit the current that can flow through the LED.

The characteristics of a LED that you will need in order to connect it are:

  • Forward Voltage: The voltage that is dropped between the terminals.
  • Forward Current: The maximum current that can flow through the LED without damaging it.

A LED’s datasheet has many more characteristics listed, and you may or may not need all of them, depending on the project that you have in mind.

Typical LED and how to power it.

The characteristics or properties of a typical LED and how to power it.

Determining the terminals – positive and negative

Longer Anode or Anode(+) to Post

Usually, the Anode(+) is longer.
If the terminals are equal and you can see inside the LED, the Anode (+) is the terminal that is smaller on the inside of the LED – the metal piece inside is called the Post.

The Cathode(-) is connected to the Anvil (a large metalic piece inside the LED). An easy way to remember this is Plus goes to Post, and the post is easy to recognize because it is the smaller piece inside the LED that looks sort of like a post.

LED with anode connected to Anvil

Some LEDs have their Anode (+) connected to the Anvil rather than to the Post.

A different convention: Anode(+) to Anvil

I haven’t encountered that many LEDs to follow this other convention, but there most definitely are LEDs that have their Anode(+) connected to the Anvil inside, and not to the Post

LED D-coding - flat side

Some LEDs can be D-coded, meaning that they have a flat side, indicating the Cathode.


Some Light Emitting Diodes are also marked by having a flat side on the Cathode(-) side of the package, as you can see in the image. This feature is called a D-Code and it can help you determining which side is (-).

Keep in mind that conventions are just that: conventions. Therefore not all manufacturers / models use these conventions. However, if you keep your LEDs well organized, you only need to determine the conventions for one LED in your box, and you’ll immediately know how to use all of them.

Calculating the value that is needed for the current limiting resistor

We know the following:

  • Forward Voltage = 2V
  • maximum current = 20mA
  • Power Source Voltage = 5V

Since the LED and Resistor are connected in series, we can calculate the voltage drop over the resitor as:

Power Source Voltage minus the LED Forward Voltage, so

Voltage across resistor = 5V – 2V = 3V

Note: The forward voltage is not something that we have  to apply to a LED, rather it is something that results from us passing a certain current through a LED. For example, if you pass 20mA to a certain LED, you’ll get – for example – a 2V Forward Voltage across its terminals.

However, for the same LED, if you pass only 10mA through it, you may get – for example – 1.8V Forward Voltage across its terminals.

This is why LED datasheets specify the Forward Voltage at a specific current, because it varies depending on the current. With a LED, the Forward Voltage, Current and temperature are always very dependent on each other.

Now we know the voltage across resistor and the desired current (either the max 20mA or a lower one of our choice), so we can use Ohm’s Law U=I x R to determine R with the formula:

R = U / I

This means that:

Resistance = Voltage across resistor / Current through resistor

 R = 3V / 0.02A = 150 Ω 

Now you can go looking in your resistors box, grab a 150 Ohm resistor and create a simple LED circuit powered by a 5V source such as your Arduino, Rasberry PI, or any other device that can provide a 5V source.

You can connect a LED in any configuration that you want, as long as the current is limited. Therefore, you can use one resistor or multiple resistors.

For example, in the example above you can use 2x 300 Ohm resistors in parallel or 2x 75 Ohm resistors in series. Either way, the total resistance is the same.

2x 75 Ohms = 150 Ohms is pretty clear, but in case you’re wondering why 2x 300 Ohm = 150, the answer is because they are connected in parallel.
When you connect two resistors in parallel, their total resistance is calculated using the formula:
1/R Total = 1/R1 + 1/R2
This means that 1/R Total = 1/300 + 1/300 = 2/300, which means that R Total is the inverse of this, which is 150 Ohms
The same formula applies no matter how many resistors you are using or their value, so you can have something like:

1/RTotal = 1/150 + 1/300 + 1/150 + 1/450 = 17/900 which would mean that the total resistance is the inverse of this value, meaning 52.94 Ohms

The complete formula is:

1/R Total = 1/R1 + 1/R2 + 1/R3 + ……. + 1/Rn

Powering a LED from 9 Volt and 30 Volt

Supply the power from any voltage source as long as the voltage and current are properly limited.


You can use any available voltage to power a Light Emitting Diode, as long as it is higher that the rated voltage (Forward Voltage) of the led.

The first schematic (top) shows how you can use a 9 Volt battery by simply changing the value of the resistor.

The second schematic (bottom) shows how you can use a 30 Volt supply through a simple voltage regulator circuit.

One more thing: you may be wondering from where did I pull out the 2V and 20mA used in the calculations above. Well, these are just some common value for typical LEDs

However, be aware of the fact that you may come across Resistor LEDs at some point. These are special Light Emitting Diodes that have built-in resistors. For example, such a LED can be rated for 12V Forward Voltage and 10mA current, or 5V Forward voltage and 10mA current.

These special LEDs are not as common as the standard ones, therefore you shouldn’t worry about them, but it’s good to know this when you purchase LEDs for a project or when you come across a LED in a circuit and there is no limiting resistor for it.

You can find an article on typical voltage ratings by emitted color here: LED Voltages by Color