int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(9600); // setup serial
pinMode(3,OUTPUT);
}
void loop()
{
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
if (val>500){analogWrite(3,128);}
}//i simplfied the code
Moderator edit: I added code tags.