Problem with potentiometer and LED


I have a problem with my (simple) circuit.

I connected a LED to digital PIN 5 with a resistor in series, going to ground. A cable goes from +5V to my potentiomenter (right connection). A cable goes from ground to the left connection of my pot. The middle connection of my pot goes to analog pin 2.

My sketch just takes the value from analog pin 2 and does an analogWrite of the same value to my led.

It works almost fine. When I turn the pot shaft, it fades smoothly but then the led goes off (approx. 0.1V) and starts to fade up again as I turn the pot.

I did a serial print to see what values were read by the analog pin 2 and everything is ok. What could be the problem? (I hope my arduino is not damaged! :( )

Thank you!

Oh BTW, my resistor is 1K and my pot is 10K.

Daa forget that, digital is 0 to 255, not 1023...

So:- val = analogRead(2) / 4; analogWrite(5,val);

should do it

thank you