laurenkoi
Published

Arduino Project 4: Color Mixing Lamp

Changing light color based on amount of light reacting with sensor.

BeginnerShowcase (no instructions)1 hour335
Arduino Project 4: Color Mixing Lamp

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Grove - Variable Color LED V1.1
Seeed Studio Grove - Variable Color LED V1.1
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 10 kohm
Through Hole Resistor, 10 kohm
×1
Photodiode, 45 °
Photodiode, 45 °
×1

Story

Read more

Schematics

Video

Fritzing

Schematics

Code

Color Mixing Light Code

Arduino
const int greenLEDPin = 9;
 const int blueLEDPin = 10;
 const int redLEDPin = 11;

 const int redSensorPin = A0;
 const int greenSensorPin = A1;
 const int blueSensorPin = A2;
 int redValue = 0;
 int greenValue = 0;
 int blueValue = 0;
//variables to store the sensor readings as well as the light level of each LED
 int redSensorValue = 0;
 int greenSensorValue = 0;
 int blueSensorValue = 0;
void setup(){
 Serial.begin(9600);

 pinMode(greenLEDPin, OUTPUT);
 pinMode(blueLEDPin, OUTPUT);
 pinMode(redLEDPin,OUTPUT);
}
void loop(){
 redSensorValue = analogRead(redSensorValue);
 delay(5);
//reading the vlaue of each light sensor
 greenSensorValue = analogRead(greenSensorValue);
 delay(5);
 blueSensorValue = analogRead(blueSensorValue);
 Serial.print("Raw Sensor Value \t Red:");
 Serial.print(redSensorValue);
 Serial.print("\t Green:");
//report the sensor readings to the computer
 Serial.print(greenSensorValue);
 Serial.print("\t Blue:");
 Serial.print(blueSensorValue);
 redValue = redSensorValue/4;
 greenValue = greenSensorValue/4;
//Convert the sensor readings from a value between 0 - 1023
 blueValue = blueSensorValue/4;
//to a value between 0 - 255
 Serial.print("Mapped Sensor Values \t Red:");
 Serial.print(redValue);
 Serial.print(" \t Green:");
//report the calculated LED light levels
 Serial.print(greenValue);
 Serial.print("\t Blue:");
 Serial.print(blueValue);
 analogWrite(redLEDPin,redValue);
 analogWrite(greenLEDPin, greenValue);
//Set the LED light levels
 analogWrite(blueLEDPin, blueValue);
 }

Credits

laurenkoi

laurenkoi

13 projects • 1 follower

Comments