TINKER PiEDESIGN IN INDIA

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

Parts

TinkerPie V1 board1 RGB LED3 resistors, 220 Ω

Steps

  1. Add the parts

    Add an RGB LED and three Resistors. The middle long leg (−) is the common cathode.

  2. Wire the colours

    Pins S1, S2, S3 go through a resistor each to R, G and B. The long leg (−) goes to GND.

  3. Write a colour function

    A function colour(r, g, b) calls analogWrite three times, each from 0 (off) to 255 (full).

  4. 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.

Challenge: Make purple (red + blue) and cyan (green + blue). Then make a colour that changes with a potentiometer.

← Measure with a voltmeter and ammeter · All 24 circuit tutorials · Blink an LED →