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 $19.95 Add to Cart
  • 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

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 LED Neon Selfie Spot By Erin St Blaine beginner Your browser does not support the video tag. This links to the guide Neon LED Signs. Neon LED Signs By John Park intermediate The PICsellator By David Littell intermediate Your browser does not support the video tag. This links to the guide FunHouse Parking Assistant. FunHouse Parking Assistant By John Park beginner Shadow Box Internet Clock with NeoPixel Visualization By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Make it Glow: NeoPixel and LED Diffusion Tips & Tricks. Make it Glow: NeoPixel and LED Diffusion Tips & Tricks By Erin St Blaine beginner TRON DISC By Ruiz Brothers beginner DotStar Pi Painter By Phillip Burgess intermediate HL1606 LED Strip By Phillip Burgess beginner Your browser does not support the video tag. This links to the guide WiFi Jellyfish Lantern with WLED. WiFi Jellyfish Lantern with WLED By Erin St Blaine beginner Motorized POV LED Display By Ruiz Brothers advanced Your browser does not support the video tag. This links to the guide Holiday Icicle Lights with Flair. Holiday Icicle Lights with Flair By Phillip Burgess beginner CLUE Vertical Garden Weather Visualizer By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Infinity Mirror Collar. Infinity Mirror Collar By Debra Ansell intermediate Your browser does not support the video tag. This links to the guide Color Mixing QT Py Cuff Bracelet. Color Mixing QT Py Cuff Bracelet By Debra Ansell beginner
Create Wishlist
× Title Description Close Search Search
Categories

Tag » Arduino Rgb Led Strip Code