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

float irSensorVal=0;

int irDelta=100;
int irBase=20;
int irMax=230;


int t1=0;
int t2=0;

int state=0; // 0= off, 1 = on
int readyForChange=1;


int pwmOut=9;

unsigned long lastTime;
int timeDelta=50;


void switchState(){


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


  Serial.print("   IR Val:"); 
