Ultrasonic Sensor Based Car (Obstruction Detector)
Automated Obstacle Detection and Avoidance Vehicle Using Ultrasonic Sensor and Servo Motor
9/22/20262 min read
Arduino, based on the ATmega328P, is an "easy to program & use" multi controller. It can be programmed using the Arduino IDE by connecting a cable to the board from any laptop with the IDE installed. To make an automated obstruction detection vehicle, the parts required are:
Arduino Uno R3
BO Motors ( 2 or 4 according to the chassis)
Car Chassis & wheels
Jumper Wire
Ultrasonic Sensor ( HC - SR 04)
Servo Motor ( SG 90)
Preferably Li Battery ( 2 each of 3.7 V) for powering Arduino
Motor Driver ( L298N) [ L293D should also work but 298N has a wider operating voltage and heat sink].
Ultrasonic Sensor holder/Bracket
The car needs to be assembled with the motors connected to the wheels and the Arduino neatly placed on the car body. The circuit diagram is shown in the image. The Li battery unit should be used to power the Motor Driver, which in turn powers the Arduino. The Arduino 5 V and 3 V pins should be connected to VCC of the Ultrasonic sensor and the Positive ( Red) wire of Servo Motor respectively. The ground pins connected between Arduino and the Sensor & Servo complete the power supplies within the circuit.
Ultrasonic sensors emit sound waves at a frequency (> 20 KHz) above the human listening range which is between 20 & 20,000 Hz. The TRIGGER PIN emits the sound wave and when it hits an obstacle & comes back, the ECHO PIN listens to it/receives it. The ECHO Pin remains in HIGH State from the time the sound is emitted till its received. Thus the distance can be calculated using the basic formula, Distance=Speed * time.


In this case, speed is the sound of speed which is known ( 0.034 cm/μs). As the wave goes till the obstacle and comes back, it covers double the distance and the final figure needs to be divided by 2. Rather the equation used is 0.01723 * time. The pulseIn( ECHO, HIGH) function returns the time period during which the ECHO Pin was HIGH in microseconds. Thus by deriving the distance between the vehicle and the obstacle, the Servo motor is moved to the desired angles by using the servo.write (angle) functions. The ultrasonic sensor mounted on the servo then scans the vicinity and detects obstacles and the vehicle is set in motion in the desired directions based on the distance range. The servo movements and the distance ranges can be modified to suit the specific use case. The vehicle works based on the combination of the sensor response which drives the servo if required, which in turn controls the vehicle through motors connected to wheels. The Motor Driver H Bridge circuit is used to move and steer the vehicle in the desired directions. The key factors are the way the sensor is mounted and the angles/distance used in the code to control the vehicle.
