45-60 min
Session 1 of 0
In Progress

LED RGB and Neopixel with Arduino

45-60 min



What Will You Learn?

You will learn to program two different types of LEDs, an RGB and a neopixel, learning much more about electronics and programming.

Connect the RGB LED to Arduino

Step 1

Connect the RGB LED to your Arduino microcontroller; It has 4 pins that will go in different lines of our breadboard, connect it as in image 2.

Step 2

Also check the following tables for more details:



Second smallest pin


Larger pin


Second long pin


Smaller pin












Program the RGB LED

Step 3

Start programming the RGB Led, this means a red, green and blue LED, to be able to combine these three colors to produce more tones.

Define the variables at the top:

int redLed = 9;

int blueLed = 11;

int greenLed = 10;

And in the void setup section, write:

   pinMode(redLed, OUTPUT);

   pinMode(blueLed, OUTPUT);

   pinMode(greenLed, OUTPUT);

You just declared the variables: their name, where they are found and also the port type (output).

Step 4

In the void loop section, write:

   digitalWrite(redLed, HIGH);


   digitalWrite(blueLed, HIGH);


   digitalWrite(greenLed, HIGH);



Step 5

You have just programmed each of the LEDs to turn on, with a waiting time of 500 milliseconds. Verify your code, save it (LedRGB-Hello-World) and upload it to your Arduino, you will see how the Led turns color to color, and how the colors are combined.

Different On, Off, and Wait Combinations

Step 6

Play with different combinations, on, off and wait, below is an example, copy and paste it in the void loop section:

   digitalWrite(redLed, HIGH);

   digitalWrite(blueLed, LOW);

   digitalWrite(greenLed, LOW);


   digitalWrite(blueLed, HIGH);

   digitalWrite(redLed, LOW);

   digitalWrite(greenLed, LOW);


   digitalWrite(greenLed, HIGH);

   digitalWrite(redLed, LOW);

   digitalWrite(blueLed, LOW);


Program the Neopixel

Step 7

Now program the Neopixel, they are individually addressable types of RGB LEDs, to program it start by writing variables like the other LEDs:

int redNeopixel = 2;

int greenNeopixel = 3;

int blueNeopixel = 5;

Step 8

Now in the “void setup” section we define our variables as output:

  pinMode(redNeopixel, OUTPUT);

  pinMode(greenNeopixel, OUTPUT);

  pinMode(blueNeopixel, OUTPUT);

Step 9

In the “void loop” section write:

  digitalWrite(redNeopixel, HIGH);

  digitalWrite(blueNeopixel, LOW);

  digitalWrite(greenNeopixel, LOW);


  digitalWrite(blueNeopixel, HIGH);

  digitalWrite(redNeopixel, LOW);

  digitalWrite(greenNeopixel, LOW);


  digitalWrite(greenNeopixel, HIGH);

  digitalWrite(redNeopixel, LOW);

  digitalWrite(blueNeopixel, LOW);


A tip: to turn on your LED you write HIGH but you can also write 1 and to turn off you write LOW just like you can write 0.

Step 10

With your code finished, verify it, save it, and upload it to your Arduino microcontroller with the buttons at the top. Cool! you can see it work.

Further Resources


function: is a section of a program that calculates a value independently from the rest of the program

void setup: The setup () function is called when a sketch begins. Use it to initialize variables, pin modes, start using libraries, etc. The setup () function will only run once, after every power-up or reboot of the Arduino board.

void loop: After creating a setup () function, which initializes and sets initial values, the loop () function does just what its name suggests and repeats consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

int: Integers are your main data type for storing numbers.

pinMode: Sets the specified pin to behave as an input or an output.

digitalWrite: Write a HIGH or LOW value to a digital pin. Its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

delay: Pauses the program for the time (in milliseconds) specified as a parameter. (There are 1000 milliseconds in a second.)

Learn More!

Take it Further?

To learn more about arduino, following the MoonMakers lessons, and learn more about the fascinating world of programming and create your own projects

Diego Francisco June 4, 2021
I am a full-stack developer, I have participated in technology and innovation competitions. I have collaborated with companies such as: Sesame Street, Make Community and in Mexico with Educational Television and Fundación Televisa, as well as with CONACYT creating educational content. We have designed and taught workshops throughout the Mexican Republic with Talent Land, the SEP of Jalisco and the Spain Cultural Center. And all this with the educational brand that I created with my sister. MoonMakers.