Using an Ultrasonic Sensor to Control a Servo Motor – YouTube
Explanation:
In this video I am demonstrating how an ultrasonic sensor can be used to control a servo motor. The way an ultrasonic sensor works is it emits ultrasonic (high frequency sound) waves. When being used, the speaker sends out these waves in a cone shape, the waves then reflect off of the surface of objects, and the time it takes to be received by the microphone on the sensor is how the distance is determined. The longer it takes to reflect back to the sensor, the further away the object, and vice versa. When an object is within a specific range of the sensor, the servo motor is then activated to turn 180 degrees, then when the object is out of range, the motor delays two seconds and goes back to its original position. This is due to the “if…else” statement in the code which allows for the motor action to be executed to any number of degrees if the sensor detects something in the given range.