Calculating LED Resistor Values
Why Resistors Are Needed
The reason for connecting a resistor when using an LED is to prevent the LED from burning out due to excessive current. The resistor can be connected to either the positive or negative terminal of the LED.

LED datasheets display voltage (forward voltage) and current (forward current) specifications. Below is an example of a red LED datasheet.

For the LED above, when 2V is applied, 20mA of current flows, and in this case, no separate resistor needs to be connected.
The following graph shows the relationship between LED voltage and current. In the case of Raspberry Pi, the GPIO output voltage is 3.3V, so if voltage is applied directly to a red LED without connecting a resistor, current far exceeding 20mA will flow, causing the LED to burn out. Therefore, when connecting an LED, if the supply voltage is greater than the LED’s forward voltage, a resistor must be connected to limit the current.
If the LED datasheet is not available, you can find the voltage and current in the table below.
Resistor Value Selection
Ohm’s law is used to calculate the resistor value.
- Ohm’s Law: V(voltage) = I(current) X R(resistance)
Using a red LED as an example, with a forward voltage of 2V and forward current of 20mA:
- R(resistance) = (3.3V(supply voltage) – 2V(forward voltage)) / 0.02A (current) = 65 Ω
According to the calculation, a 65Ω resistor is needed. However, one more factor to consider is the maximum output current of the GPIO pin of the hardware being used. For example, the maximum current output of Raspberry Pi GPIO pins is approximately 8mA, and the total current sum of all output pins should not exceed 50mA. Therefore, to use an LED with Raspberry Pi, recalculating with a current of 5mA:
- R(resistance) = (3.3V(supply voltage) – 2V(LED voltage)) / 0.005A (current) = 260 Ω
Therefore, you can use a commonly available 220-ohm resistor, which is similar to the calculated result. The current at this time is approximately 5.9mA, making it safe to use. Since the current flowing is less than the rated current of 20mA, it will be relatively dimmer, but generally provides an acceptable level of brightness.
The approximate resistor values by color calculated using the above formula are as follows (based on Raspberry Pi):
Color | Resistance |
---|---|
Red | 220Ω |
Yellow | 180Ω |
Green | 220Ω |
White | 100Ω |