RGB LED Module with Arduino
Written By: Cherie Tan
Difficulty
Easy
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.
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.
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.