Raspberry Pi Based Obstacle Avoiding Robot using Ultrasonic Sensor

Robots are machines which reduce the human efforts in heavy works by automating the tasks in industries, factories, hospitals etc. Most of the robots are run by using some control unit or components like a push button, remote, joystick, PC, gestures and by executing some command by using controller or processor. But today we are here with a Automatic Robot which moves autonomously without any external events avoiding all the obstacle in its path, yes we talking about Obstacle Avoiding Robot. In this project, we have used Raspberry Pi and Motor driver to drive the robot and Ultrasonic sensor for detecting objects in the path of Robot.

Previously we have covered many useful Robots, you can find them in our Robotics projects section.

raspberry pi based obstacle avoiding robot using ultrasonic sensor
Raspberry Pi Obstacle Avoiding Robot using Ultrasonic Sensor

Components Required:

  • Raspberry Pi
  • Ultrasonic Sensor Module HC-SR04
  • ROBOT Chassis complete with screw
  • DC Motors
  • L293D IC
  • Wheels
  • Bread Board
  • Resistor (1k)
  • Capacitor (100nF)
  • Connecting wires
  • Power supply or Power bank

Ultrasonic Sensor Module:

An Obstacle Avoider Robot is an Automated Robot and it doesn’t need to be controlled using any remote. These types of automated robots have some ‘sixth sense’ sensors like obstacle detectors, sound detector, heat detector or metal detectors. Here we have done Obstacle Detection using Ultrasound Signals. For this purpose, we have used Ultrasonic Sensor Module.

Ultrasonic Sensors are commonly used to detect objects and determine the distance of the obstacle from the sensor. This is a great tool to measure the distance without any physical contact, like as Water Level Measurement in tank, distance measurement , Obstacle avoider robot etc. So here, we have detected the object and measured the distance by using Ultrasonic Sensor and Raspberry Pi.

Ultrasonic sensor HC-SR04 is used to measure distance in the range of 2cm-400cm with an accuracy of 3mm. The sensor module consists of an ultrasonic transmitter, receiver, and the control circuit. Ultrasonic Sensor consists of two circular eyes out of which one is used to transmit the ultrasonic wave and the other to receive it.

We can calculate the distance of the object based on the time taken by ultrasonic wave to return back to the sensor. Since the time and speed of sound is known we can calculate the distance by the following formulae.

  • Distance= (Time x Speed of Sound in Air (343 m/s))/2.

The value is divided by two since the wave travels forward and backward covering the same distance.Thus the time to reach obstacle is just half the total time taken.

So we have calculated the distance (in centimetre) from the obstacle like below:

  pulse_start = time.time()
  while GPIO.input(ECHO)==1:
      #Check whether the ECHO is HIGH
       GPIO.output(led, False) 
  pulse_end = time.time()
  pulse_duration = pulse_end - pulse_start
  distance = pulse_duration * 17150
  distance = round(distance,2)

Where pulse_duration is the time between sending and receiving ultrasonic signal.

Circuit Explanation:

Circuit is very simple for this Obstacle Avoiding Robot using Raspberry Pi. An Ultrasonic Sensor module, used for detecting objects, is connected at GPIO pin 17 and 27 of Raspberry Pi. A Motor Driver IC L293D is connected to Raspberry Pi 3 for driving robot’s motors. Motor driver’s input pins 2, 7, 10 and 15 are connected to Raspberry Pi GPIO pin number 12, 16, 20 and 21 respectively. Here we have used two DC motors to drive the robot in which one motor is connected to the output pin 3 & 6 of motor driver IC and another motor is connected at Pin 11 & 14 of motor driver IC.

schematic raspberry pi based obstacle avoiding robot using ultrasonic sensor

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top