analogWrite not functioning in if statement

brightness is zero every time through loop. loop is essentially this...

void loop(){
  int val = analogRead(sensorPin);
  Serial.println(val);

  //just to slow down the output - remove if trying to catch an object passing by
  delay(1000);
  
  if (val >= 1000){
    
    counter++; 
    counter = counter%5;
  
  }
  
  Serial.println(counter);
  

if (counter == 1){
  // set the brightness of pin 9:
  analogWrite(2, 0);    

  // wait for 30 milliseconds to see the dimming effect    
  delay(30); 
  
}

//some else ifs here for the counters 2 - 4, cut for length

else {
  //all off
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);

}

  
}

...which is clearly not what you want. Does this bring any clarity... http://arduino.cc/en/Reference/scope