How to Program Solid Colors with an LED Strip

LED strips are very cool for many aesthetic situations but programming them is way cooler. In this tutorial, we’re going to learn how to light them up.

Requirements

  • LED strip
  • Arduino
  • Adafruit Neopixel Library (You can find this in the library manager of the Arduino IDE)
  • 3 wires

Schematic

Blue – Digital Pin
Red – 5 volts
Black – Ground

Code Walkthrough Example #1

Red Solid Color LED Strip

#include <Adafruit_NeoPixel.h>
#define total 10
Adafruit_NeoPixel ledstrip(total, 2,NEO_GRB + NEO_KHZ800); //Example
//keep in mind, NEO_GRB and NEOKHZ800 are usually the default values in an led strip.
  1. First, add the Adafruit library to your code, create a variable for the total number of LEDs, and instantiate the object name “ledstrip” or any name you prefer. Within the parenthesis are the values in this order: (the number of pixels in your led strip, the digital pin, the LED type and the bitrate of the LEDs).
void setup() {
    
  ledstrip.begin();

}

Next, to begin LED processing, you have to put the line “ledstrip.begin()”, otherwise, nothing will appear.

void loop() {

for(int x = 0;x <= 9;x++)
    {
      ledstrip.setPixelColor(x,255,0,0);//pixelnumber-1,,r,g,b)
    }
}

This loop will go through all the individual LEDs and change the color of each. The x in “setPixelColor” means the pixel position. So if I wanted to change the 5th pixel on an LED strip, I would say ledstrip.setPixelColor(4,r,g,b) (The position starts at 0).

Final

#include <Adafruit_NeoPixel.h>
#define total 10
Adafruit_NeoPixel ledstrip(10, 2, NEO_GRB + NEO_KHZ800); 
//(numoftotalpixels,pinnumber(digital),ledtype,ledbitrate)
void setup() {
    
  ledstrip.begin();

}

void loop() {

for(int x = 0;x < total;x++)
    {
      ledstrip.setPixelColor(x,255,0,0);//pixelnumber-1,,r,g,b)
      ledstrip.show();
    }
}

Leave a comment

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