Need help with logic to fix "dead zone" area in balance beam pivot

Hello,

I am doing a project that requires balancing of a ball on a beam using PID control. A portion of the project uses an IR sensor to detect the distance of the ball and depending on that distance adjusts the beam accordingly to optimum position. This distance is calculated with a min and max distance value. What I need help with is that if the ball is too close, it could mess up with the sudden drop of the value ("dead zone" area) and have the balancing beam go haywire. I was looking for someone who can help guide me to fixed this dead zone with code? I was thinking of using the constrain function and force a value once the ball crosses a certain point on the beam but that value could possibly be on another position on the beam pivot. If someone can help me with this it would be greatly appreciated.

int i;
int iprev;
int val = 0;
int y;
int toggle;
int redpin= A15;
int theta = 10;
int smoothIR;

void setup() {
   // pinMode(redpin,OUTPUT);
    Serial.begin(9600);
    i= analogRead(A15);
    iprev = analogRead(A15);
    smoothIR = i;
    }

//change values to be measured in cm
void loop() {
 i=analogRead(redpin);
 i= smoothreading(i,theta,smoothIR);
 i =  map(i,94,640,40,4);

 Serial.print ("Current Value:"); Serial.println (i);
 Serial.print ("Previous Value:"); Serial.println (smoothIR);

  
 
    smoothIR = i;
 
 
    delay(500);
   // val=(6762/(i-9))-4;
  
}
// Kalman Function
int smoothreading(int i_func, int theta_func, int smoothIR_func)
{
  float alpha = 0,x = 0;
  if( theta_func < 15)
  {
    alpha = 0.5;
  }
  else
  {
    alpha = 0.9;
  }
  x = i_func*alpha+(1-alpha)*smoothIR_func;
  Serial.print ("Value:"); Serial.println (i_func);
return x;

 
}