LED Illumination Control with Arduino Uno

There was an online guide that walks a viewer through how to assign color variable values in code to red, green and blue. To combine each as having relative color strength to produce a mixed color output on an RGB LED. This is a way to prepare unique light color values beyond the conventional LED lights with fixed colors. In this small project, color is programmed within the Arduino IDE and thereafter code loaded into the SBC itself to run the unique color mix.

The code to set up this functionality is set up on Arduino Sketch. To write and edit instructions that determine the operability and behavioral properties of the hardware and circuit.

After declarations and set up, this is what the code looks like.

void loop()
{
Serial.println(“Please input your color choice (red, green or blue): “);
while (Serial.available()==0) {

colorChoice= Serial.readString();

if (colorChoice==”red”)
{analogWrite(redPin,brightness);
analogWrite(bluePin,0);
analogWrite(greenPin,0);
}
if (colorChoice==”green”){
analogWrite(redPin,0);
analogWrite(bluePin,0);
analogWrite(greenPin,brightness);
}
if (colorChoice==”blue”){
analogWrite(redPin,0);
analogWrite(bluePin,brightness);
analogWrite(greenPin,0);
}
if ( colorChoice != “red” && colorChoice != “green” && colorChoice != “blue”) { //test for valid input
Serial.println(“”);
Serial.println(“You have not entered a valid color, please enter red, blue or green”);
Serial.println(“”);
}
}

About

Servant of Christ Jesus. U.S. Military Veteran, Electrical Engineer, Pepperdine MBA, and M.A. Biblical and Theological Studies.

, ,

Comments are closed.