WS2812 / NeoPixel Addressable LEDs: Particle Quickstart Guide

Updated 08 February 2019

This tutorial is aimed at getting some instant gratification from your WS2812 LEDs (trade name: NeoPixels). I'll briefly cover a bare-bones setup for the Particle Photon.

If you've never used any Particle hardware before, learn how to get one set up with our Particle Tutorials! We even have an in-depth Particle NeoPixel tutorial if you want to learn more.

Parts Required for this Project

Connecting the LEDs

The Particle Photon uses 3.3V Logic, So we will need to use a Logic Level Converter to convert it to the 5V logic that WS2812/Neopixels require. 

You will need to use an external 5V Power Supply, as WS2812/NeoPixels take a LOT of power. Each pixel will draw about 20mA on average, and 60mA at white - max brightness. 30 Pixels will draw 600mA on average, and up to 1.8A. Ensure your power supply is large enough to drive your strip!

Here's the wiring used in the video (click for hi-res):

WS2812B-neopixel-particle-photon-schematic

The Code

You could just copy+paste the following code into a new build.particle.io project, but be sure to check the video to see how this example is accessed from the built-in NeoPixels library.

/*
 * This is a minimal example, see extra-examples.cpp for a version
 * with more explantory documentation, example routines, how to
 * hook up your pixels and all of the pixel types that are supported.
 *
 */

#include "Particle.h"
#include "neopixel.h"

SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 5
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop()
{
  rainbow(20);
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

That's all there is to it! Once uploaded, this code should have your LED strip showing some vibrant colours.

If you run into any trouble, be sure to reach out to us in the comments section below. We're full-time makers and we're here to help!

Going Further

Are you looking to add WS2812/NeoPixel LEDs to your other project but you aren't using a Particle Photon? Check out our other guides to get you started on other hardware types:

Need to take one step back and figure out what these fandangled NeoPixels even are? Check out our What Are NeoPixel LEDs Guide!

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.