My first robot I have programmed with NXC was the Explorer.
This robot's mission is to explore all around your room, house or wherever you set it loose. It tries to "see" walls and other obstacles before running into them. Then the robot turns it´s head to look left and right to determine which direction is the best to turn. In case it does accidentally run into something, a bumper in the front triggers a touch sensor to make the robot stop and then decide which way to turn.
An additional system writes the data comming from the ultrasonic sensor into a text file.
I copied the datas into a Excel spreadsheet. Then you could see a line chart which showes the outlines of the room.
Open with Notepad if you do not have BricxCC
Text Document [1.8 KB]
The blue line represents the wall recognized on the left side of the robot and the red line the right side. The unit on the y-axis is centimeter. The robot moves along the x-axis.
You can see that the measurement is very inaccurate.
The reason is that the motor does not align the ultrasonic sensor perpendicular to the wall.
There are also variations
to measure the distance with the ultrasonicsensor.