RGB LED Beginner Tutorial & Random Colors Every 2 Seconds


const byte blue = 9;
const byte red = 10;
const byte green = 11;
void setup() {
  // put your setup code here, to run once:
  pinMode(blue, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(blue, random(0, 256));
  analogWrite(red, random(0, 256));
  analogWrite(green, random(0, 256));

Are the current limiting resistors for the LEDs on the little PC board? If not, where are they?

Please edit & post your code properly, or this can go to the project gallery!

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You shall extend your "RGB LED Beginner Tutorial" with this smart and small solution for "Random Colours Every 2 Seconds".

constexpr byte LEDs[] {10,11,12};
void setup() {
  for (auto LED : LEDs) pinMode(LED, OUTPUT);
void loop () {for (auto LED : LEDs) analogWrite(LED, random(0,256)); delay(2000);}

Yes, all the resistors are already wired on the pc board.

Thank you very much, I fixed the code. :slightly_smiling_face:

Done, Thank you for the warning.

It's a great idea, but I try to leave the arrays and "for" statement statements out of the beginner tutorials.

Beginner for C++ :nerd_face:

yeah but this is beginner arduino tutorial