Ultrasonic Sensor and Servo Control with Arduino
Components Needed
Arduino Uno
Ultrasonic Sensor HC-SR04
Servo Motor
Breadboard

the code is here
Here explain the working of this project
How the Circuit Works
Ultrasonic Sensor Measures Distance:
The Trigger Pin of the ultrasonic sensor is triggered by the Arduino to send out an ultrasonic pulse.
The sensor's Echo Pin receives the reflected pulse when it bounces back from an object.
The time it takes for the pulse to return is measured by the Arduino, and based on this, the distance to the object is calculated.
Distance Calculation:
The time taken for the sound wave to return (echo) is used to calculate the distance. The speed of sound in air is approximately 343 meters per second (or 0.0343 cm/μs).
The formula for calculating the distance is:
Distance
=
Time of flight
×
Speed of sound
2
Distance=
2
Time of flight×Speed of sound
The division by 2 is because the pulse travels to the object and back.
Servo Motor Movement Based on Distance:
Based on the calculated distance, the Arduino sends a signal to the Servo Motor to move to a specific angle.
step by step
- The Arduino triggers the ultrasonic sensor.
- The sensor emits an ultrasonic wave and measures the time it takes for the wave to return.
- The Arduino calculates the distance.
- Based on the distance, the Arduino controls the servo to position it at a specific angle.