Luis Estades
Published

Project 4 Color Changing Lamp

Using a tri color LED and three gel filtered phototransistors, to create a lamp that changes colors depending on outside factors

BeginnerShowcase (no instructions)2 hours63
Project 4 Color Changing Lamp

Things used in this project

Story

Read more

Schematics

Fritzing Diagram

Code

Color Changing 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;




void setup() {
  Serial.begin(9600);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);

}

void loop()
 {
  redSensorValue = analogRead(redSensorpin);
  delay(5);
  greenSensorValue = analogRead(greenSensorpin);
  delay(5);
  blueSensorValue = analogRead(blueSensorpin);
  delay(5);
  //reads value of each sensor.
Serial.Print("Raw Sensor \t red: ");
Serial.Print(redSensorValue);
Serial.Print("\t green  ");
Serial.Print(greenSensorValue);
Serial.Print("\t blue  ");
Serial.Print(blueSensorValue);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;

Serial.Print("Mapped Sensor values \t");
Serial.Print(redValue);
Serial.Print("\t Green");
Serial.Print(greenValue);
Serial.Print("\t Blue");
Serial.Print(blueValue);
//report and print calculated LED levels
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
//Set LED light levels

}

Credits

Luis Estades
13 projects • 1 follower

Comments