Arduino Pixel LED Experiment

Author : Dinesh Kumar Wickramasinghe

Introduction and Images

Hello friends, Here again with an interesting project. Let’s see how to control pixel LED strips using Arduino. After this tutorial, you will be able to control your pixel LED strips via Arduino and build nice custom patterns.

Here is an image of the final project. You can see the video of the finel project at the end of this blog post.

Arduino Pixel LED Completed

Pixel LED Strips

There are different types of neo pixel led strips you can find in the market. With different shapes and sizes.

Most important thing is the chip that controls the individual LEDs. In this tutorial I use the most common RGB pixel led with the chip WS2811. The below image shows the type of RGB string that I am going to use.

Arduino Pixel LED String

The interesting feature of these pixel led strips is you can individually control any of the led in the strips. For example, if you want to turn on the 10th led and assign a custom color to that LED, you can simply do that from your arduino code.

Connect your Pixel LED strip to Arduino

You need an external power supply to power up the pixel string. When all the LEDs light up, your arduino won’t be able to supply enough current. That’s why it is always safe to use an external power source. Mostly the pixel led strips / strings need 5V DC power supply. So, you can use any kind of 5V DC power supply with minimum 1A current. You can also use a power bank with 5V output.

There is only one data pin you have to connect from your pixel LED strip to the Arduino. That’s a great advantage. Make sure to connect your external power supply ground connection to arduino ground. Here is the basic schematic.

Arduino Pixel LED Connectivity

Here is how my setup looks like :

Arduino Pixel LED Project Setup
Arduino Sketch (Code)

In this example, I will use the Arduino library "FastLED”. (Kudos to the developers)

Here is the github link : https://github.com/FastLED/FastLED/

Here is the documentation link : https://github.com/FastLED/FastLED/wiki/Overview

This library supports many types of pixel LED chips. You can find more information from the documentation.

You can also add this library easily from your Arduino IDE, go to Tools > Manage Libraries

Now search for “fastled” and install the library as below screenshot :

Arduino Pixel LED Add Library

Now, if you go to the examples menu of your Arduino IDE, you will see new examples added by the fast LED library.

Arduino Pixel LED Library Samples

In my LED string, there are 50 LEDs. Also in the above schematic, I used the arduino digital pin number 3 as the data pin. Those information we need to set in the sketch.

Now, let's go for a very small example. I want to blink the 10th pixel LED of my string with the blue color. So here is the code (sketch)

#include <FastLED.h>
#define NUM_LEDS 50
#define DATA_PIN 3

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() { 
  // Turn the LED on, then pause
  leds[9] = CRGB::Blue;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[9] = CRGB::Black;
  FastLED.show();
  delay(500);
}
                    

Some explanations about the code

NUM_LEDS : Defines the number of LEDs in your strip / string

DATA_PIN : Defines the data pin

leds[9] = CRGB::Blue; Set the 10th LED to blue color (Index is 9 because the array starts from 0)

leds[9] = CRGB::Black; Turn off the LED

Output looks like below :

(I used a small power bank as the external power source)

Arduino Pixel LED Sketch Output

Here is another example with a loop :

#include  <FastLED.h>

#define NUM_LEDS 50
#define DATA_PIN 3

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds <WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() { 
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(500);

    leds[i] = CRGB::Black;
    FastLED.show();
    delay(100);
  }
}
                    

Hope now you understand the pattern. Please read the documentation to learn more functions provided by this interesting library.

There are several interesting examples provided by the library. You can try them too. Make sure you set the correct chip.

In your library examples, try the example “Color Palette”. It has beautiful patterns. Here is a video of that example.

Extra Notes and Conclusion :

You can connect more than one led strings together. Use the below port to connect them.

Arduino Pixel LED Connect More Strings

Make sure you define the total number of LEDs in the arduino sketch and also connect each and every strip to the external power source separately.

Once you finish setting up your code / patterns, you can use the same external power supply to power up your Arduino as well. Then no need to connect the arduino to your PC / Laptop always.

There are pre-built small controllers that you can use to control pixel led strips. I tried the one like in the below image and it has some interesting patterns. Very small and cheap. You can also try.

Arduino Pixel LED Controller

Hope you enjoyed this tutorial. Add your comments, questions below.

Have a nice day.

Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : Josh
Added Date :2/17/2022 11:11:27 AM
Interesting project. Thank you.

 

Similar Projects

Go Top