Lisleapex Blog
Published © Apache-2.0

How to Drive WS2812 LED Strip With Arduino

In the following experiment, I will introduce how to drive WS2812 LED strip with Arduino.

BeginnerWork in progress2 hours36
How to Drive WS2812 LED Strip With Arduino

Things used in this project

Hardware components

Ws2812
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Dupont cable

Story

Read more

Schematics

2_mOeW7ax7Hi.jpg

Code

Untitled file

Arduino
#include <Adafruit_NeoPixel.h>

#ifdef __AVR__

#include <avr/power.h> // Required for 16 MHz Adafruit Trinket

#endif



// Pin number to control WS2812 light strip

#define PIN 6



// Define the number of LEDs to control

#define NUMPIXELS 8



Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);



// Delay between adjacent LEDs in milliseconds

#define DELAYVAL 500



void setup() {

// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.

// Any other board, you can remove this part (but no harm leaving it):

#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)

clock_prescale_set(clock_div_1);

#endif

// END of Trinket-specific code.



pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)

}

//Write your code here to control the brightness and color of the LED light strip

void loop() {

pixels.clear(); // Set all pixel colors to 'off'



// The first NeoPixel in a strand is #0, second is 1, all the way up

// to the count of pixels minus one.

for(int i=0; i<NUMPIXELS; i++) { // For each pixel...



// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255

// Here we're using a moderately bright green color:



pixels.setPixelColor(i, pixels.Color(150, 150, 20));



pixels.show(); // Send the updated pixel colors to the hardware.



delay(DELAYVAL); // Pause before next pass through loop

}

}

Credits

Lisleapex Blog
28 projects • 0 followers
Fast Delivery of High-Quality Electronic Components

Comments