LED fading effect using a push button
The 1k (pulldown-)resistor must be placed at the other side of the button (the pin8 side, not the 5v side).

The led needs a resistor, to limit the current.

There is no need for the buttonstate variable, as you can just check the brightness to see if the PWM value must be changed.

int ledpin = 9;
int pushbutton = 8;

int brightness = 0;
int fadeamount = 1;

void setup ()
{ 
  pinMode (ledpin,OUTPUT);
  pinMode (pushbutton,INPUT);
}

void loop ()
{ 
  if( digitalRead(pushbutton)==HIGH &amp;&amp; brightness&lt;255 )
  {
    // fade in led 
    brightness = brightness + fadeamount;// increase brightness
    if( brightness&gt;255 ) // check that brightness doesn't exceed 255
      brightness = 255;
    analogWrite(ledpin,brightness);
    delay (1);
  }
  else if( digitalRead(pushbutton)==LOW &amp;&amp; brightness&gt;0 )
  {
    // fade out led
    brightness = brightness - fadeamount;// decrease brightness
    if( brightness&lt;0 ) // check that brightness doesn't go below 0
      brightness = 0;
    analogWrite(ledpin,brightness);
    delay (1);
  }

}