updated code to autocalibrate sensor