3.7 Obstacle avoidance 2

In 3.5 Obstacle avoidance project, only 2 IR obstacle avoidance modules are used for obstacle avoidance, but the detection distance of IR obstacle avoidance module is short, which may make the car too late to avoid the obstacles.

In this project, we also add ultrasonic module to do some long-distance detection, so that the car can sense obstacles at a farther distance to make a judgment.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

3 in 1 Starter Kit

380+

3 in 1 Starter Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

SunFounder R3 Board

BUY

L298N Module

BUY

TT Motor

-

Ultrasonic Module

BUY

Obstacle Avoidance Module

BUY

Build the Circuit

Connect the ultrasonic module and the 2 IR obstacle avoidance modules at the same time.

Wire the ultrasonic to the R3 board as follows.

Ultrasonic Module

R3 Board

Vcc

5V

Trig

3

Echo

4

Gnd

GND

The wiring of the 2 IR obstacle avoidance modules to the R3 board is as follows.

Left IR Module

R3 Board

OUT

8

GND

GND

VCC

5V

Right IR Module

R3 Board

OUT

7

GND

GND

VCC

5V

../../_images/car_avoid_ultrasonic1.jpg

Programming

1. Create function

Make the car go forward and backward.

../../_images/7_avoid2_1.png

Make the car to go backward to the left and backward to the right.

../../_images/7_avoid2_2.png

Make the car stop.

../../_images/7_avoid2_3.png

2. Emergency obstacle avoidance

The 2 infrared obstacle avoidance modules on the car are used for emergency obstacle avoidance, detecting obstacles at short distances, corners or relatively small obstacles.

  • If the left infrared module detects an obstacle, the car backs up to the left.

  • If the right IR module detects an obstacle, the car recedes to the right rear.

  • If 2 modules detect the obstacle at the same time, the car goes backward directly.

../../_images/7_avoid2_4.png

3. Long range obstacle avoidance

Read the value of ultrasonic module, when the detected value is less than 10, the car will go backward; otherwise it keeps going forward.

../../_images/7_avoid2_5.png