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.
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:
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.
Use this breadboard diagram for reference:
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.
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!
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!