Project: RGB Mixer

Objectives and Overview

This project takes your RGB LED and potentiometer skills to the next level! This project is a great example of how you can combine input and output components to create an interactive project. The RGB Mixer covers several  Arduino concepts such as analog input and analog output.

Lesson Objectives

  • Combine a potentiometer input with the RGB LED output to create a color mixer.

RGB Mixer

The RGB Mixer is a literal example of mixing the Red, Green, and Blue values of the RGB LED. You’ll use three potentiometers as input knobs to control the Red, Green, and Blue values. The position of each knob controls the color output from the RGB LED.

The wiring for the project may seem complex, but it’s really the same wiring patterns repeated multiple times. Once you get through the basics, you can create a physical enclosure and begin thinking about how to take your mixer beyond the breadboard!

Here’s an image of the completed Arduino and breadboard wiring:

Arduino and breadboard wired up to be a RGB Mixer

Supplies

  1. Arduino and USB
  2. Breadboard
  3. Common Anode RGB LED
  4. 3x 270 Ohm resistors (Red Purple Brown)
  5. 3x potentiometers
  6. 18x jumper wires

Steps

This project builds on the skills you’ve used while working with the projects for the potentiometer and the RGB LED. There are two parts for the steps: circuit assembly and code for the sketch. It may seem like several steps, but you’re repeating the same wiring multiple times.

Circuit

Use this breadboard diagram for reference:

Fritzing diagram for the RGB mixer project showing an Arduino Uno and breadboard with potentiometers and a RGB LED
  1. Connect the Arduino 5v to the + rail of the breadboard.
  2. Connect the Arduino GND to the – rail of the breadboard.
  3. Place the RGB LED on the top right side of the breadboard. This occupies column J in the diagram. Make sure to align it so that the red lead is in the top most pin.
  4. Connect Arduino pins ~11, ~10, ~9 to the R, G, and B on the RGB LED.
    • You can see ~11, ~10, and ~9 are connected to breadboard pins A1, A5, and A7. This is to provide enough space for the components.
  5. Place a 270 Ohm resistor between the pin connection and each lead from the RGB LED.
    • There is a yellow wire connected from Arduino pin ~11 to A1 on the breadboard. The resistor is placed on this same row and connects the wire and the R lead of the RGB LED.
  6. Connect the + rail of the breadboard to the common anode lead. This is the second lead from the top in the diagram.
  7. Place each potentiometer on the breadboard. You should be using 3 total. Space them out so that they aren’t right next to each other.
  8. Connect the top potentiometer pin to the + rail of the breadboard.
  9. Next, connect the middle potentiometer pin to the Arduino A0.
  10. Then connect the bottom potentiometer pin to the – rail of the breadboard.
  11. Repeat steps 8, 9, and 10 for each potentiometer using Arduino pins A1 and A2 for the middle pins.

Wiring Tips

Remember, the middle pin for the potentiometer is the signal output. The readings from the potentiometer are sent from this pin into the Arduino via the analog input pins. The analog inputs used in this project are A0 for the first potentiometer, A1 for the second, and A2 for the third. The result is that each potentiometer has a dedicated Arduino analog input pin.

Sketch

The sketch includes concepts from the RGB LED and the potentiometer sketches. The base sketch contains comments to guide you.

You should experiment and alter the code once you understand the functionality. Here’s the base sketch:

/* * RGB Mixer code by Jonathan Prozzi. * This includes Simon Monk's RGB LED code from the Adafruit lesson. * * There are several variables that need to be initialized. * Remember, if you change the pins on the Arduino you * also change the variables below. */ // These are the pins connected to each of the RGB leads. int redPin = 11; int greenPin = 10; int bluePin = 9; // These are the input pins for the potentiometers. int redPot = A0; int greenPot = A1; int bluePot = A2; // These are the initial reading values for the potentiometers. int redVal = 0; int greenVal = 0; int blueVal = 0; // These are the initial color values - used later in the sketch. int redColor = 0; int greenColor = 0; int blueColor = 0; #define COMMON_ANODE; // This is necessary for the common anode RGB LED. void setup() { // Set the RGB LED pins for output. pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); Serial.begin(9600); // Setting the Serial monitor to check the values from the pots. } void loop() { // Read the values from each potentiometer redVal = analogRead(redPot); greenVal = analogRead(greenPot); blueVal = analogRead(bluePot); // Print the pot values to the Serial monitor. This is to check that the readings are coming in. Serial.print("Red Reading: "); Serial.println(redVal); Serial.print("Green Reading: "); Serial.println(greenVal); Serial.print("Blue Reading: "); Serial.println(blueVal); delay(1000); // Map the potentiometer readings (0 - 1023) to RGB values (0 - 255) redColor = map(redVal, 0, 1023, 0, 255); greenColor = map(greenVal, 0, 1023, 0, 255); blueColor = map(blueVal, 0, 1023, 0, 255); // Set the RGB colors to the values from the potentiometers setColor(redColor, greenColor, blueColor); } void setColor(int red, int green, int blue) { #ifdef COMMON_ANODE red = 255 - red; green = 255 - green; blue = 255 - blue; #endif analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); }
Code language: PHP (php)

This sketch doesn’t contain any new commands!


Going Further

Once you understand the concepts and setup you can try a variety of different things. One suggestion would be to find a way to create a physical enclosure for the project. Another recommendation is to build an enclosure for the LED. One great suggestion is to use a clear piece of plastic or a see-through ping-pong ball to amplify the light.

This is a fun project that illustrates both analog input and output!