Arduino With Neopixel

Light up your world with these programmable fountains of




Media-center lighting, high-viz vehicles, text and image displays – NeoPixels are a beautiful and versatile way to add programmable RGB LEDs to your project. They come in rings, sticks, strips, matrices, and more.

Each pixel is made up of several separate colored diodes: RGB, or RGBW if there's a pure-white channel. And each RGB "pixel" has its own little controller chip. If you just hook up the power, nothing will happen – you have to send data over a PWM pin to make



the Circuit

THE CODE

Go download Adafruit's NeoPixel library to get started. You can just download the .zip file with the library, unzip it on your computer, and drag the contents into your Arduino libraries folder. (The "libraries" folder is usually created in the same "Arduino" folder where you save your sketches. If you don't have one yet, go ahead and create it.) Also, restart the Arduino IDE if you already had it open.

Once it's up again, you'll have some new example sketches. Let's take a look!

File > Examples > Adafruit NeoPixel > simple

  • This guy will light up your LEDs green, one at a time. How does it work? We're gonna use another for loop! (Here's our So, first, we tell the sketch to include Adafruit's library.
  • Then, we define two variables: the data pin we're using (any PWM pin), and the number of pixels in the strip.
  • In the next bit, we initialize the strip as a new object, pixels . (You can call it whatever you want, of course.)
  • Then, we set a delay value, which will be used later to pause after lighting up each LED.

There's a little bit of board-specific code in the setup code, and then we tell the NeoPixel library to start communicating with this strip.

Adapt this

You can transfer this to a smaller circuit (I recommend the ATtiny) to easily hide the controls.

Build an infinity mirror with some half-silvered acrylic or glass!


the Code

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      16

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; // delay for half a second

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

  for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }
}


Apply for sponsorship >>
13800+ Projects Sponsored
Dec 18,2019
1,314 viewsReport item
  • Comments(0)
  • Likes(1)
Upload photo
You can only upload 5 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000