#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Define pin connected to NeoPixel data line
#define PIN 6
// Define number of NeoPixels
#define NUMPIXELS 8
// Create NeoPixel object
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Delay between lighting each pixel (in milliseconds)
int delayval = 500;
void setup() {
// Initialize NeoPixel library
pixels.begin();
}
void loop() {
// Loop through each pixel in the strip
for (int i = 0; i < NUMPIXELS; i++) {
// Set pixel color (RGB: 0,150,0 -> moderate green)
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
// Send updated color data to strip
pixels.show();
// Wait before lighting next pixel
delay(delayval);
}
}
Instruction Details
Wiring: Connect NeoPixel strip DIN (data in) to Digital Pin 6. Connect VCC to 5V and GND to GND. Use external 5V for long strips.
Library: Sketch → Include Library → Manage Libraries → search "Adafruit NeoPixel" → Install.
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: LED strip displays colors and patterns. Set correct LED count in code.
How to Use
Connect the required components as per the Pin Configuration above
Open Arduino IDE and create a new sketch
Copy and paste the code above
Select your Arduino board and COM port from Tools menu
Click the Upload button to upload the code to your Arduino
Open Serial Monitor (if applicable) to see the output