LED RGB and Neopixel with Arduino

45-60 min

Ages 14+

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:

LED RGB

Arduino 

Second smallest pin

D9

Larger pin

GND

Second long pin

D10

Smaller pin

D11

Neopixel

Arduino 

V

3.3V

R

D2

B

D5

G

D3

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);

   delay(500);

   digitalWrite(blueLed, HIGH);

   delay(500);

   digitalWrite(greenLed, HIGH);

   delay(500);

  “

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);

   delay(500);

   digitalWrite(blueLed, HIGH);

   digitalWrite(redLed, LOW);

   digitalWrite(greenLed, LOW);

   delay(500);

   digitalWrite(greenLed, HIGH);

   digitalWrite(redLed, LOW);

   digitalWrite(blueLed, LOW);

   delay(500);

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);

  delay(500);

  digitalWrite(blueNeopixel, HIGH);

  digitalWrite(redNeopixel, LOW);

  digitalWrite(greenNeopixel, LOW);

  delay(500);

  digitalWrite(greenNeopixel, HIGH);

  digitalWrite(redNeopixel, LOW);

  digitalWrite(blueNeopixel, LOW);

  delay(500);

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

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

About MoonMakers

MoonMakers — led by Camila and Diego Luna — are a community of creators passionate about knowledge. A Makerspace, an open space with different digital manufacturing machines. And a YouTube channel where we promote science, technology and the maker movement.

MoonMakers have collaborated with companies such as: Sesame Street, Make Community and in Mexico with Educational Television and Fundación Televisa, creating educational content.

We have given workshops throughout the Mexican Republic with: Talent Land, Secretary of Education in Jalisco, Conacyt, Centro Cultural España.

MoonMakers

Materials:

  • Arduino microcontroller (We will use the Arduino nano 33 loT, but you can use the Arduino microcontroller of your choice)
  • 1 RGB LED
  • 1 Neopixel
  • 2 resistors of 100 ohms
  • 1 220 ohm resistors
  • 8 cables
  • Breadboard
  • A micro usb cable
  • A computer, with the Arduino IDE

Vocabulary:

  • 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.)

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK