How to Make Arduino Obstacle Avoiding Robot Car With Radar

by RonFrtek in Circuits > Arduino

2347 Views, 5 Favorites, 0 Comments

How to Make Arduino Obstacle Avoiding Robot Car With Radar

Arduino Obstacle Avoidance Smart Robot Car with Radar - Simple Tutorial

In this tutorial we are going to make an Arduino Obstacle Avoiding Robot Car with Radar using the HC-SR04 ultrasonic sensor attached to the servo motor.

Why is this project better than all the other "Obstacle Avoiding Car" projects out there, because most Projects out there only detects the Obstacle in the front and the then servo checks on the left or the right and decides where the Robot should go, so no real time detection on all angles.

On this Robot Car the servo rotates the ultrasonic all the time from the left side to the right side just like a radar does it, and as soon as the Obstacle is detected on any point the reverse direction is triggered and the direction of the travel is changed.

The Angle of the "Radar"detection can be adjusted and the distance of the detection can be adjusted as well.

Special Thank you! goes to Akis for giving the Idea, you can check his Youtube channel here: Akis Kot

And also a Special Thank you! goes to user Jim Ryan for helping me with the project, You can find his amazing Projects & Tutorials here: Jim Ryan Youtube Videos

What You Will Need

smart-car-chassis-4wd-racing-car-robot-car-chassis-wheels-motors-32482971681004_800x.jpg
ultrasonic-sensor-hc-sr04-500x500.jpg
HTB1TMikbyjrK1RjSsplq6xHmVXa3.jpg
Ultrasonic sensor (HC- SR04)-bracket.jpg
VisuinoAdvrtisementElegooV4.jpg
336-3361370_arduino-uno-r3-png-png-download-arduino-uno.png
FEGPLRJKK5FQW91.jpg
  • Arduino UNO (or any other board)
  • Smart Car Chassis 4WD
  • L298N DC MOTOR CONTROLER
  • Ultrasonic sensor (HC- SR04)
  • Servo motor
  • Ultrasonic sensor (HC- SR04) bracket servo mounted - 3DPrinted part Download here
    If you do not have a bracket you can find some other way to attach the sensor to the servo motor, perhaps some glue,etc
  • Jumper wires
  • Visuino program: Download Visuino

The Circuit

2022-01-26_16-57-00.jpg
  • Connect Power supply (batteries) pin (gnd) to motor driver controler pin (gnd)
  • Connect Power supply (batteries) pin (+) to motor driver controler pin (+)
  • Connect Power supply (batteries) pin (+) to Arduino pin (VIN)
  • Connect GND from Arduino to motor driver controler pin (gnd)
  • Connect digital pin(6) from Arduino to motor driver pin (IN1)
  • Connect digital pin(8) from Arduino to motor driver pin (IN2)
  • Connect digital pin(10) from Arduino to motor driver pin (IN3)
  • Connect digital pin(11) from Arduino to motor driver pin (IN4)
  • Connect DC motors (on the right side of the robot) to one side of motor driver
  • Connect DC motor (on the left side of the robot) to other side of motor driver
  • Connect Ultrasonic module pin (VCC) to Arduino pin [+5V]
  • Connect Ultrasonic module pin (GND) to Arduino pin [GND]
  • Connect Ultrasonic module pin (ECHO) to Arduino pin digital (4)
  • Connect Ultrasonic module pin (TRIG) to Arduino pin digital (3)
  • Connect Servo motor "Orange" (signal) pin to Arduino Digital pin[2]
  • Connect Servo motor "Red" pin to Arduino positive pin[5V]
  • Connect Servo motor "Brown" pin to Arduino negative pin[GND]

Start Visuino, and Select the Arduino UNO Board Type

FMW5CHBKFV47BP9.jpg
Visuino-Select-Board-UNO.jpg

The Visuino: https://www.visuino.eu needs to be installed. Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add Components

2022-01-26_17-36-50.jpg
2022-01-26_17-39-38.jpg
2022-01-26_17-46-01.jpg
2022-01-26_17-40-23.jpg
2022-01-26_17-41-37.jpg
2022-01-26_17-42-28.jpg
2022-01-26_17-43-26.jpg
2022-01-26_17-44-19.jpg
2022-01-26_17-45-07.jpg
2022-01-26_17-47-05.jpg
  • Add "Clock Generator" component
  • Add "Sine Analog Generator"component
  • Add "Ultrasonic Ranger" component
  • Add "Servo" component
  • Add "Compare Analog Value" component
  • Add "Analog Value" component
  • Add "Timer" component
  • Add "Inverter" component
  • Add 2X "Speed and Direction To Speed" component
  • Add "L298N" component

In Visuino Set Components

2022-01-26_17-50-44.jpg
2022-01-26_17-51-50.jpg
2022-01-26_17-55-45.jpg
2022-01-26_17-59-51.jpg
2022-01-26_18-02-42.jpg
2022-01-26_18-02-54.jpg
  • Select "ClockGenerator1" and in the Properties window set "Frequency" to 70
This means how fas will the servo motor move (You can adjust the number)
  • Select "SineAnalogGenerator1" and in the Properties window set "Amplitude" to 0.3

This means ho far to the left or right the servo will rotate.(You can adjust the number)

  • Select "CompareValue1" and in the Properties window select "Compare Type" ctSmallerOrEqual and set "Value" to 30 (You can adjust the number)

This means that at the distance of 30cm or less the Robot car will reverse (You can adjust the number)

  • Select "AnalogValue1" and in the Properties window set "Value" to 0.9

This will be the Default Speed of the Robot Car You can set it to less or to 1 to have a Full Speed

  • Select "SpeedAndDirectionToSpeed1" and in the Properties window set "Initial Reverse" to True
This will reverse the Start Direction, Depending on your motor wiring, you can leave this to False
  • Select "SpeedAndDirectionToSpeed2" and in the Properties window set "Initial Reverse" to True"
    This will reverse the Start Direction, Depending on your motor wiring, you can leave this to False

In Visuino Connect Components

2022-01-26_20-11-14.jpg
2022-01-26_20-11-35.jpg
4wd-car.png
  • Connect "ClockGenerator1" pin [Out] to "ClockGenerator1" pin [Clock]
  • Connect "ClockGenerator1" pin [Out] to "SineAnalogGenerator1" pin [Clock]
  • Connect "SineAnalogGenerator1" pin [Out] to "Servo1" pin [In]
  • Connect "Servo1" pin[Out] to Arduino board digital pin [2]
  • Connect Arduino board digital Out pin [4] to "UltrasonicRanger1" pin [Echo]
  • Connect "UltrasonicRanger1" pin [Trigger] to Arduino board digital pin [3]
  • Connect "UltrasonicRanger1" pin [Out] to "CompareValue1" pin [In]
  • Connect "CompareValue1" pin [Out] to "Timer1" pin [Start]
  • Connect "Timer1" pin [Out] to "Inverter1" pin [In]
  • Connect "Inverter1" pin [Out] to "SpeedAndDirectionToSpeed2" pin [Reverse]
  • Connect "IAnalogValue1" pin [Out] to "SpeedAndDirectionToSpeed1" pin [Speed]
  • Connect "IAnalogValue1" pin [Out] to "SpeedAndDirectionToSpeed2" pin [Speed]
  • Connect "SpeedAndDirectionToSpeed1" pin [Out] to "DualMotorDriver1" "Motor0" pin [In]
  • Connect "SpeedAndDirectionToSpeed2" pin [Out] to "DualMotorDriver1" "Motor1" pin [In]
  • Connect "DualMotorDriver1" "Motor0" pin [Direction B] to Arduino board digital pin [6]
  • Connect "DualMotorDriver1" "Motor0" pin [Speed A] to Arduino board Analog(PWM) pin [8]
  • Connect "DualMotorDriver1" "Motor1" pin [Speed A] to Arduino board Analog(PWM) pin [11]
  • Connect "DualMotorDriver1" "Motor1" pin [Direction B] to Arduino board digital pin [10]

Generate, Compile, and Upload the Arduino Code

Visuino-Compile-UNO.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Robot car & the Arduino module, the car wheels will start to spin and the servo motor will start to rotate the ultrasonic sensor. Once the sensor detects the obstacle the wheels will start to spin in reverse to avoid the obstacle.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project file, that I created for this Tutorial, you can download it and open it in Visuino: https://www.visuino.eu

Video

Arduino Obstacle Avoidance Smart Robot Car with Radar