Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
RGB Module

Introduction
The RGB Full Color LED module emits a range of colors by mixing red, green, and blue light. Each color is adjusted by using PWM.It can be used to create colorful lighting effects or to learn how to use PWM (pulse-width modulation) with Arduino.
Principle
The RGB MODULE works by using a full-color LED that uses R, G, and B pins with adjustable PWM voltage input. Colors from the LED can be combined. For example, mix blue light and green light give cyan light, red light and green light give yellow light. This is called “The additive method of color mixing”.

Based on this method, we can use the three primary colors to mix the visible light of any color according to different proportions. For example, orange can be produced by more red and less green. The strength of the primary colors (red, blue, green) is adjusted in order to achieve full color mixing effect.PWM is a technique where the duty cycle of a digital signal is modified, adjusting the percentage of time that the signal remains active within a given period. By changing the duty cycle, we can make the LED appear brighter or dimmer.
Module Schematic Diagram

Usage
Hardware components
Arduino Uno R4 or R3 board * 1
RGB Module * 1
Jumper Wires
Circuit Assembly

Code
Code explanation
The first segment of the code declares and initializes the pins to which each color channel of the RGB LED module is connected.
const int rledPin = 9; // pin connected to the red color channel const int gledPin = 10; // pin connected to the green color channel const int bledPin = 11; // pin connected to the blue color channel
The
setup()
function initializes these pins as OUTPUT. This means we are sending signals OUT from these pins to the RGB LED module.void setup() { pinMode(rledPin, OUTPUT); pinMode(gledPin, OUTPUT); pinMode(bledPin, OUTPUT); }
In the
loop()
function, thesetColor()
function is called with different parameters to display different colors. Thedelay()
function is used after setting each color to pause for 1000 milliseconds (or 1 second) before moving on to the next color.void loop() { setColor(255, 0, 0); // Set RGB LED color to red delay(1000); setColor(0, 255, 0); // Set RGB LED color to green delay(1000); // The rest of the color sequence... }
The
setColor()
function uses theanalogWrite()
function to adjust the brightness of each color channel on the RGB LED module. TheanalogWrite()
function employs Pulse Width Modulation (PWM) to simulate varying voltage outputs. By controlling the PWM duty cycle (the percentage of time a signal is HIGH within a fixed period), the brightness of each color channel can be controlled, allowing the mixing of various colors.void setColor(int R, int G, int B) { analogWrite(rledPin, R); // Use PWM to control the brightness of the red color channel analogWrite(gledPin, G); // Use PWM to control the brightness of the green color channel analogWrite(bledPin, B); // Use PWM to control the brightness of the blue color channel }
Additional Ideas
Try displaying other colors
Integrate the RGB LED with sensors, and display different colors based on the sensor’s value.