Link Search Menu Expand Document

In this guide we walk through how to program your first Neopixel sketch

Create your Circuit

Complete the wiring for your Neopixel outlined in the main Neopixel guide

In Particle Dev, create a new project and add the library for Neopixels.

Setting up the Sketch

Every Neopixel sketch will start with the same boilerplate:

First start by including the Neopixel library at the top of your file

#include "neopixel.h"

Next add the definitions to the top of your code file and adjust as needed if you are using a different type of Neopixel or are using a different pin.

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

In the setup you need to initialize the neopixel with the strip.begin command, like so

void setup() {

  strip.begin();; // Initialize all pixels to 'off'

Then in your main loop you can write code to control the Neopixels:

void loop() {

  uint16_t i;
  uint32_t c = strip.Color(255, 255, 255);

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c );;
		delay( 100 );
	delay( 100 );


Remember that the is really important. It tells your Neopixels to push the updates to each individual pixel

Compiling and sending to the Particle Argon.

Make sure the Status Bar has a Particle Argon connected and the Particle Argon’s indicator is breathing blue. If not make sure your Argon is connected by USB and is getting a WiFi signal.

Press the Lightning bolt on the top left of the window.

You’ll see a message ‘Compiling in the Cloud’ and a few sections later your Argon should start flashing magenta.

Wait a few moments, and your Neopixel should begin to light up!

Build your skills - Independent Exercises

Exercise 1

Modify the code to light up pixel by pixel then reverse the sequence turning each pixel off one by one

Exercise 2

Modify the code to light up blue, then red, then green then white in sequence

Exercise 3

Change the code to only light up only one pixel at a time. With each loop move that pixel one position higher. When it reaches the final pixel, restart the sequence at zero i.e. build a single pixel that will continually cycle

Exercise 4

Add three Particle.function to set the Red, Green and Blue components. Allow these values to be set from 0-255 and as they are set to change all of the pixels on the LED strip to that color.

Table of contents