Menu
CoddyTech

Your First NeoPixel

Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 12 of 24.

A NeoPixel is an RGB LED with a tiny chip inside. It has one data wire instead of three colour pins: the board sends the colour as a burst of pulses, and the pixel keeps it until it gets a new one.

The Adafruit_NeoPixel library sends those pulses. Make an object with how many pixels there are, the data pin, and the pixel type (NEO_GRB + NEO_KHZ800 is the colour order and speed of these pixels):

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel pixel(1, 6, NEO_GRB + NEO_KHZ800);

In setup(), pixel.begin() gets the data pin ready. Then give a pixel a colour with its number (they count from 0) and its red, green and blue, each from 0 to 255:

pixel.setPixelColor(0, 255, 0, 0);   // pixel 0: full red
pixel.show();                        // send it

setPixelColor() only stores the colour in the board's memory. Nothing changes on the pixel until show() sends it.

challenge icon

Challenge

Easy

A single NeoPixel is on pin 6. In setup():

  • start it with pixel.begin()
  • make pixel 0 green
  • send the colour with pixel.show()

Press Run, then Check.

Try it yourself

#include <Adafruit_NeoPixel.h>

// 1 pixel, data on pin 6
Adafruit_NeoPixel pixel(1, 6, NEO_GRB + NEO_KHZ800);

void setup() {
  // start the pixel, then make it green
}

void loop() {
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Displays and Sensors

Practice on your own: Arduino playground