     irSensorVal = irSensorVal*10;
 
     irSensorVal = map(irSensorVal, irBase, irMax, 0, 1000);
+
+    if(irSensorVal > 1000){
+      irSensorVal = 1000;
+    }
     
 }
 


  unsigned long thisTime= millis();
  
  if( thisTime >= lastTime + timeDelta){
    Serial.print(thisTime);
    Serial.println("BINGO");
    
    lastTime=thisTime;
    
  }
  
  readIR();


  if( irSensorVal >= (t1 + irDelta) ){
    switchState();
  }

  if(irSensorVal <  (t1 + irDelta) ){
     readyForChange=1; 
  }


  
  if(state == 1){
    analogWrite(pwmOut,200);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255  
  }else if(state == 0){
    analogWrite(pwmOut,0);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255  



   Serial.print("STATE: ");
   Serial.print(state);
   
   Serial.print("   HAND: ");
   Serial.print(handposition);


  Serial.print("   IR Val:"); 
