Created a finite state machine for sonar readings.