Introduction: Make Any Colour With One LED!

Picture of Make Any Colour With One LED!

The RGB LED can produce virtually any colour you want. However with the digital output signals of the Arduino we are limited to the use of the 3 primary colours of the LED which are red, green, and blue (RGB), as well as the combination of these colours, that is, violet, cyan, and yellow. However to produce more elaborate patterns, it requires an analog input for each of the different coloured LEDs housed in a single RGB LED. The potentiometer is a perfect input for controlling each of pin of an RGB LED giving us the ability to make any colour we wish!

Step 1: Tools and Materials

Picture of Tools and Materials
  • Arduino 101 or Arduino Uno
  • Breadboard
  • 3 Potentiometers
  • RGB LED
  • 3 pieces of 100Ω resistors
  • Jumper wires

Step 2: Circuitry

Picture of Circuitry

Connecting the Arduino power to the breadboard power rails.

  • Connect the 3.3V pin from the Arduino to the red power rail on the breadboard.
  • Connect the GND pin from the Arduino to the black power rail on the breadboard.

Wiring the Potentiometers.

  • For each potentiometer connect one of the outermost pins to the red power rail on the breadboard.
  • Connect the remaining outermost pin to the black power rail on the breadboard for all the potentiometers.
  • Connect the middle pins of each of the potentiometer to pins A0, A1, and A2 on the Arduino with pink, green, and blue jumper cables for each of the colour LEDs they will control.

Lastly, connecting the RGB LED to the Arduino.

  • Connect the longest pin to the common ground on the breadboard
  • Connect the red pin of the RGB LED (the outermost pin closest to the ground pin) to a 100Ω resistor, then in series to pin 5 on the Arduino with a pink jumper wire to differentiate it from red being 3.3V.
  • Connect the green pin (the remaining pin that's not on the outside) to a 100Ω resistor, then in series to pin 6 on the Arduino with a green jumper wire.
  • Connect the blue pin (the only other unconnected pin) to a 100Ω resistor, then in series to pin 9 on the Arduino with a blue jumper wire.

Step 3: Code

Picture of Code

//create constants for the three analog input pins

const int redPot = 0; const int greenPot = 1; const int bluePot = 2;

//create constants for the three RGB pulse width pins const int redPin = 5; const int greenPin = 6; const int bluePin = 9;

//create variables to store the red, green and blue values int redVal; int greenVal; int blueVal;

void setup() { //set the RGB pins as outputs pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); }

void loop() { //read the three analog input pins and store their value to the color variables redVal = analogRead(redPot); greenVal = analogRead(greenPot); blueVal = analogRead(bluePot);

//use the map() function to scale the 10 bit (0-1023) analog input value to an 8 bit //(0-255) PWM, or analogWrite() signal. Then store the new mapped value back in the //color variable

redVal = map(redVal, 0, 1023, 0, 255); greenVal = map(greenVal, 0, 1023, 0, 255); blueVal = map(blueVal, 0, 1023, 0, 255);

// use the analogWrite() function to write the color values to their respective // RGB pins. analogWrite(redPin, redVal); analogWrite(greenPin, greenVal); analogWrite(bluePin, blueVal); }

Step 4: Demo

Changing each of the potentiometer will change the colour of the RGB LED. Each potentiometer corresponds to one of the colours, and controls the brightness of each colour, thus turning all of them to max will produce a white light. Since the potentiometer is an analog signal you can make virtually any colour you wish by turning the potentiometer knobs.

Comments

About This Instructable

152views

6favorites

License:

Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: