This psuedo code illustrates a routine for performing action based on sensor readings utilizing hysteresis to prevent jumping around of values This code is un-tested and imperfect in many ways, it is provided to give a starting point for writing ADC functions utilizing hysteresis Please let me know if you have better methods for doing similar work or if this proves not to work Some Variables: currentMovingDirection = 0 (this would be -1 for down and +1 for up) lastMovingDirection = 0 (same) lastADCPinValue = 0 jumpAmount = 0 initialCalibrationTime = 5 startTime = Get Current Time Function lowValue = Get Current ADC Pin Value Function highValue = Get Current ADC Pin Value Function Initial Calibration Routine: while (currentTime - startTime < initialCalibrationTime) { currentADCPinValue = Get Current ADC Pin Value Function if (currentADCPinValue < lowValue) { lowValue = currentADCPinValue } else if (currentADCPinValue > highValue) { highValue = currentADCPinValue } jumpAmount = highValue - lowValue } Utilizing The Calibration: while (true) { currentADCPinValue = Get Current ADC Pin Value Function if (currentADCPinValue > lastADCPinValue) { currentMovingDirection = 1 } else if (currentADCPinValue < lastADCPinValue) { currentMovingDirection = -1 } else { currentMovingDirection = 0 } if (currentMovingDirection == lastMovingDirection) { realADCPinValue = currentADCPinValue lastADCPinValue = currentADCPinValue } else if (currentMovingDirection = -1 and currentADCPinValue < lastADCPinValue - jumpAmount) { realADCPinValue = currentADCPinValue lastADCPinValue = currentADCPinValue } else if (currentMovingDirection = 1 and currentADCPinValue > lastADCPinValue + jumpAmount) { realADCPinValue = currentADCPinValue lastADCPinValue = currentADCPinValue } else { Don't Move } }