How to Connect LED Light Strips to Arduino: The Ultimate Guide

One of the most common LED products is the LED strip. In this article, we will cover how to connect LED light strips to Arduino.

The rise of LED lighting has been stratospheric, and it's easy to understand why. They are inexpensive to produce, require a lot less power than other lighting options, and in most cases don't become hot, making them safe for a variety of tasks.

We'll cover how to set up the two most common types using an Arduino in this post. Even if you are new to Arduino or DIY electronics, you will be able to complete these projects since they are so simple.

lilygo Official Store

We will also control them using the Arduino IDE. While practically any compatible board might be used, this project uses an Arduino Uno (such as the NodeMCU).

Choose Your Strip

There are a few things to think about while shopping for LED strips. The first is functionality. A simple 12V RGB LED strip (SMD5050) would be the right option if you are planning to use the strips mostly for ambient lighting.

While we will be using an Arduino in this project, many of these strips come with an infrared remote to control them. Take some time shopping around; at the time of writing, it was possible to buy these strips for as low as $1 per meter.

RGB LED strip (SMD5050)

Consider the WS2811/12/12B if you want something a bit more technical. These strips, which are often referred to as “Neopixels“, include integrated chipsets that enable individual addressability. This means they are capable of providing more than simply ambient lighting.

These may be used to create a cheap LED pixel display from scratch. You may even use them to create your own personal indoor storm cloud light.

keyestudio Official Store

Just 5 volts are needed to power these strips. It is possible to power small amounts of them straight from an Arduino board, but it is normally a good idea to use a separate 5V power supply to avoid the smell of fried Arduino. These are the LEDs for you if you're seeking individually programmable LEDs. These are available for around $4 per meter at the time of this writing.

Where these strips are likely to be used is another factor to take into account. Both of these types of strips are available in varying lengths, LED densities (the number of LEDs per meter), and weatherproofing levels.

Pay attention to the numbers on the listing while browsing for LED strips. The number of LEDs per meter is often the first number, and the letters IP followed by the number are the weatherproofing. For instance, “30 IP67” means there will be 30 LEDs per meter in the listing. The number 6 indicates that it is dust-sealed, while the number 7 means that it is protected against brief immersion in water. Now that you have it, it's time to connect LED light strips to Arduino. Let's begin with the SMD5050.

Getting Connected

smd5050 parts list Connect LED Light Strips to Arduino

A few components are required to connect a 12-volt LED strip to an Arduino:

  • 1 x Arduino Uno
  • 12v RGB LED strip (SMD5050)
  • 12v Power Supply
  • 3 x 10k Ohm Resistors
  • 3 x Logic Level N-channel MOSFETs
  • 1 x Breadboard
  • Hookup wires

Let's talk about MOSFETs before setting up the circuit.

TSCINBUNY Official Store

You need something in between to protect your board if you are operating anything that is at a greater voltage than your microcontroller. Using a MOSFET is one of the simpler ways to do this. It is possible to control how much power flows between the drain and source legs by delivering pulse-width modulation (PWM) signals to the gate leg. You can control the brightness of each color on the LED strip by feeding each of its colors via the MOSFET.

To be sure that things work the way you want them to, logic-level components should be used with microcontrollers. Make sure your MOSFETs are logic-level devices and not ordinary ones.

Set up your circuit like this:

connect LED light strips to Arduino circuit
  1. Connect Arduino pins 9, 6, and 5 to the gate legs of the three MOSFETs, then connect a 10K resistor in line with each to the ground rail.
  2. Connect the source legs to the ground rail.
  3. Connect the drain legs to the green, red, and blue connectors on the LED strip.
  4. Connect the power strip to the LED strip's +12 volt rail (note that the power wire in this image is black to match the colors of the connectors on my LED strip).
  5. Connect the Arduino's ground to the ground rail.
  6. Connect the power rails to your 12-volt power supply.

Dupont connectors, which are easy to connect to, are found on the majority of LED strips. You may need to solder wires to the LED strip if yours doesn't. If you are relatively new to soldering, don't be alarmed; it's an easy task, and if you need it, we have a guide on getting started with soldering.

We will use USB to power our Arduino board for this project. Make sure you know the power limitations of your board before you opt to power it via the VIN pin.

Your circuit should look like this when it is finished:

connect LED light strips to Arduino complete circuit

It's time to create a simple Arduino sketch to control it now that you've connected everything.

Fade It Up

Open the Arduino IDE after connecting your Arduino board via USB to your computer. Under the Tools > Board and Tools > Port menus, make sure you have the appropriate board and port number selected for your board. Create a new sketch and give it a suitable name before saving it.

This sketch will turn on the lights one color at a time, keep them on for a short period, then fade them out till they are off again. Simply get the whole code from GitHub or follow along here to create the sketch on your own.

Start by defining the pins that will be used to control the MOSFETs.

#define RED_LED 6
#define BLUE_LED 5
#define GREEN_LED 9

You then need some variables to be able to proceed. Construct an overall brightness variable as well as a variable that can adjust the brightness of each color separately. Set the main brightness variable to the maximum brightness value of 255, as we will only be using it for turning the lights off.

To control how fast the fading will happen, you will also need to create a variable.

int brightness = 255;

int gBright = 0;
int rBright = 0;
int bBright = 0;

int fadeSpeed = 10;

We'll set our Arduino pins to output in your setup function. We'll also call a few functions with a 5-second break in between. Don't worry, we'll get to these functions even if they don't yet exist.

void setup() {
   pinMode(GREEN_LED, OUTPUT);
   pinMode(RED_LED, OUTPUT);
   pinMode(BLUE_LED, OUTPUT);

   TurnOn();
   delay(5000);
   TurnOff();
}

Now create the TurnOn() method:

void TurnOn() { 
   for (int i = 0; i < 256; i++) {
       analogWrite(RED_LED, rBright);
       rBright +=1;
       delay(fadeSpeed);
   }

   for (int i = 0; i < 256; i++) {
       analogWrite(BLUE_LED, bBright);
       bBright += 1;
       delay(fadeSpeed);
   }

   for (int i = 0; i < 256; i++) {
       analogWrite(GREEN_LED, gBright);
       gBright +=1;
       delay(fadeSpeed);
   }
}

Throughout the time specified by the fadeSpeed value, these three for loops bring each color to its full brightness.

Finally you need to create the TurnOff() method:

void TurnOff() {
   for (int i = 0; i < 256; i++) {
       analogWrite(GREEN_LED, brightness);
       analogWrite(RED_LED, brightness);
       analogWrite(BLUE_LED, brightness);

       brightness -= 1;
       delay(fadeSpeed);
   }
}

void loop() {

}

All three color pins are subjected to our brightness variable and brought to zero over a period using this method. To prevent compilation issues, we also need an empty loop method here.

Save this sketch after you're done. Validate the sketch, then upload it to your Arduino board. If you are receiving problems, go back over the code and look for any annoying mistakes or omitted semicolons.

Your LED strip should now ramp up each color separately, hold the white color for 5 seconds, and then fade uniformly to nothing:

LED strip should now ramp

Check your wiring and coding again if you are having any difficulties.

This project is a simple way to get started, but the ideas covered may be developed upon to create lighting that is quite effective. You might create your own sunrise alarm with only a few additional components. If your Arduino came with a starter kit, you could use any button or sensor to trigger your lights as you walk into the room, for example:

relau snip

Let's move on to the WS2812B strips now that we've covered the SMD5050s.

Bright Ideas

There is some flexibility in the values of the components you may use with these strips, which need fewer components to get going. The capacitor in this circuit makes sure that the 5-volt LEDs get a steady power supply. The resistor makes sure that there is no interference with the data signal that is received from the Arduino.

You will need:

  • LED strip WS2811/12/12B 5V.
  • 1 x Arduino Uno.
  • 1 x 220-440 ohm resistor
  • 1 x 100-1000 microfarad capacitor
  • 5V power supply.
  • Breadboard and hook up wires.

As shown in the diagram, set up your circuit.

circuit diagram

Keep in mind that the capacitor must be positioned correctly. Look for the negative (-) symbol on the capacitor's body to determine which side is connected to the ground rail.

This time, we are supplying the Arduino with a 5 volt power supply. While there are a few things to keep in mind, this enables the project to stand on its own after we're done.

Before connecting your board to the power source, make sure it can take 5 volts. The majority of development boards operate at 5 volts through the USB port, but the power input pins on some of them sometimes bypass the voltage regulators and render them useless.

Likewise, it is best practice to make sure that two separate power sources are not connected to the Arduino; anytime you are using an external power supply, unplug the USB cord.

It should look like this after you're plugged in:

setup and Connect  LED Light Strips to Arduino

Now that our LED strip is wired in, let's move on to the code.

Dancing Lights

Disconnect the VIN line from the power line to securely program our board. Afterward, you'll reconnect it.

Open the Arduino IDE after connecting your Arduino to your computer. Verify that the Tools > Board and Tools > Port options have the proper board and selected port number.

To test out our setup, we will use the FastLED library. By selecting Sketch > Include Library > Manage Libraries and typing in FastLED, you may add the library. The library will be added to the IDE once you click “install“.

Choose the DemoReel100 sketch from File > Examples > FastLED. This sketch is really easy to set up and cycles through numerous things that can be done with WS2812 LED strips.

The only variables you need to modify are the DATA_PIN variable to match pin 13, and the NUM LEDS variable to specify the number of LEDs in the strip you are using. In this instance, I'm merely using a small line of 10 LEDs that was chopped from a larger strip. For a brighter light display, use more!

LED SKETCH

That's all! Turn on your 5-volt power supply, then upload the sketch to your board and unplug the USB wire. Reconnect the Arduino's VIN to the power line and watch the show!

working Connect LED Light Strips to Arduino

If nothing happens, check your wiring and make sure you specified the correct Arduino pin in the demo sketch.

Endless Possibilities

The demo sketch shows a few of the many possible effect combinations that may be created with the WS2812 strips. These may be put to practical use in addition to being a step above regular LED strips. Building your own Ambilight for your media center might be a nice next project.

Don't write off the standard 12v LED strips just yet, even if these strips are more functional than SMD5050s. There are a huge number of uses for LED light strips, and they are unbeatable in terms of price.

Learning to work with LED strips is a fantastic way to get comfortable with Arduino's fundamental programming, but experimenting is the best way to learn. See what you can achieve by changing the code above! Consider starting with these Arduino projects for beginners if all of this seems a little overwhelming to you.

Oh hi there It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Read our privacy policy for more info.

Leave a Reply

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