LED Current Control and The Arduino: Tutorial

Powering LEDs in Series

1W LEDThose of you who have used a single 5mm LED with an Arduino  probably have used a currently limiting resistor in series the LED.  Nothing wrong with that.

However another way to power the LED is to use current control.   This has the advantage of allowing you to place multiple LEDs in series.  This is because current control raises or lowers the voltage to control the current.

In this article, we will configure an LM317 to act as a current controller.  This is not new stuff to those of us who have been chasing trons for a while, but is necessary if you wish to advance your Arduino expertise beyond the ability to use bricks.

Alas, this tutorial would not be complete without showing you how control these LEDs with your Arduino.   Like some of my other tutorials,  I will employ a TIP122 Darlington pair transistor to do just that.

Where to Get the Parts

In addition to your stash of resistors and LEDs, you will want the LM317 and TIP122.

The LM317 can be purchased at any of the retailers below:




The TIP122 can also be purchased from any of the following:



Deal Extreme

LM317 Voltage Regulator Pin Outs

The LM317 is most commonly found in a TO220 package.  It only has three pins and we will be using all of them in this tutorial.

LM317 Pin Outs

The LM317 Voltage Regulator for Current Control

The use of an LM317 as a constant current source comes right from the data sheet.     The schematic below shows how to configure the LM317 as a current regulator.   It is the value of R1 that you will be concerned about and that value is determined by the type of LED you are using.


LM317 LED Current Regulator Schematic Simple

The math is really simple. The factor of 1.25 also comes from the data sheet.

Let’s walk through an example:

  1. Lets say you wanted to control to 300 mA.    You would determine that your optimum resistor is:
    R1 = 1.25 / 0.300 = 4.17 Ohms
  2. Next you’re going to poke around in your box of resistors to see what you’ve got.  You probably won’t find that 4.17 Ohm resistor, so you will want to try something close.   I had a 4.7 Ohm resistor.
  3. Now you’re going to want to apply the formula to see what that gets you.
    Current Out = 1.25 / 4.7 = 266 mA.
  4. Finally, we need to do a sanity check of the power rating of the resistor.   Here we will use I2 x R to get the power dissipated by the resistor.
    Power Dissipated by Resistor = 0.2662 x 4.7 = 0.332 Watts   (a half watt resistor will do the trick)

 If you’re really particular about the current, you could search through that box of resistors to see what parallel resistor combination will get you to where you want to be.   If you had a 47 ohm and a 4.7  ohm resistor, you would find that putting them in parallel would get you very close… like 4.16 Ohms.  Take a look at this Parallel Resistance Calculator.

LM317 LED Current Control Test Circuit

For this tutorial,  I’m using the super bright 3.5V,  1W LEDs.    These LEDs happen to  have a forward current of 350 mA.   Since I’ve played with these for a bit, I happen to know that they will work just fine (albeit a little dimmer).   If you want,  put a 4.7 Ohm and a 15 Ohm Resistor in Parallel.

This is the circuit I have built.

LM317 LED Current Regulator Test Circuit

If you were to measure the voltage across each LED, you would find that they each drop about 3.2 Vdc for a total of 9.6 Vdc.

In truth,  I set my adjustable supply to about 14V for this test.   I did this because the LM317 wants an input voltage that is greater than 3 volts greater than the output.

If you were to reduce the number of LEDs to two,  you find that the LM317 regulator sets the output across the LEDs to 6.4 Vdc to keep the current at the 266 mA set by the resistor.

Current Controlled LEDs with an Arduino Tutorial

Build the Arduino Current Control LED Circuit

We’re going to use the TIP122 to sink the LEDs to ground.  This transistor is more than capable of handling the 266 mA.

Arduino LM317 LED Current Regulator TutorialCopy, Paste and Upload the Sketch


// Henry's Bench
//LED Current Control Tutorial Using an LM317

int nLedDrive = 10; // pin zero is our relay drive
int x; // Controls LED brightness

void setup() {
  pinMode(nLedDrive, OUTPUT); //
  digitalWrite(nLedDrive, HIGH); //Turn LED OFF

void loop() {
  for (x =  0; x < 256; x++){
    analogWrite(nLedDrive, x); // 0 is off, 255 is bright

Test the LED Current Control Project

When you apply power, you will see the LEDs start dim and begin to brighten.


  1. HAİKO December 27, 2016
  2. Greg November 24, 2016
  3. capnfatz@gmail.comAuthor May 27, 2016
  4. jeff May 26, 2016

Add a Comment

Your email address will not be published. Required fields are marked *