Things You'll Need
Instructions
Use single-core or multi-core wire to connect the ultrasonic range finder's pins to the microcontroller controlling the robot. The pins are the metal pieces protruding from the sensor. Connect them to the voltage output, ground and input terminals on the microcontroller. If you don't know which pins to use on the sensor, look at its datasheet to determine which pin is which.
Connect the microcontroller to the computer with a compatible computer cable, so you can modify its program.
Launch the microcontoller's programming software on the computer.
Write code to create a variable called "sonicReading." The variable stores incoming data from the ultrasonic range finder in the microcontroller's program.
Write code to set the pin connected to the ultrasonic range finder's output as an input. This allows the microcontroller to read the data coming from the ultrasonic range finder.
Write code that reads the data from the microcontroller's input that's connected to the ultrasonic range finder, and stores the data in the variable called "sonicReading."
Write statements, such as "if" and "else if" statements, that modify the robot's movements based on the data stored in "sonicReading." For example, if the value stored in "sonicReading" indicates an object is nearby, tell the robot to turn, reverse or stop, else if the value indicates no objects are nearby, tell the robot to continue moving along its path.
Upload the code to the microcontroller.
Disconnect the microcontroller from the computer.