Trouble using proximity sensor as input and LED output
You want 2 independant loops, one for the measurement and one for the dimming effect. The latter one must also be able to run when not measuring.

if(millis()-lastReading&gt;=sampleRate) //this very simple statement is the timer,
{ 
  distanceVal = proximity1.ping_cm();  //get the distance value in centimeters


  lastReading = millis();

  Serial.print("Distance Reading CM : ");  //print the value to the Serial monitor
  Serial.println(distanceVal);
}

if(millis() - lastFade &gt;= fadeRate) //other timer
{
  lastFade = millis();
  if(distanceVal&lt;20){
    fadeAmount = 5;
  }else{
    fadeAmount = 2;
  }

  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness &lt;= 0 || brightness &gt;= 255) {
    fadeAmount = -fadeAmount;
  }
}