Published © GPL3+

Color Mixing Addressable LEDs

This lesson aims to show how to control an addressable WS2812 LEDs strip in order to obtain various colors using 3 potentiometers.

BeginnerShowcase (no instructions)30 minutes6,670
Color Mixing Addressable LEDs

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
WS2811 Addressable LED strip (1m, 60 LEDs)
10 10K trimmer


Read more


Schematic 1


Code snippet #1

Color addressable LEDs control using Adafruit NeoPixel library

 Parts required:
 1m strip of addressable LEDs
 This example code is part of the public domain

#include <Adafruit_NeoPixel.h>

const int NUMPIXELS = 60; //number of LEDs in 1m
const int LEDsPin = 9;    // LEDs connected to digital pin 9

const int redPotPin = A0;      // pin to control red
const int greenPotPin = A1;   // pin to control green
const int bluePotPin = A2;   // pin to control blue

int redValue = 0; // value to write to the red LED
int greenValue = 0; // value to write to the green LED
int blueValue = 0; // value to write to the blue LED

int redPotValue = 0; // variable to hold the value from the red pot
int greenPotValue = 0; // variable to hold the value from the green pot
int bluePotValue = 0; // variable to hold the value from the blue pot

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // initialize serial communications at 9600 bps:

  // set the digital pin as output
  pinMode(LEDsPin, OUTPUT);

void loop() {
  // Read the pots first:

  // read the value from the red pot control:
  redPotValue = analogRead(redPotPin);
  // give the ADC a moment to settle
  // read the value from the green pot control:
  greenPotValue = analogRead(greenPotPin);
  // give the ADC a moment to settle
  // read the value from the blue pot control:
  bluePotValue = analogRead(bluePotPin);

  // print out the values to the serial monitor
  Serial.print("raw sensor Values \t red: ");
  Serial.print("\t green: ");
  Serial.print("\t Blue: ");

  In order to use the values from the pots for the LEDs,
  you need to do some math. The ADC provides a 10-bit number,
  but analogWrite() uses 8 bits. You'll want to divide your
  sensor readings by 4 to keep them in range of the output.
  redValue = map(redPotValue, 0, 1023, 0, 255);
  greenValue = map(greenPotValue, 0, 1023, 0, 255);
  blueValue = map(bluePotValue, 0, 1023, 0, 255);;

  //  print out the mapped values
  Serial.print("Mapped sensor Values \t red: ");
  Serial.print("\t green: ");
  Serial.print("\t Blue: ");

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  for (int i = 0; i < NUMPIXELS; i++) {
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(redValue, greenValue, blueValue));; // This sends the updated pixel color to the hardware.
    delay(50); // Delay for a period of time (in milliseconds).

Github file




32 projects • 115 followers