Line follow robot car with Arduino UNO, L298N driver, infrared sensor

Line follow robot car with Arduino UNO, L298N driver, infrared sensor

original

some robot making projects

Line following robot is simple

'Arduino

Make an Arduino Line Follower Robot Car Using Arduino UNO, L298N Motor Driver, Infrared Sensor

Shows how to make a line following robot car using an Arduino UNO and 2 IR sensor modules . The Line follower designation indicates a fully autonomous vehicle . This follows the visual lines embedded in any floor or on any surface (most likely white or black).

This project is based on an Arduino microcontroller. is a basic line follow robot project .

Arduino Line Following Robot Using IR Sensor, Arduino Uno and L298N Motor Driver

How does the robot car work?

An infrared sensor senses if the line color is reflective. Reflection here means that the surface sends light back. In this case, the reflective surface is a white surface. (**Non-reflective surfaces are just black lines.** This means the black track does not reflect any light. The IR sensor works in that it senses if any reflected light returns. The sensor then gives an output. If there is no reflection, Then the IR sensor will not provide any output, or in other words, the output will be low.

Based on this high output and low output result, the microcontroller can control the car.

The microcontroller gives the direction to the car, then when to turn (left or right) and where to stop, if the 2 sensors get a black surface then it tells the microcontroller to stop the car.

Arduino wires to follow what the robot car needs

Amazon.com link

  • infrared sensor

  • Arduino UNO R3

  • L298N Motor Driver

  • TT geared motor

  • Jumper

  • 18650 battery

  • 2S, 18650 battery holder

  • 65MM motor hub

Popular categories:

  1. circuit
  2. Arduino project
  3. Independent research and development projects

Schematic of the Arduino Line Follower Robot Car:

[ Arduino Line Following Robot with IR Sensor, Arduino Uno and L298N Motor Driver](data:image/svg+xml, Arduino line following robot with infrared sensor, Arduino Uno and L298N motor driver

Steps to make a car:

step 1:

First, we need a piece of wood for the chassis of the car. Here I am using 13CM x 10CM plywood for the chassis of the car. You can also use an acrylic sheet or a prefabricated chassis.

[img](data:image/svg+xml,

Step 2:

Now mount the motor on the 4 corners of the plywood with a glue gun or any other glue. Make sure that when installing the motor, the motor placement should be correct. Otherwise, the car will not be able to go straight.

[img](data:image/svg+xml,

Step 3:

Now connect the TT gear motor as shown below. We will connect the motors in a cross pattern. This is because we have to make the car build the car in such a way that the two side motors spin in the same direction for forwards backwards and other known directions.

[img](data:image/svg+xml,

Step 4:

With the motor connected, the connections should look like this. Here I've provided a picture of both sides to give you a clear idea of ​​what's going on.

[img](data:image/svg+xml,

Step 5:

Here we are using L298N motor driver. I used double sided tape to attach the L298N motor driver to the plywood. You can also use nuts and bolts for this.

[img](data:image/svg+xml,

Step 6:

Now connect the motor wires with the L298N motor driver. Then tighten the motor driver wires. And avoid loose connections of any kind.

[img](data:image/svg+xml,

Once connected, all wires will look like this.

**Note:** After uploading the code, if the car is not going in the correct direction or in the wrong direction, then just replace the motor wires. It will work fine.

[img](data:image/svg+xml,

Step 7:

For the batteries, I'm using 2, 18650 cells. This is very useful for building this type of car. For connecting the battery I am using a 2s 18650 battery holder. I also added a switch.

[img](data:image/svg+xml,

The battery wires will be connected with the motor driver input wires. You can also clearly see where to connect the battery wires.

Step 8:

In this project, I am using Arduino Uno as microcontroller. You can also use any other microcontroller if you want.

[img](data:image/svg+xml,

Next, you have to remove the jumper shorting the connector from the motor driver to make the next connection.

Step 9:

In the picture I have mentioned the necessary connections for the motor driver.

[img](data:image/svg+xml,

Arduino Uno L298N Motor Driver
Pin 10 This one
Pin 9 IN1
Pin 8 IN2
Pin 7 IN3
Pin 6 IN4
Pin 5 ENB

Step 10:

Connect the IR sensor as shown in the photo. Then connect the necessary wires with the Arduino UNO. Just follow the wiring diagram in the schematic.

Now upload the code to Arduino. Now we have to calibrate the running car.

[img](data:image/svg+xml,

Step 11:

Connect the battery to the car and turn on the switch.

[img](data:image/svg+xml,

Step 12: (Sensor Calibration) *** IMPORTANT ***

Before calibrating, you must attach the wheel to the car. You don't need to open the serial monitor to calibrate. This is just a manual calibration. Here I use the number read function to differentiate between light and dark . So the IR sensor will only provide high/low as output.

[img](data:image/svg+xml,

Leave the car in the air. Here I use the painted roof to put the car on for calibration. Here I use a white surface coupling with T-shaped wires for calibration. (black electrical tape)

[img](data:image/svg+xml,

Place the car as shown. Now you are ready to calibrate. First turn the 2 potentiometers (left and right sensor) fully counterclockwise.

[img](data:image/svg+xml,

  • Now slowly turn the potentiometers one by one clockwise until the LED of the IR sensor lights up.
  • Next, slowly move the car left and right so that the car left and right sensors will be on the black line. The wheels then spin in different directions.
  • More specifically, if you put the left sensor on the black line, the car will try to move in the correct direction. Likewise, if the right sensor is dark, the car is moving in the left direction.
  • This is due to keeping the car on the black line. A key feature of this configuration is that you cannot go too fast in this configuration. As a beginner project, this is great.

[[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-tf5e6hlP-1678587460475)(https://circuitbest.com/wp-content/uploads/2020/11/ 3.gif)]](data:image/svg+xml,

So in this case the calibration process will be a little easier. Now you can turn on the car and place where you want it to follow and the car will follow the line.

Arduino line follower car code:

/*
Description: This program is used to make Arduino Line Follower Robot Car.
Note: You can use any value between 0 to 255 for M1_Speed, M2_Speed, LeftRotationSpeed, RightRotationSpeed.
Here 0 means Low Speed and 255 is for High Speed.
*/

#define in1 9
#define in2 8
#define in3 7
#define in4 6
#define enA 10
#define enB 5


int M1_Speed = 80;             // speed of motor 1
int M2_Speed = 80;             // speed of motor 2
int LeftRotationSpeed = 250;   // Left Rotation Speed
int RightRotationSpeed = 250;  // Right Rotation Speed


void setup() {

  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);

  pinMode(A0, INPUT);  // initialize Left sensor as an input
  pinMode(A1, INPUT);  // initialize Right sensor as an input
}

void loop() {

  int LEFT_SENSOR = digitalRead(A0);
  int RIGHT_SENSOR = digitalRead(A1);

  if (RIGHT_SENSOR == 0 && LEFT_SENSOR == 0) {
    forward();  //FORWARD
  }

  else if (RIGHT_SENSOR == 0 && LEFT_SENSOR == 1) {
    right();  //Move Right
  }

  else if (RIGHT_SENSOR == 1 && LEFT_SENSOR == 0) {
    left();  //Move Left
  }

  else if (RIGHT_SENSOR == 1 && LEFT_SENSOR == 1) {
    Stop();  //STOP
  }
}



void forward() {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  analogWrite(enA, M1_Speed);
  analogWrite(enB, M2_Speed);
}

void backward() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);

  analogWrite(enA, M1_Speed);
  analogWrite(enB, M2_Speed);
}

void right() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  analogWrite(enA, LeftRotationSpeed);
  analogWrite(enB, RightRotationSpeed);
}

void left() {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);

  analogWrite(enA, LeftRotationSpeed);
  analogWrite(enB, RightRotationSpeed);
}

void Stop() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

download

If the car is not going in the correct direction, here are some simple troubleshooting steps:

If this happens and your car isn't going in the correct direction, you don't have to modify any code. You just need to replace the motor driver wire. Now your car will be heading in the correct direction.

[ img](data:image/svg+xml, line follower car demo

Simplified PCB:

I also created a simplified PCB for the line following robot car, which you can order from PCB fabrication company PCBWay . It will give the car a more professional look.

[ img](data:image/svg+xml, I designed the schematic in EasyEDA.

Provide all the necessary connections for the car such as power input, L298N motor driver pinout, left IR sensor and right IR sensor pinout.

[ img](data:image/svg+xml, PCB layout

Here, I have used Atmega328P microcontroller. This IC is also used in Arduino Uno R3. So we will program the Arduino UNO R3 and take the chip from the UNO board and place it on the PCB. This will keep the exterior of the car minimal.

[ img](data:image/svg+xml, 3D view of printed circuit board

How to order printed circuit boards?

PCB Gerber Link: Download

in conclusion:

All in all, it's a great car for the amateur. The speed of the car is too low to follow the line efficiently. If you want to accelerate the car, then you can use an infrared array.

I also provided in the code how to accelerate the car while rotating in a straight line and angle. Just change the speed parameter according to your car. Don't overdo the speed parameter, or the car won't be able to make any quick spins.

You can also read other Arduino project articles.

Guess you like

Origin blog.csdn.net/acktomas/article/details/129472787