factor out ultrasonic range sensor code