Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled WS2812 RGB LED Strip with Pushbutton Interaction

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled WS2812 RGB LED Strip with Pushbutton Interaction

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller, a WS2812 RGB LED strip, a 12V battery, and a red pushbutton. The Arduino UNO controls the LED strip, which displays various lighting effects. The pushbutton is used as an input to the Arduino. The 12V battery powers the LED strip.

Component List

WS2812 RGB LED Strip

Arduino UNO

12V Battery

Red Pushbutton

Wiring Details

WS2812 RGB LED Strip

Arduino UNO

12V Battery

Red Pushbutton

Code

Arduino UNO Code

/*
 * This Arduino sketch controls a WS2812 RGB LED strip connected to pin D3 of an
 * Arduino UNO. The LEDs 68, 69, and 70 blink red with 500ms on and 3000ms off.
 * LEDs 0 to 67 perform a rainbow color dimming up and down while LEDs 68, 69,
 * and 70 are off.
 */

#include <Adafruit_NeoPixel.h>

#define PIN 3
#define NUM_LEDS 70

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

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

void loop() {
  blinkRed(68, 70, 500, 3000);
  rainbowDimming(0, 66, 2000, 2000);
  blinkRed(68, 70, 500, 3000);
}

void blinkRed(int start, int end, int onTime, int offTime) {
  for (int i = start; i <= end; i++) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
  }
  strip.show();
  delay(onTime);
  for (int i = start; i <= end; i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
  strip.show();
  delay(offTime);
}

void rainbowDimming(int start, int end, int upTime, int downTime) {
  for (int j = 0; j < 256; j++) { // Dimming up
    for (int i = start; i <= end; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (end - start + 1) + j) & 255));
    }
    strip.setBrightness(j);
    strip.show();
    delay(upTime / 256);
  }
  for (int j = 255; j >= 0; j--) { // Dimming down
    for (int i = start; i <= end; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (end - start + 1) + j) & 255));
    }
    strip.setBrightness(j);
    strip.show();
    delay(downTime / 256);
  }
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

WS2812 RGB LED Strip Code

/*
 * This Arduino sketch controls a WS2812 RGB LED strip connected to pin D6 of an
 * Arduino Mega 2560. The LEDs 68, 69, and 70 blink red with 500ms on and 500ms
 * off. LEDs 0 to 68 perform a rainbow color dimming up over 2000ms and dimming
 * down over 500ms, then stop for 2 seconds before repeating.
 */

#include <Adafruit_NeoPixel.h>

#define PIN 3
#define NUM_LEDS 70

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

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

void loop() {
  blinkRed(68, 70, 500);
  rainbowDimming(0, 68, 2000, 500);
  delay(2000); // Stop for 2 seconds
}

void blinkRed(int start, int end, int delayTime) {
  for (int i = start; i <= end; i++) {
    strip.setPixelColor(i, strip.Color(255, 0, 0));
  }
  strip.show();
  delay(delayTime);
  for (int i = start; i <= end; i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
  strip.show();
  delay(delayTime);
}

void rainbowDimming(int start, int end, int upTime, int downTime) {
  for (int j = 0; j < 256; j++) { // Dimming up
    for (int i = start; i <= end; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (end - start + 1) + j) & 255));
    }
    strip.setBrightness(j);
    strip.show();
    delay(upTime / 256);
  }
  for (int j = 255; j >= 0; j--) { // Dimming down
    for (int i = start; i <= end; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (end - start + 1) + j) & 255));
    }
    strip.setBrightness(j);
    strip.show();
    delay(downTime / 256);
  }
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}