Obstacle Avoiding Robot Using Ultrasonic Sensors




About: Passion and love for working with Industrial Automation, Innovation, Electronics, Robotics, Biomechatronics and Artificial Intelligence.

This is a simple project about Obstacle Avoiding Robot using Ultrasonic sensors(HC SR 04) and Arduino Uno board.Robot moves avoiding obstacles and choosing the best way to follow by sensors.And please notice that is not a tutorial project, share your knowledge and comments with me.

List of Main Components :-

  • Arduino Uno - 1
  • Ultrasonic Sensor (HC SR 04) - 3
  • 5v Relay Board - 1
  • 12 V Battery - 1
  • 12 V Gear Motor - 4
  • Motor Brackets - 4
  • Chasi - 1
  • Wheels - 4
  • Screws and nuts
  • Switch -1
  • Jumper Cables -10

Step 1: Arduino Uno Board

Arduino Uno is a micro controller board based on the ATmega328P. It has 14 digital input and output pins, 6 analog inputs.Operating Voltage is 5 V with external power supply.There are many advantages,easy to coding and uploading,easy to error corrections,available different sensors and other devices,can be used for led control,motor control and any other devices.

When give power supply to Arduino board,use 5 volt or 9 volt battery.But do not use 12 volt directly to Arduino. If has to use 12v battery,give it through 5v regulator circuit.

Step 2: Ultrasonic Sensor (HC SR 04)

The robot has three Ultrasonic Sensors where are front,left and right.Robot works according to these sensors.An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves.There are four pins which are VCC (5v power supply),GND (Ground),Trig and echo.There are two transducers ,one for Transmit & the other for Receive.Both are fixed on a single PCB with control circuit.Ultrasonic distance measurements from about 2 cm to 400 cm. Also is a high frequency sound of frequency 40 KHz.

Principle of Operation

From Arduino generate a short 20 uS pulse to the Trigger input to start the ranging.The Ultrasonic Module will send out an 8 cycle burst of ultrasound at 40 khz and raise its echo line high.

It then listens for an echo, and as soon as it detects one it lowers the echo line again. The echo line is therefore a pulse whose width is proportional to the distance to the object.

By timing the pulse it is possible to calculate the range in inches/centimeters.

The module provides an echo pulse proportional to distance.

uS/58=cm or uS/148=inches.

Step 3: Other Components

Available different sizes in motors shaft diameter (4 mm,6 mm).Make sure which size you need.

Jumper Cable should be Male to Female and Male to Male.

Step 4: Sensors With Arduino Connection Diagram

Front Sensor :-

Echo pin - Arduino pin 6

Trig pin - Arduino pin 7

VCC pin - 5V

GND - ground

Left Sensor :-
Echo pin - Arduino pin 8

Trig pin - Arduino pin 9

VCC pin - 5V
GND - ground

Right Sensor :-
Echo pin - Arduino pin 10

Trig pin - Arduino pin 11

VCC pin - 5V
GND - ground

Step 5: Relay Board With Arduino Connection Diagram

Relay pin 1 - Arduino pin 2.

Relay pin 2 - Arduino pin 3.

Relay pin 3 - Arduino pin 4.

Relay pin 4 - Arduino pin 5.

Step 6: 12 Volt and Relay Connection

NC - Normal Closed

NO - Normal Open

C - Common

Here you can change polarity,if you need.According to that, motor rotating direction will change.

Motors should be connected to the common pins.

Step 7: Assembling

Left side and right side motors should be separated from each sides.Front side motors are parallel with back side motors.

Step 8: Codes

Step 9: Testing and Finishing



    • Epilog X Contest

      Epilog X Contest
    • PCB Contest

      PCB Contest
    • Safe and Secure Challenge

      Safe and Secure Challenge

    9 Discussions


    1 year ago

    your code doesnt match the wiring you done also the code mention two ENA,ENB which you never mentioned ?

    4 replies

    Reply 4 months ago

    Hi dude,

    Better not to by heart wiring etc,please use your skills.I have checked several times before upload it.



    Reply 10 months ago

    I don't know the wiring etc.. But I know that the logic he used the file attaches, can't do the work that robot is performing in the video.


    Reply 4 months ago

    Thanks for commenting,I think you can understand video is a demonstration for getting simple idea.


    Where I have kept objects and your objects, robot...,obviously it does not work same in video.But robot function is same.

    Also, better not to by heart the video and wiring etc,please use your skills.Because I check more times and did upload it.



    Reply 1 year ago

    Thanks for your comment.This is the same codes that i did.You can check it.

    And i did not use any ena or enb.