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 Your browser does not support the video tag. This links to the guide Light Up Paper Dragon Wall Sconce. Light Up Paper Dragon Wall Sconce By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Using NeoPixels and Servos Together. Using NeoPixels and Servos Together By Phillip Burgess intermediate Wonder Woman Cosplay Bracers By Erin St Blaine intermediate Your browser does not support the video tag. This links to the guide Neon LED Signs. Neon LED Signs By John Park intermediate Your browser does not support the video tag. This links to the guide CircuitPython Animated Holiday Wreath Lights. CircuitPython Animated Holiday Wreath Lights By Kattni Rembor beginner Your browser does not support the video tag. This links to the guide Monster Matrix with WLED. Monster Matrix with WLED By Erin St Blaine 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 LED Sculpture Lamp By Jeff Epler beginner Bluetooth Controlled NeoPixel Lightbox By Dave Astels beginner Your browser does not support the video tag. This links to the guide Gemma-Powered NeoPixel LED Sound Reactive Drums. Gemma-Powered NeoPixel LED Sound Reactive Drums By Ruiz Brothers intermediate Remote Controlled LED Tea Light Sconce By Erin St Blaine beginner Your browser does not support the video tag. This links to the guide Halo Energy Sword RP2040. Halo Energy Sword RP2040 By Ruiz Brothers intermediate WiFi Controlled LED Christmahanukwanzaa Tree By Tony DiCola beginner 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 Your browser does not support the video tag. This links to the guide LED Snowboard with Motion-Reactive Animation. LED Snowboard with Motion-Reactive Animation By Erin St Blaine intermediate
Create Wishlist
× Title Description Close Search Search
Categories

Tag » Arduino Rgb Led Strip Code