Saturday, February 9, 2013

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
}





No comments:

Post a Comment