Saturday, February 9, 2013

RGB Light Dimmer

Made a light dimmer that will control a multicolored LED through the colors of the rainbow.  I started with concept from this post and expanded it. The code can be seen after the jump break.




Light Dimmer


Thanks to Arduino.cc for the code.

Pictures



Video:


Code:
/*Quick note, dividing by 4.011 is used because the potentiometer can range from 0 to 1023 and the LED brightness can go from 0 to 255 so it wouldn't make sense to give values greater than 255 to the LED so I scaled the poteniometer range to 0 to 255 by dividing by 4.011. */

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read
int ledPin= 6;
void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin)/4.011;    // read the input pin.
  analogWrite(ledPin,val) ;           // debug value
}





Consuming parts for new projects

Combined a battery clip I have today with a power adapter I salvaged from something I took apart to see what was on the inside.