/* Simple sketch to show output of potentiometer value on the Serial Output Window and controlling the brightness of an LED with pwm. 3/18/2012 */ int potPin = A0;// potentiometer attached to A0 int potVal = 0; // potentiometer value 0-1023 int pwmPin = 3; // pin for LED int pwmVal = 0; // PWM value, based on potVal, 0-255 void setup(){ Serial.begin(9600); pinMode(pwmPin, OUTPUT);// not necessary, but is best practice } void loop(){ potVal = analogRead(potPin); Serial.println(potVal); pwmVal = map( potVal, 0, 1023, 0, 255 ); analogWrite(pwmPin, pwmVal); }