Color Changing Light

The purpose of this project is to create a light that wen placed on a certain colored surface ex. blue, the photoreisistor reads that the LED, when lit blue, reflects the most light on a blue surface, resulting in the light on top of the box to light up blue.

The LED on the bottom of the box cycles through red, green, and blue while the photoresistor reads the values of light reflected off of the surface. The value of the photoresistor tells the LED on top which color to light up. The photoresistor does this by using the highest value of the light reflected. The highest value of light reflected is the same color of the surface it is on, ex. blue light reflects the most on a blue surface.

int redPin = 8; //sets the variable for the LEDs

int greenPin = 7;

int bluePin = 6;

int redPin2 = 5;

int greenPin2 = 4;

int bluePin2 = 3;

int potPin = 5; //sets the variable for the photoresistor

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

int redVal = 0;

int greenVal = 0;

int blueVal = 0;

void setup()

{

pinMode(redPin, OUTPUT); //sets the LEDs to OUTPUTs

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

pinMode(redPin2, OUTPUT);

pinMode(greenPin2, OUTPUT);

pinMode(bluePin2, OUTPUT);

Serial.begin(9600); //tells the serial monitor to begin reading the values

}

void loop()

{

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

delay(500);

val = analogRead(potPin); //tells the photoresistor to read the value of light reflected

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

Serial.println(val); //prints the value of the reflected light

redVal=map(val, 800, 990, 0, 255); //converts the value from the photo resistor to a number between 0 and 255

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 arudino to turn the LED on top of the box on to the color of the most reflected color

analogWrite(greenPin2, greenVal);

analogWrite(bluePin2, blueVal);

}

Problems we encountered during this project were the LEDs not lighting up at the right time, the LED on top not lighting up to the correct color we wanted, and getting the project to stay inside the box and still work.

If we had more time and money we would have probably made a better project enclosure to hold it in, we would have had more time to figure out a better way to get everything to stay in place inside the box, and we would have modified the code to work better and light up in more colors.