The ultrasonic sensor

The ultrasonic sensor looks like a pair of eyes and sends out a signal from one side that rebounds and is received by the other side using the amount of time it takes to calculate the distance to an object. Smooth, hard objects are the easiest to sense.

Type in this program to use the ultrasonic sensor as a tool to calculate the distance to obejcts around the room and discover its range and accuracy. Be sure the sensor is plugged into port 1 or change the port number in the line that creates the UltrasonicSensor object..

code for sensor test

The next program uses the ultrasonic sensor and motors.

code for ultrasonic