RGB LED: one light, seven colours
One LED with a red, a green and a blue light inside: the program mixes them to choose the colour, from purple to cyan to white. Its legs use the red, green and blue LED pins.
The test program
Test this part on its own before you build the rest: if it works alone, the rest is built on something you know works.
10 RGB red
20 WAIT 500
30 RGB green
40 WAIT 500
50 RGB blue
60 WAIT 500
70 RGB white
80 WAIT 500
90 GOTO 10What you should see: The LED turns red, then green, then blue, then white, and starts again.
▶ Try it in the IDEWhat to buy
- Common-cathode RGB LED, 4 legs (with three resistors: 220 Ω, or 470 Ω on the UNO R4)
How to wire it to an ESP32-S3
- R → ESP32-S3: GPIO4Through a 220 Ω resistor
- G → ESP32-S3: GPIO1Through a 220 Ω resistor
- B → ESP32-S3: GPIO18Through a 220 Ω resistor
- − → ESP32-S3: GNDThe longest leg is the common cathode: it goes to ground.
If it does not work
- The program runs but nothing happens
- The long leg (the common cathode) is not on ground, or the LED is common anode instead of common cathode. The longest leg goes to GND; the other three to the pins, each through its own resistor (220 Ω, or 470 Ω on the UNO R4). If the colours come out swapped, your LED's legs are in another order: swap the green and blue wires.
Which boards it works on
- ESP32-S3 Freenove: yes
- Nordic nRF54LM20 DK: yes
- Arduino UNO R4 WiFi: yes