Ahmed Hamdy
Published © GPL3+

Arduino Color Mixer

This project will let you have some fun playing with colors using Arduino analog input / output. Change colors with just a twist.

BeginnerFull instructions provided12 minutes18,445
Arduino Color Mixer

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
RGB Led
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Full Circuit

Code

RGB LED Game code

Arduino
Connect the LED pins according to the pins in outRGB array and the sensor pins according to inRGB array
/*

 Controls RGB LED using potentiometers for each color

 Name:		RGBLedPot.ino
 Created:	17/2/16 9:47:03 AM
 Author:	Ahmed Hamdy
 GNUPL 3.0+
*/

// the setup function runs once when you press reset or power the board

int inRGB[] = { A0,A1,A2 }; // Analog Inputs to reada potentiometer values
int outRGB[] = { 9,10,11 }; // PWM output pins to control brightness of each color in the RGB LED
int tempValue = 0;	// Placeholder

const int inMinVal = 0, inMaxVal = 1023;	// Values that define the maximum and minimum value returned from the potentiometer reading

void setup() {

	// Loop on all pins ( 3 values: Red, Green and Blue )
	for (int i = 0; i < 3; i++)
	{
		pinMode(inRGB[i], INPUT);	// Prepare those pins to read the potentiometer values
		pinMode(outRGB[i], OUTPUT);	// Prepare those pins to output the values of the RGB LED
	}
}

// the loop function runs over and over again until power down or reset
void loop() {

	// Repeat the following for each color
	for (int i = 0; i < 3; i++)
	{
		tempValue = analogRead(inRGB[i]);	// Read the potentiometer

		// Scale down the potentiometer reading ( 0 ~ 1023 ) to a valid PWM value
		// 0 ~ 255 represent the range of the Arduino PWM output
		tempValue = map(tempValue, inMinVal, inMaxVal, 0, 255);
		
		// Write the output on the pin
		analogWrite(outRGB[i], tempValue);
	}
}

Credits

Ahmed Hamdy

Ahmed Hamdy

7 projects • 105 followers
I Love programmable stuff. Don't hesitate to send me an e-mail >> ahmedhamdyau@gmail.com

Comments