Ultrasonic Sensor: Obstacles and Navigation


Our robot also has an ultrasonic sensor for detecting obstacles. This will allow us to use this as feedback for navigation. To prepare for this lab, you were asked to do some background research on the HC-SR04 ultrasonic sensor. The goal was to understand how the sensor works and coding basics needed to program a solution to the more complex navigation challenge that will provided for you. The program below triggers the ultrasonic pin by sending a HIGH signal for 10 microseconds and then uses pulseIn to get the time in microseconds it took for the echo to be sent and then received back to the sensor. The program also uses the Serial to output that duration in microseconds.