Neopixel with Arduino UNO

Updated on 23 September 2022
dev board Arduino UNO
chip WS2812
features neopixel
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Code

Download code neopixel-ws2812.ino
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 60
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(
    NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// 10 pixels * 200 ms = 2 seconds to display 10 pixels
#define DELAYVAL 200

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  Serial.println("Start Neopixel!");

  pixels.begin();
  pixels.show();
  pixels.setBrightness(50);
}

void loop() {
  pixels.clear();

  Serial.print("Pixel #1 at ");
  Serial.print(String(millis()/1000));
  Serial.println("s");

  for (int i = 0; i < 10; i++) {
    pixels.setPixelColor(i, pixels.Color(0, 150, 0));
    // TODO show all pixels at one go after the for loop without a delay
    pixels.show();
    delay(DELAYVAL);
  }

  Serial.print("Pixel #10 at ");
  Serial.print(String(millis()/1000));
  Serial.println("s");

  delay(2000);
}

Makefile

BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

Prototype

A photo of the actual setup.

Neopixel with Arduino UNO prototype

Schematic

Wire up the hardware accordingly

Neopixel with Arduino UNO schematic

Serial console

Serial output from the firmware.

Neopixel with Arduino UNO serial console

Description

Install Neopixel library:

arduino-cli lib install "Adafruit NeoPixel"

The signals were captured with the Saleae Logic Analyser.

Download Saleae Analyser File

Zoomed out signals:

Magnified signal at a closer look:

References