Color Changing Light

The purpose of this project is to make a light that when placed on a certain colored surface, lights up to that color.

Ex. If the light is placed on a blue surface, the LED on top will turn blue

When the code runs the arduino turns each light on in the multi-colored LED in a cycle. It reflects on the surface to help the photoresistor figure out what color it is on. It does this because the color that the light is on, lets go with blue, when the light is on a blue paper and it goes through each color the blue LED reflects the most light off of the blue surface then the red and green colors. Then the photoresistor takes the highest number value and send that to the other LED on top of the light to turn it on. This process repeats continuosley to keep the light on top lite to the color of the surface it is on.

int redPin = 8; //sets variables for different LEDs

int greenPin = 7;

int bluePin = 6;

int redPin2 = 5;

int greenPin2 = 4;

int bluePin2 = 3;

int potPin = 5; //sets variable for photoresistor

int val = 0; //variable for value read from photoresistor

int redVal = 0;

int greenVal = 0;

int blueVal = 0;

void setup()

{

pinMode(redPin, OUTPUT); //makes each LED an OUTPUT

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

pinMode(redPin2, OUTPUT);

pinMode(greenPin2, OUTPUT);

pinMode(bluePin2, OUTPUT);

Serial.begin(9600);

}

void loop()

{

digitalWrite(redPin, HIGH); //turns LED on

delay(500);

val = analogRead(potPin); //tells arduino to read the value from the photoresistor

digitalWrite(redPin, LOW); //turns LED off

Serial.println(val); //writes val

redVal=map(val, 800, 990, 0, 255); //take the value from between the first set of number and changes it to a number between 0 and 255 to set the color

digitalWrite(greenPin, HIGH);

delay(500);

val = analogRead(potPin);

digitalWrite(greenPin, LOW);

Serial.println(val);

greenVal=map(val, 800, 990, 0, 255);

digitalWrite(bluePin, HIGH);

delay(500);

val = analogRead(potPin);

digitalWrite(bluePin, LOW);

Serial.println(val);

blueVal=map(val, 800, 990, 0, 255);

analogWrite(redPin2, redVal); //tells the second LED to turn on to a certain value

analogWrite(greenPin2, greenVal);

analogWrite(bluePin2, blueVal);

}