Arduino Code | RGB LED Strips - Adafruit Learning System

Skip to main content RGB LED Strips Arduino Code
  • Overview
  • Schematic
  • Current Draw
  • Wiring
  • Usage
  • Arduino Code
  • CircuitPython Code
  • Single page
  • Feedback? Corrections?
  • Text View
Featured Products view all
  • Your browser does not support the video tag. Two hands repeatedly bending and manipulating lit-up flexible silicone tubing. Flexible RGB Neon-like LED Strip 120 LEDs - 1 meter long Out of Stock
  • Angled Shot of the RGB LED weatherproof flexi-strip - 30 LED/m - 5m on the reel. RGB LED weatherproof flexi-strip - 30 LED/m - 5m $80.00 Add to Cart
  • Spool of flexible LED strip lit up purple RGB LED Weatherproof flexi-strip 60 LED/m- 5m $125.00 Add to Cart
  • Your browser does not support the video tag. Coiled cool white LED strip with LEDs changing color throughout rainbow and also white Analog RGBW LED Strip - RGB plus Cool White - 60 LED/m $79.80 Add to Cart
  • Your browser does not support the video tag. Coiled warm white LED strip with LEDs changing color throughout rainbow and also white Analog RGBW LED Strip - RGB plus Warm White - 60 LED/m $79.80 Add to Cart
  • two cables and a connector Solderless DotStar and Analog RGB LED Strip Clip Sampler $2.95 Add to Cart
  • 3 pack TIP120 Power Darlington Transistors TIP120 Power Darlington Transistors - 3 pack $2.50 Add to Cart
  • Bundle of multi-colored multi-length wire jumpers Breadboarding wire bundle $4.95 Add to Cart
180 Beginner Project guide 😍 1 🔥 1

Arduino Code

Once you have the strip wired up, it is easy to control the color of the strip by using PWM output, for Arduino you can use analogWrite() on pins 3, 5, 6, 9, 10 or 11 (for classic Arduinos using the Atmega328 or 168). An analogWrite(pin, 0) will turn that LED off, analogWrite(pin, 127) will turn it on half-way and analogWrite(pin, 255) will turn it on full blast. Here is some example code that performs a simple color-swirl.If you want to use other pins, check out this page on analogWrite() to know which models support analogWrite() on which pins Download File Copy Code // color swirl! connect an RGB LED to the PWM pins as indicated // in the #defines // public domain, enjoy! #define REDPIN 5 #define GREENPIN 6 #define BLUEPIN 3 #define FADESPEED 5 // make this higher to slow down void setup() { pinMode(REDPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BLUEPIN, OUTPUT); } void loop() { int r, g, b; // fade from blue to violet for (r = 0; r < 256; r++) { analogWrite(REDPIN, r); delay(FADESPEED); } // fade from violet to red for (b = 255; b > 0; b--) { analogWrite(BLUEPIN, b); delay(FADESPEED); } // fade from red to yellow for (g = 0; g < 256; g++) { analogWrite(GREENPIN, g); delay(FADESPEED); } // fade from yellow to green for (r = 255; r > 0; r--) { analogWrite(REDPIN, r); delay(FADESPEED); } // fade from green to teal for (b = 0; b < 256; b++) { analogWrite(BLUEPIN, b); delay(FADESPEED); } // fade from teal to blue for (g = 255; g > 0; g--) { analogWrite(GREENPIN, g); delay(FADESPEED); } } // color swirl! connect an RGB LED to the PWM pins as indicated // in the #defines // public domain, enjoy! #define REDPIN 5 #define GREENPIN 6 #define BLUEPIN 3 #define FADESPEED 5 // make this higher to slow down void setup() { pinMode(REDPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BLUEPIN, OUTPUT); } void loop() { int r, g, b; // fade from blue to violet for (r = 0; r < 256; r++) { analogWrite(REDPIN, r); delay(FADESPEED); } // fade from violet to red for (b = 255; b > 0; b--) { analogWrite(BLUEPIN, b); delay(FADESPEED); } // fade from red to yellow for (g = 0; g < 256; g++) { analogWrite(GREENPIN, g); delay(FADESPEED); } // fade from yellow to green for (r = 255; r > 0; r--) { analogWrite(REDPIN, r); delay(FADESPEED); } // fade from green to teal for (b = 0; b < 256; b++) { analogWrite(BLUEPIN, b); delay(FADESPEED); } // fade from teal to blue for (g = 255; g > 0; g--) { analogWrite(GREENPIN, g); delay(FADESPEED); } }

Page last edited November 26, 2012

Text editor powered by tinymce.

Usage CircuitPython Code Related Guides Your browser does not support the video tag. This links to the guide NeoPixel Infinity Mirror Coaster. NeoPixel Infinity Mirror Coaster By Ruiz Brothers beginner Sparkle Motion Dance Shoes By John Park intermediate Make a Zelda Master Sword with the RP2040 Prop-Maker... By Ruiz Brothers beginner Your browser does not support the video tag. This links to the guide Holiday Tree with Feather RP2040 Scorpio. Holiday Tree with Feather RP2040 Scorpio By Ruiz Brothers intermediate Techno-Tiki RGB LED Torch By Tony DiCola intermediate Your browser does not support the video tag. This links to the guide Sound Reactive LED Top Hat. Sound Reactive LED Top Hat By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide USB Rotary Media Dial. USB Rotary Media Dial By Ruiz Brothers beginner Your browser does not support the video tag. This links to the guide Glowing Viking Rune wayFinder. Glowing Viking Rune wayFinder By Erin St Blaine beginner No-Code Rain Sensing Smart Desktop Umbrella Stand By Tyler Cooper beginner Your browser does not support the video tag. This links to the guide Glowing Interactive Crystal Staff . Glowing Interactive Crystal Staff By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Holiday Lights: Easy DIY Christmas Wreath & Garland with WLED. Holiday Lights: Easy DIY Christmas Wreath & Garland... By Erin St Blaine beginner Your browser does not support the video tag. This links to the guide Edge-Lit Tavern Sign with WLED - Control with WiFi or IR Remote. Edge-Lit Tavern Sign with WLED - Control with WiFi... By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Halloween Skeleton Transformation Illusion Prop. Halloween Skeleton Transformation Illusion Prop By Erin St Blaine beginner The PICsellator By David Littell intermediate Your browser does not support the video tag. This links to the guide 3D Printed Frankenstein Monster with NeoPixel Eyes. 3D Printed Frankenstein Monster with NeoPixel Eyes By Liz Clark beginner
Create Wishlist
× Title Description Close Search Search
Categories

Tag » Arduino Rgb Led Strip Code