RGB colour mixerTinkerPieCircuit tutorial 7 of 24 · Intermediate · 20 minutes
Mix red, green and blue light with an RGB LED to make any colour.
Open this circuit in TinkerPieCircuit (free, runs in your browser)
What you will learn
- How an RGB LED has three LEDs in one
- Mixing light colours
- analogWrite and functions
Parts
Steps
Add the parts
Add an RGB LED and three Resistors. The middle long leg (−) is the common cathode.
Wire the colours
Pins
S1,S2,S3go through a resistor each to R, G and B. The long leg (−) goes toGND.Write a colour function
A function
colour(r, g, b)callsanalogWritethree times, each from 0 (off) to 255 (full).Press Start
Watch red, green, blue, orange and white. Then the fade from blue to red.
The code
function setup() {
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
}
function colour(r, g, b) {
analogWrite(S1, r);
analogWrite(S2, g);
analogWrite(S3, b);
}
function loop() {
colour(255, 0, 0);
delay(700);
colour(0, 255, 0);
delay(700);
colour(0, 0, 255);
delay(700);
}
Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.
How it works
Red, green and blue light add together. Equal amounts of all three make white, red plus green make yellow. Each colour needs its own resistor.
← Measure with a voltmeter and ammeter · All 24 circuit tutorials · Blink an LED →