Jump to content

Check out our Community Blogs

- - - - -

Arduino Project 04

Posted by Alcamech, 07 August 2013 · 19041 views

arduino uno project 04 programming code open source electronics circuitry
Here it is ! Arduino project 04 , titled "Color Mixing LAMP". By using a tri-color LED and three photo-resistors I created a LED that smoothly changes colors depending on external lighting conditions.

The components of this project included:
  • 220 ohm resistor (3)
  • 10 kilohm resistor(3)
  • photo-resistor(3)
  • GEL color filter(3, RGB)
  • jumper wires
And because the Arduino can't vary the output voltage on its pins, cause it can only output 5V. I had to use a technique called the Pulse Width Modulation ( PWM ) to fade LEDs. PWM rapidly turns the output pin high and low over a fixed period of time.
The Arduino Uno has six pins set aside for PWM( digital pins 3, 5, 6, 9, 10, and 11). And in addition to that I also learned about Photo-Resistors(What they are and how they work).

Source Code:
const int greenLEDPin = 9;
const int blueLEDPin = 10;
const int redLEDPin = 11;
                              //useful constants
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(){
                                //setting the direction of the digital pins and setting up the serial port
  pinMode(greenLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);

void loop(){
  redSensorValue = analogRead(redSensorValue);
  delay(5);                                         //reading the vlaue of each light sensor
  greenSensorValue = analogRead(greenSensorValue);
  blueSensorValue = analogRead(blueSensorValue);
  Serial.print("Raw Sensor Value \t Red:");
  Serial.print("\t Green:");                //report the sensor readings to the computer
  Serial.print("\t Blue:");
  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(" \t Green:");      //report the calculated LED light levels
  Serial.print("\t Blue:");
  analogWrite(greenLEDPin, greenValue);    //Set the LED light levels
  analogWrite(blueLEDPin, blueValue);

Posted Image

Posted Image

Posted Image

  • 3

very neat and organized code :) and good design too, but how much did you pay for those light sensors? 

    • 0

The whole kit is priced on amazon for aorund 120$ but im looking here that you can get 20 photo-resistors for 9.99 on amazon .

    • 0

I see, so it mimicks the colour temperature/colour of the room on to the LED? What could be some improvements?


I would maybe..

1. Isolate the LED from the sensors, to prevent a feedback loop.

2. maybe remove the delays from where they are (are you running in to a bug reading them all at the same time?) and situate it after the reading.

3. Maybe averaging could be used! Read 5 times maybe in to an array, add them together, divide the result by 5 to smooth any changes so they are not jittery and reduce your rate of noise or errors. I find your project fancy!


PS: Making this in to a fair priced DIY kit, I think the Arduino can be found for $~30, and if you use Newark/Digikey or other industry component redistributors you can probably get resistors and LEDs for $0.10-$0.99 each, more akin to your Amazon findings. Just the colour-gel stuffs need to be found. You can probably make them out of coloured transparencies, would fit your intended precision quite well and you can always calibrate for them if they're not perfectly RGB.

    • 0

Recent Entries

Recent Comments

My Picture

0 user(s) viewing

0 members, 0 guests, 0 anonymous users


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download