What is an LED strip light? How do you choose the right one? How do you control it?

Introduction

LED strips, also known as LED ribbons, are a series of LEDs that can be controlled using an Arduino board.

LED strips, also known as LED ribbons, are a series of LEDs that can be controlled using an Arduino board. This will allow you to control your LED strip using a remote control, a smartphone, or automatically. If your LED strip has fewer than ten LEDs, you can connect it directly to the Arduino board.

However, an LED strip often contains many LEDs, so you will need an external power supply to operate it, as the Arduino board cannot provide the required power.
To control your strip and connect it to the external power supply, you can use one of these two components: a relay or a transistor.

What is the difference between a relay and a transistor?

Both components allow you to connect the Arduino board to your LED strip. However, a relay does not allow you to adjust the brightness of your LEDs, unlike a transistor. Additionally, you won’t be able to change the color of your LEDs with a relay, but this is possible with a transistor.

LED strip pin

The LED strip has three pins:

  • Vcc: to be connected to the 5V pin of the Arduino board or to the transistor/relay.
  • GND: to be connected to the ground of the Arduino board or to the transistor/relay.
  • DIN (Signal): to be connected to the Arduino board or to the transistor/relay.

The different types of LED strips

There are two types of LED strips: addressable, where each LED can display a different color, and non-addressable, where all the LEDs show the same color.

Now, let’s take a look at the different types of LED strips so you can make your choice:

LEDs are most often sold in the form of LED strips. To control them, you will need an external power supply due to the number of LEDs.

This LED ring, offered by Neopixel, consists of 16 addressable LEDs and measures 12 x 8 x 0.3 centimeters. It can be powered by 5V and does not require an external power supply.

This LED circle, also offered by Neopixel, has 7 LEDs. Its dimensions are 12 x 8 x 0.3 centimeters.

Now, let’s see how to control these LEDs using libraries.

Neopixel library

Several libraries can be used to program your LED strip. Notably, Adafruit\_NeoPixel, PololuLedStrip, and FastLED.h.

In our course, we will use the Neopixel library. This one will allow you to program most LED strips.

How to install the library?

To control your LED strip, you will need to install the library in the Arduino IDE.

To do this, go to “Sketch”, then “Include Library”, and “Manage Libraries”, and type Adafruit Neopixel.

If you’re having trouble installing it, we recommend our course on libraries.

How to use the Adafruit Neopixel library?

Let’s look at some functions from the library that might be useful to you.

Here’s how to import the Neopixel library into your program:

#include <Adafruit_NeoPixel.h>

Here’s how to configure the library. You pass the pin where the LED strip is connected and the number of LEDs on your strip as parameters:

int pin = 2; // LED strip pin
int led_count = 4; // Number of LEDs in the strip
// Declare the library with the above data
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(led_count, pin, NEO_GRB + NEO_KHZ800);

Allows you to start using the library:

pixels.begin();

Allows you to turn off the LEDs:

 pixels.clear();

Allows you to assign a color to an LED on the strip. Here, we set the color blue to LED 1:

pixels.setPixelColor(1, pixels.Color(0,0,255)); 

For the color green, you should write: (0, 255, 0)

For the color red, you should write: (255, 0, 0)

Here is the code to turn on your LED:

pixels.show();

LED strip without external power supply

Now, let’s see how to light up LEDs on a small LED strip. This one does not require an external power supply. Here is the circuit:

In our program, we light up the LEDs in blue with a 0.2-second interval:

#include <Adafruit_NeoPixel.h> // Library used
int PIN = 2; // LED strip pin
int numPixel = 4; // Number of LEDs in the strip
// Declare the library with the above data
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numPixel, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin(); // Initialize the library
}

void loop() {
  pixels.clear(); // Turn off all lit LEDs
  for (int i = 0; i < numPixel; i++) { // Loop through all the LEDs
    pixels.setPixelColor(i, pixels.Color(0, 0, 255)); // Assign blue color to the LED
    pixels.show(); // Light the LED with the color
    delay(200); // Pause for 0.2 seconds before lighting the next LED
  }
}

Here is the result once the project is completed:

LED strip with external power supply

If you need to power a strip with many LEDs, you will require an external power supply. For this, we recommend using a transistor to connect the Arduino board to your LED strip.

Here is an example circuit to operate your LED strip:

The program is exactly the same as for controlling an LED strip without an external power supply.

LED ring

Now let’s see how to operate the LED ring. Here, you won’t need an external power supply due to the number of LEDs. Additionally, the LED ring is powered by 5V.

Here is the circuit:

Here, the program creates a random color and gradually lights up the LEDs.

#include <Adafruit_NeoPixel.h> // The Neopixel library

#define PIN 2          // The pin where the LED ring is connected
#define NUMPIXELS 12   // Number of LEDs in the ring

// Initialize the library with the LED ring model
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int red_color = 0;    // Initialize red color
int green_color = 0;  // Initialize green color
int blue_color = 0;   // Initialize blue color
long random_number;   // Initialize random number

void setup() {
  pixels.begin();    // Initialize the LEDs
  pixels.show();     // Turn on the LEDs
  randomSeed(analogRead(0));  // Random seed for color change
  delay(100);        // Pause for one tenth of a second
}

void loop() {
  randomSeed(analogRead(0));  // Change random seed to vary colors
  setColor();                 // Call the function to set color
  
  for(int i = 0; i < NUMPIXELS; i++) {  // Loop through all LEDs
    pixels.setPixelColor(i, pixels.Color(red_color, green_color, blue_color));  // Assign color to pixel
    pixels.show();   // Display the pixel
    
    delay(100);      // Pause for one tenth of a second between lighting LEDs
    
    if (i == 0) {   // At the start of the loop, turn off LEDs and get a new random number
      pixels.clear();  // Turn off LEDs
      random_number = random(256);
      delay(100);
    }
  }
}

void setColor() {  // Color function
  red_color = random(0, 255);    // Random red color value
  green_color = random(0, 255);  // Random green color value
  blue_color = random(0, 255);   // Random blue color value
}

Here is the result when the project is powered on: