When ultrasonic sensor read 5cm distance ore less servo will rotate in 120 degree else servo will rotate 0 degree arduino will print the distance on serial print.
Servo motor control using arduino and ultrasonic sensor.
Second part is the ultrasonic sensor third part is a servo motor.
Attach the ultrasonic sensor on the red strip on one side of the base using hot glue.
You can see the motor works differently based on the height that the sensor detects.
The connection is very simple.
Thus let s add them one after the other.
In this project you can see how can we control servo motor using arduino and ultrasonic sensor.
And attach the servo motor on the other side of the red strip using hot glue.
How the project work.
The ultrasonic vcc is connected to 5v the gnd to ground.
An ultrasonic sensor is a device that can measure the distance to an object by the use of sound waves while a servo motor is built for precision control of the angular or linear position velocity and acceleration.