how to make arduino obstacle avoiding Car

0

Today in this article we are going to Make an Arduino obstacle avoiding Car with Arduino UNO, L293D Motor Driver, and Joystick Module. Here you will get Fully Detailed instructions for making an Arduino Arduino obstacle-avoiding Car. Codes are also Included.

I have tried to provide you all the must-have Circuit Schematics and Diagrams in this article. My intention was to give you all in one guide for making a joystick Car.

Joystick-controlled car is a motion-controlled car. Here, the Joystick can be used in two ways by using the button underneath the Joystick: By changing the Gear and moving the Joystick left, right, forward, and backward the car can be controlled accordingly.

If you want to make a School/ College project then this project is for you. You would not need any special knowledge for making the Arduino joystick control car. So, you should definitely try it.

WATCH YOUTUBE VIDEO

Watch the Full Video and you will understand everything. Next, follow the step by step guide below.

Making video of Arduino obstacle avoiding Car

COMPONENTS REQUIRED

Item Image

Item Name

Quantity

Shop Online

Plywood 16cm X10cm

1 No
Caster Wheels
1 No

Arduino UNO

1 No Order Now

L298N Motor Driver

1 NO Order Now

dc gear motor

2 no Order Now

Wheel

2 no Order Now

Servo motor
sg90

1 No Order Now

ultrasonic sensor
HC-SR04

1 No Order Now

Jumper wires

Enough Order Now

TOOLS REQUIRED

Tool Image

Tool Name

Shop Online

Gun gum

Order Now

Soldering rod with lead

Order Now

Screwdriver

Order Now

APPS AND ONLINE SERVICES

Arduino IDE

Download now

STEPS TO MAKING

I have divided the joystick control car into several steps. By this, you can understand the Arduino car more easily. Please don’t skip any step otherwise it will be difficult to replicate.

CIRCUIT DIAGRAM

Step 1:

First, you will need 2 gear Motors. Sometimes the motor doesn’t come with wire attached. So, In that case, you have to attach the wire to the motors with a soldering iron.

Step 2:

In the same way, I have connected wires with Motors. One suggestion to solder is that please don’t heat the motor terminals too much they will be damaged if you heat that too much. After that, I tested all the motors before connecting and it works just fine.

Step 3:

fix the 360-degree wheel to plywood with help of screws

Step 4:

Now take a Piece of Plywood dimension of 16CM x 10CM. Now use a Glue Gun and place the motor on the Plywood corners. Use the same technique and connect all 2 Motors on the chassis.

Step 5:

I have attached 2 motors in the Plywood. One suggestion to you is to align the motors. Otherwise, the motors will not go straight.

Step 6:

First, take Arduino Uno and attach it to the Chassis. Many people use Hot Glue to attach but I don’t recommend that at all. The coper traces under the PCB may be damaged by the hot glue. So, I used Double-sided tape for attaching the Board. For controlling the Motors we will definitely need a motor driver. The L298n and the L293D motor drivers are most commonly used with Arduino. All these drivers have an inbuilt H-Bridge inside in them for controlling the motors.

Step 7:

Here is the Left and the Right side view of the Car. You can see the connection more clearly here. If you change the motor wires then the motor rotation will also change. Just connect all the motors as shown in the picture and will work just fine.

Note:

Suppose you are powering a DC motor with a power source like 9V Battery. Just think that your motor is rotating in a certain direction. Now, If you change the connection (Suppose previously you connected Red Wire to the +ve and the Gray wire with the -ve of the battery. So, here changing connection means you have to connect the Red wire with the -ve and Gray wire with the +ve) then the motor will rotate in the opposite direction. This is the property of DC Motor. In this way, you can also check your DC Motor is working or not.

Step 8:

I have used 18650 Batteries for Joystick Control Car. You can also use Li-Po Batteries or Lead Acid Batteries as well. My recommendation is to go with Li-ion or Li-Po Battery because this is most commonly used in Projects. Nowadays you can get 18650 Batteries as cheap as 2$. And these batteries will give you the most power.

Connect the Battery wires with the EXT_PWR Terminal Block. The Battery Terminal block has a Switch inbuilt in it. It is used to turn On/ Off the car. I have attached Double-sided tape with the battery holder and connected it with the Chassis.

Note:

But one thing I should definitely mention is that Li Batteries are great for DIY Projects. But use with care. Charge with Dedicated chargers. Just being on the safe side you may use the TP4056 Li Charger module. And never ever Over-charge, Over-discharge, or short circuit these batteries. It may blast.

Step 09:

Connect the wires as per shown in the figure or table

wire connection between Arduino and motor driver

Motor Driver(L298n) Arduino UNO
IN 1 Pin 8
IN 2 Pin 9
IN 3 Pin 10
IN 4 Pin 11

Step 10:

Connect the wires as per the shown in the figure or table

wire connection between Arduino and Ultrasonic sensor

Ultrasonic sensor Arduino UNO
+5ve 5v
GND GND
VRx pin A0
VRy pin A1

Step 11:

Next, connect your Arduino with your PC or MAC. After that, we will dive into the software section.

Now, I have provided the code below. Just copy the code and paste it in your Arduino IDE. Before uploading the code to Arduino we need to add a library to Arduino. Just go to the following.

ARDUINO CODE

    
#include <Servo.h>          //Servo motor library. This is standard library
#include <NewPing.h>        //Ultrasonic sensor function library. You must install this library

//our L298N control pins
const int LeftMotorForward = 8;
const int LeftMotorBackward = 9;
const int RightMotorForward = 10;
const int RightMotorBackward = 11;

//sensor pins
#define trig_pin A1 //analog input 1
#define echo_pin A0 //analog input 2

#define maximum_distance 200
boolean goesForward = false;
int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function
Servo servo_motor; //our servo name


void setup(){

  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);
  
  servo_motor.attach(7); //our servo pin

  servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

  if (distance <= 20){
    moveStop();
    delay(300);
    moveBackward();
    delay(400);
    moveStop();
    delay(300);
    distanceRight = lookRight();
    delay(300);
    distanceLeft = lookLeft();
    delay(300);

    if (distance >= distanceLeft){
      turnRight();
      moveStop();
    }
    else{
      turnLeft();
      moveStop();
    }
  }
  else{
    moveForward(); 
  }
    distance = readPing();
}

int lookRight(){  
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

int lookLeft(){
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=250;
  }
  return cm;
}

void moveStop(){
  
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(LeftMotorBackward, LOW);
}

void moveForward(){

  if(!goesForward){

    goesForward=true;
    
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(RightMotorForward, HIGH);
  
    digitalWrite(LeftMotorBackward, LOW);
    digitalWrite(RightMotorBackward, LOW); 
  }
}

void moveBackward(){

  goesForward=false;

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
}

void turnRight(){

  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
 
  
  
}

void turnLeft(){

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);

  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}
    
    

Step 12:

Now choose the Board as Arduino Uno and Choose the right COM port. Next compile the code first and then Upload the code to Arduino.

Step 13:

Now I attached the 18650 Batteries in the 18650 Battery Holder. Before powering the car just check all the necessary connections like Battery Power +ve and -ve is connected or not, joystick modules Polarity is right or different. A simple mistake can lead you to damage any modules. And turned on the Switch. Here you will see the L293D Motor Driver’s Green LED glow after turning it on.

Step 14:

Now you will need the joystick for controlling the car.

Output Video

I hope this step by step guide will help you for making the Arduino Joystick control car with L293D whether you are a Beginner or it is your first-ever Arduino project. All components link are included with proper pricing. Hope this helps. If you have any queries or any suggestions then don’t forget to mention that into the comment section. I will definitely try to help you. Moreover, you can subscribe to our Youtube channel Electromechanics for more amazing content like this.

Thank you

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !