Project tutorial
Ultrasonic Obstacle Avoiding Robot Using Evive

Ultrasonic Obstacle Avoiding Robot Using Evive © CC BY-SA

Unlike others, we have mounted our ultrasonic sensor on a servo.

  • 11,278 views
  • 0 comments
  • 14 respects

Components and supplies

Screen%20shot%202016 08 17%20at%2012.06.19%20pm
evive
×1
Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
Optional, if you use evive, the it has arduino MEGA 2560 R3 inside it.
×1
Servos (Tower Pro MG996R)
×1
Ultrasonic Distance Sensor
×1
DC motor (generic)
×2
Drv8711
Texas Instruments Motor Drivers
OPTIONAL: We can make a simple motor driver using SN754410NE or L293D (or any similar Dual channel H bridge) We have used evive, it has in-built motor driver using SN754410
×1
Battery 12V (generic)
×1
Robot Car Body (generic)
×1
Seven (or five) array IR Sensor
×1

Apps and online services

About this project

We have built an obstacle avoiding robot using evive. Unlike others, we have mounted our ultrasonic sensor on a servo. So after detecting an obstruction, the robot analyses which direction is the best to go using distance at various angles from the ultrasonic sensor.

Assembling the robot

First of all we will see the building part of it, then we will proceed to the coding part. You can see in the image what our robot looks like. This structure actually makes the work easier.

Please go through the very detailed tutorial on making the modular differential drive robot here.

All the CAD files can be downloaded from our GrabCAD profile.

Connections for Obstacle Avoidance Robot

We have three devices to be connected to the evive. To connect the two motors of the robot insert the wires of motors in the slot made in evive that are M1 and M2 in the correct orientation.

Now, we have to connect the servo motor to evive, in this we have not used the inbuilt servo pinouts because it uses the same pin as that of motor so instead we have used digital pin 9 for communication of servo and other power related pins to the Arduino for example VCC to 5 volt and GND to ground.

To connect the ultrasonic sensor just connect the VCC to 5 volt, GND to ground and for trig pin and echo pin we have used the digital pins 3 and 2 respectively. Please have a detailed look at the evive's schematic pinout diagram, so that you can easily connect motors and servos.

How Our Robot Senses Distances

We have mounted an ultrasonic sensor on top of servo. When the ultrasonic sensor is triggered, it sends out a pulse and simultaneously starts an internal clock. When the pulse hits an obstacle, it gets reflected back to the sensor. The sensor calculates the time difference between the sending and receiving of the pulse. Since the speed of the pulse in air (let it be 'v') and the time gap ('t') is known, the distance to the obstacle can be calculated as:

  • Time for total trip = t
  • Time for reaching the obstacle = t/2
  • distance = v*(t/2)

This value has been calculated in our code and can be stored and manipulated accordingly.

Finding the best direction in current situation

Normally, while moving forward, the ultrasonic sensor 'looks' in front, i.e. the sensor provides the Arduino the value of the nearest distance that an obstacle is present in front of it. As soon as this value becomes less than a minimum threshold, we stop the bot. Then, we turn the ultrasonic sensor, once to the left and then to the right.

Each time, we obtain the distance of the nearest obstacle in the respective direction. We store both of these values and calculate the maximum of these values. Then, we turn our bot in that particular direction. This is the optimum direction, where the bot can travel the farthest without needing to stop and check again.

The robot starts moving forward, until another obstacle comes in front of it.

Add libraries for Controlling Motor and Servo to Arduino IDE

Due to limitations of the present servo library, we cannot use the servo along with motor drivers. So we have modified the servo.cpp file in Arduino/Libraries/Servo. Download the Servo library code here and replace the original library in Arduino IDE using this.

NOTE: evive uses PWM Pins 44, 45 for motors and the same are used for servos, so you CANNOT use plug and play interface for servo motor. You will have to use any of the 3 to 13 pin for connecting the signal wire of servo. ALSO since default servo library uses TIMER 5 (aka PWM pins 44, 45) for controlling the servos. So please replace the default servo library in Arduino libraries using the attached file "Servo.rar". Please have a look at Schematic PinOut Diagram of evive here.

Now we need to include the motor library. Please find it here. It is very extensive in a way that it makes controlling motors very easy. Please look the motor.h for understanding the available functions in this library. Screenshots are provided for describing how to add a library to Arduino IDE.

Using the 1.8" SPI TFT screen programmed with Arduino for debugging

Evive also have inbuilt 1.8" SPI interfaced TFT screen (explore the details here). You can check the internal wiring for making/updating your Arduino sketches at this link. The following are the connections:

  • VCC to 3.3V
  • GND to evive's GND
  • CS to Arduino pin 48
  • RESET to Arduino pin 47
  • D/C (or A0) Arduino pin 49
  • SDA to MOSI (For Arduino Mega on Pin 51)
  • SCL (or SDA) to SCLK (or SCK) (For Arduino Mega on Pin 52)
  • LED (or LEDA) to 3.3V or as per brightness level required.

The most important thing is that while the robot moves, you can display and monitor the distance, PWM etc on the screen. Hence it reduces the dependence on Arduino Serial Monitor via using USB cable with your laptop or desktop. It makes the debugging process wire free.

Upload the Obstacle Avoidance Robot Code

We have made the Arduino IDE ready for our robot. Although its not necessary to use the motor library, then you can yourself do the pinMode settings and control the motor related pins yourself. So, its recommended to use the motor library.

Download the well documented codes from here to make your own obstacle avoidance robot.

Code

Modified Servo Library
In Arduino MEGA, default servo library uses TIMER 5 which are also linked on Pins 44, 45, 46. So for using Motors (on TIMER5, ie Pins 45, 45) and Servo on any Pin 2-13, we need to modify Servo Library.
Obstacle Avoidaning Robot Code
This link contains the folder for Arduino sketches and library used.

Schematics

Schematic Diagram
Connect motors, ultrasonic distance sensor, servo to evive
obstacleAvoidanceRobot.fzz

Comments

Similar projects you might like

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 11,827 views
  • 7 comments
  • 28 respects

How to Make Obstacle Avoiding Robot

Project tutorial by Darwin Dela Cruz

  • 25,343 views
  • 9 comments
  • 37 respects

Bluetooth Controlled & Obstacle Avoiding Arduino Robot

Project showcase by KureBas Robotics

  • 8,435 views
  • 11 comments
  • 20 respects

Ground-Based Obstacle Avoiding Robot

Project showcase by Xavier Tan

  • 5,312 views
  • 1 comment
  • 20 respects

Transformer's Baby: Arduino Avoiding Obstacle Robot

Project tutorial by diyProjectsStepByStep

  • 2,969 views
  • 0 comments
  • 13 respects

Robot for supercool indoor navigation

Project tutorial by Team oblu

  • 14,445 views
  • 9 comments
  • 45 respects
Add projectSign up / Login