In this project, Arduino will send the analog readings obtained from a Photo Resistor, also known as a Light Dependent Resistor (LDR), to the computer and according to the values RGB Light will change its colours.

Parts required:

  • PhotoCell (or PhotoResistor)
  • 10K ohm resistor
  • 330 ohm resistor
  • RGB light
  • Breadboard
  • Arduino UNO
  • 5 wires(to connect it all together)

//Code for Arduino to Map Colours

int redPin = 6; // declaring the pins of each RGB LED led
int greenPin = 5;
int bluePin = 3;
int LDR = A0; // light dependent sensor
int redMapped; // declare integers for mapped values
int blueMapped;
int greenMapped;

void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
int light = analogRead(LDR); //LDR will take analog readings
blueMapped = map(light, 0, 1023, 0, 255); // map blue – note highs/ lows
redMapped = map(light, 0, 1023, 255, 0);

blueMapped = constrain (blueMapped, 0,255); // contrain values between 0 and 255
redMapped = constrain (redMapped, 0, 255);

Serial.print(light);
Serial.print(“,”);
Serial.print(blueMapped);
Serial.print(“,”);
Serial.println(redMapped);

setColor(redMapped, 0, blueMapped); //ggradient from less light = blue, more light = red
}
void setColor(int red, int green, int blue) //setColor function
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

}

 

Arduino Colour Mapping is a project of IaaC, Institute for Advanced Architecture of Catalonia developed at Master in Advanced Architecture in 2015 of the Academic Program by:

Student:

Lalin Keyvan

Faculty:

Carmen Aguilar

Ramin Shambayati