Example Code for Arduino-Random Color Light Effect
Last revision 2025/12/12
This article provides step-by-step instructions and example code for creating a random color light effect using Arduino, utilizing PWM pins and digital pins 3, 5, and 6 to control RGB LEDs effectively.
Wiring Diagram

This Disk requires PWM pins, you may use any Pins capable of PWM output.
Other Preparation Work
This sample code use Digital Pin 3,5,6 and GND
This code only works for V1 version which comes with a soldered cable
Connect the 5V pin of light disc to GND Pin of Arduino
Sample Code
//This sample code use Digital Pin 3,5,6 and GND
// This code only works for V1 version which comes with a soldered cable
// www.dfrobot.com
// Last modified on 26/11/2014
int B = 3; //Connect Blue led to Digital pin 3
int R = 5;//Connect Red led to Digital pin 5
int G = 6;//Connect Green led to Digital pin 6
//Connect the 5V pin of light disc to GND Pin of Arduino
void setup()
{
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
analogWrite(B,random(255));
analogWrite(R,random(255));
analogWrite(G,random(255));
delay(80);
}
Was this article helpful?
