Program RGB LEDs with Arduino

Wondering how to wire up and program an RGB LED?

We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.

Important Note: Make sure to add a current-limiting resistors for each LED color (~220 ohm) when you hooking up your RGB LED.

installing Arduino libraries

Installing Arduino Libraries | Beginners Guide

IoT sewage project

Pumping poo! An IoT sewage project

ESP32 webOTA updates

How to update ESP32 firmware using web OTA [Guide + Code]

error message Brackets Thumbnail V1

expected declaration before ‘}’ token [SOLVED]

Compilation SOLVED | 1

Compilation error: expected ‘;’ before [SOLVED]

Learn how to structure your code

5 Comments

  1. patrickd314 on November 24, 2016 at 6:15 pm

    Careful, viewers: The schematic omits the series resistors (which were included on the breadboard.)

  2. Sravan Mutharasu on March 14, 2017 at 9:11 am

    Weird! I followed everything to the dot. However, connecting the ground pin to the ground lead of the RGB LED doesnt turn on the LED, but not connecting the ground pin to one of the leads of R,G turns the LED On.. I suppose the RGB LED is broken?

  3. Andi1356 on July 20, 2019 at 9:04 pm

    why did’t you declared the variable in the setup and initialized it with 0. This way the program won’t declare a variable every time in the loop.

    • Michael James on July 21, 2019 at 8:23 am

      The reason I chose to do that is for variable scope. If a variable is declared in the setup(), it can only be used within setup().

      If a variable is declared outside of setup() and loop(), it can be used (changed and referred to) anywhere in the program, this property is called global scope. In most small Arduino programs, using variables with global scope is not that big of an issue, however, as program size and complexity grows, using variables of global scope can increasingly become hard to debug. By declaring the variable inside loop(), I am limiting its scope to loop(). It is pretty trivial in this example, because the program is so small, but that is how I chose to do it. I hope this helps answer your question.

  4. Kvon on April 7, 2020 at 8:45 am

    Interesting to know analogWrite can be applied to digital pins 3 , 5 and 6

Leave a Comment