RGB LED Module with Arduino

Written By: Cherie Tan

Dash icon
Difficulty
Easy
Steps icon
Steps
6
You might have already tried your hands at making a two colour LED module blink with the Arduino. But what about more colours? How does that work? In this guide, you will learn to make an RGB LED blink with an Arduino, and change it to a variety of colours. Complete this guide to learn the basics of programming an RGB LED with an Arduino.

Step 1 RGB LED Module

Let's take a look a closer look at the RGB LED Module before we begin. There are four pins: RED (R), GREEN (G), BLUE (B), and GND. GND: In electronics, we define a point in a circuit to be a kind of zero volts or 0V reference point, on which to base all other voltage measurements. This point is called ground or GND. Voltage is the difference in electric potential between two points. As it is difficult to talk about voltage without a reference point, we need another point to compare it to. As you might guess, this module is capable of emitting red, green, blue as well as a variety of colours based on how they are combined. This module has on-board resistors, so external resistors are not required here.

Step 2 Connect R to Digital Pin 8

Connect a jumper wire from Pin R to Digital Pin 8.

Step 3 Connect G to Digital Pin 10

Connect a jumper wire from Pin G to Digital Pin 10.

Step 4 Connect B to Digital Pin 12

Connect a jumper wire from Pin B to Digital Pin 12.

Step 5 Connect GND to GND

Connect GND to GND.

Step 6 Random Colours

const int redPin = 8;
const int greenPin = 10;
const int bluePin = 12;
 
void setup() {
}
 
void loop() {
  analogWrite(redPin, random(0,255));
  analogWrite(greenPin, random(0,255));
  analogWrite(bluePin, random(0,255));
  delay(500);
}

Upload the following code to your Arduino Uno! This changes the every colour's value randomly, within the range of 0 to 255. Another way to go about it is to change it to a fixed colour, give it a try! Also, the colour is being changed every half a second, but you can change the delay value too.