Arduino Uno Tutorial: NeoPixel Ring Setup

Elon
4 min readNov 16, 2022

Hey again! So last weekend I took a trip to MicroCenter and got a couple fancy new shindigs to upgrade my Arduino starter kit. Specifically, I got this NeoPixel 16 RGBW Ring, which is a powerful plug-in ring with 16 seperately controllable LEDs in it. I also got this microphone breakout but we’ll dive into that at a later date.

Let’s start by setting up the ring!

Simple NeoPixel circuit

Turns out the circuit itself is extraordinarily similar — the magic will come later through the code. We have 5V power and ground running into the positive and negative rows of the breadboard. From there, run a jumper cable from the positive row into the port on the back of the NeoPixel that says “Power 5V”. Run another from the negative row of the breadboard into the port “Power Ground”. Finally, run one more wire from digital pin 6 of the Arduino to the breadboard, through a 470 ohm resistor, and into the port on the NeoPixel that reads “Data Input”. That’s it.

We need to run through the resistor just to protect against data spikes coming from the data port of the Arduino. Also, the NeoPixel documentation warns against connecting your ring to a live circuit at all costs, so be careful with that. Finally, you may have some trouble getting your jumper wires to stay in the NeoPixel ports. I had luck by bending the wires over the inside of each port.

Okay great! Now that we have our circuit set up we can start writing some code! Here’s the objective for our first test with the NeoPixel:

Circulating LEDs in ring

Before we start writing any actual code, we’re gonna have to be sure to import the NeoPixel library so we can access the functions we need. In your Arduino IDE, click Sketch -> Include Library -> Manage Libraries. Type “neopixel” into the search bar and select and install the library called Adafruit NeoPixel by Adafruit.

Great! Now we can start by initializing and setting up the NeoPixel:

#include <Adafruit_NeoPixel.h>

#define LED_PIN 6
#define LED_COUNT 16

Adafruit_NeoPixel ring(LED_COUNT, LED_PIN, NEO_RGBW + NEO_KHZ800);

void setup() {
ring.begin();
ring.show();
ring.setBrightness(50);
}

At the top, we’ll include in that library we just loaded. Next, we define the pin that the NeoPixel data output is connected to, and how many LEDs there are in our ring. The next step is to actually declare our NeoPixel object, which we’ll call ring. Next, in our setup function, we call the function begin() on that ring. This is a necessary step to let our board know to read commands. Then, we call show() to clear all the LEDs, and finally setBrightness(), which we call once at the beginning to tell our NeoPixel what the maximum brightness will be. This function can take a value up to 255 so 50 is about 1/5 of the maximum brightness.

Now we get to the fun part, in our loop() function:

void loop() {
for(int i = 0; i < ring.numPixels(); i++){
ring.setPixelColor(i, random(255), random(255), random(255), 0);
ring.show();
delay(50);
}
for(int i = ring.numPixels()-1; i >= 0; i--){
ring.setPixelColor(i, 0, 0, 0, 0);
ring.show();
delay(50);
}
}

This is the part when you can get real creative, but I’ll walk you through what I did as I jumping off point.

I start with a for loop, which runs from 0 to the number of lights in our ring. Then, we set the pixel color. By pixel we are referring to an individual LED in our ring. The function setPixelColor() takes the arguments, in order: numLED, red, green, blue, white. We’ll enter i as the numLED so that the for loop will run through each one. For the color, I’ve decided to choose a random red, green and blue value just to add some variety. Calling setPixelColor() only, as it says, sets the color, so we have to call ring.show() afterwards to actually update that color into the ring. Finally, we add a delay of 50 milliseconds after applying each color so that we get a sort of loading animation effect.

For extra fun, I take that same loop and reverse it so that the ring lights up and then blinks out. To do this, we start from the LED and count backwards to 0. Then, we set the pixel color to be 0, 0, 0, 0, which means no color, and then add those same two lines. Voila! Put it all together, and hopefully you’ll get the same effect as the GIF I posted above.

Stay tuned for the next post where I’ll add some more interaction and maybe bring the microphone into play!

--

--