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

Arduino-Controlled WS2812 RGB LED Strip with Red Pushbutton and Battery Power

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled WS2812 RGB LED Strip with Red Pushbutton and Battery Power

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a red pushbutton, a WS2812 RGB LED strip, and a 12V battery. The Arduino UNO controls the LED strip and reads the state of the pushbutton. The LED strip displays a sequence of colors, and specific LEDs blink red. The pushbutton can be used to interact with the circuit.

Component List

Red Pushbutton

Arduino UNO

WS2812 RGB LED strip

Battery 12V

Wiring Details

Red Pushbutton

Arduino UNO

WS2812 RGB LED strip

Battery 12V

Code Documentation

Arduino Sketch

/*
 * This Arduino sketch controls a WS2812 RGB LED strip and a red pushbutton.
 * LEDs 67, 68, and 69 blink red with 500ms on and 100ms off.
 * LEDs 0 to 66 dim up and down in rainbow colors with 2000ms up and 1000ms down.
 * The sequence stops for 300ms before repeating.
 */

#include <Adafruit_NeoPixel.h>

#define LED_PIN 3
#define BUTTON_PIN A0
#define NUM_LEDS 70

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

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

void loop() {
  blinkRedLeds();
  rainbowCycle(2000, 1000);
  delay(300);
}

void blinkRedLeds() {
  for (int i = 0; i < 3; i++) {
    strip.setPixelColor(67 + i, strip.Color(255, 0, 0));
  }
  strip.show();
  delay(500);
  for (int i = 0; i < 3; i++) {
    strip.setPixelColor(67 + i, strip.Color(0, 0, 0));
  }
  strip.show();
  delay(100);
}

void rainbowCycle(uint16_t upTime, uint16_t downTime) {
  for (uint16_t j = 0; j < 256; j++) { // 1 cycle of all colors on wheel
    for (uint16_t i = 0; i < strip.numPixels() - 3; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (strip.numPixels() - 3) + j) & 255));
    }
    strip.show();
    delay(upTime / 256);
  }
  for (uint16_t j = 256; j > 0; j--) { // 1 cycle of all colors on wheel
    for (uint16_t i = 0; i < strip.numPixels() - 3; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / (strip.numPixels() - 3) + j) & 255));
    }
    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);
}

This code initializes the WS2812 RGB LED strip and the pushbutton. The loop function continuously runs two functions: blinkRedLeds and rainbowCycle. The blinkRedLeds function makes LEDs 67, 68, and 69 blink red, while the rainbowCycle function creates a rainbow effect on the other LEDs. The Wheel function is a helper function to generate color values.