Line Following Bot

by fenilchandarana in Circuits > Arduino

1815 Views, 19 Favorites, 0 Comments

Line Following Bot

IMG20230301210910.jpg

This is a bot that follows black line. My goal was to make it as compact as possible and to use Infrared LEDs instead of Infrared modules. I have used BO motors, Arduino UNO, L298N driver and IR transmitter and Receiver for the electronic components, for the chassis I used acrylic sheet which I fabricated using Laser cutting machine and for the motor clamps I 3D printed them.

Supplies

  1. Arduino UNO
  2. BO Motor
  3. L298N Motor driver
  4. Infrared Transmitter and Receiver LED
  5. Resistors: 220ohms and 4.7Kohms
  6. Male to Male and Male to Female Jumper wire
  7. Ball caster wheel
  8. M3 Bolts, Nuts and female to female hex standoff spacer

Understanding the Logic

The purpose of the motor is to move the bot.

The purpose of the motor driver is to control the speed and rotation of the motors.

The purpose of the Infrared(IR) LEDs is to differentiate between the black and non black surface. The IR transmitter emits infrared rays, the rays bounces onto the surface and the IR receiver detects the infrared rays. The black color absorbs all the infrared rays and doesn't let any rays bounce for the IR receiver to detect. So in reality, the bot is following the non black surface while avoiding the black surface. But because of the arrangement of the pair of IR LEDs, it looks like the bot is following the line. The distance between the two pair or IR LEDs should be equivalent to the width of the black line on which you want the bot to follow.

Arduino UNO is the micro-controller who will take input from the IR receiver and accordingly give the output to the motor driver.

Here is how the line following bot works:

IR LEDs will detect the surface if it is black or non black, send the signal to the UNO, the UNO according to the code will send the signal to the driver and accordingly the motors will rotate and the bot will follow the line.

How does bot know when to move forward and when to take left or right turns?

There are three cases for the bot: move forward, turn left and turn right. Place the bot in a way that the black line is between the two pair of IR LEDs

Forward motion: When you place the bot in a way that the black line is between the two pair of IR LEDs, what will happen is that the IR receiver on the left pair and right pair will detect white surface. In the case where the left IR receiver and right IR receiver is detecting white surface, the motor on the right will rotate clockwise and the motor on the left will rotate counterclockwise. Because of that the bot will move forward.

Left turn: When the bot is moving forward and there is a left curve in the black line, what will happen is that the IR receiver on the left pair will detect a black surface and at the same time the IR receiver on the right pair will be detecting white surface. In the case where the left IR receiver is detecting black surface while the right IR receiver is detecting white surface, the motor on the right and the motor on the left will rotate counterclockwise. Because of that the bot will turn left.

Right turn: When the bot is moving forward and there is a right curve in the black line, what will happen is that the IR receiver on the right pair will detect a black surface and at the same time the IR receiver on the left pair will be detecting white surface. In the case where the right IR receiver is detecting black surface while the left IR receiver is detecting white surface, the motor on the left and the motor on the right will rotate clockwise. Because of that the bot will turn right.

Design

Screenshot_14.png
Screenshot_15.png
Screenshot_6.png
Screenshot_7.png
Screenshot_9.png
Screenshot_10.png
Screenshot_8.png
Screenshot_11.png
Screenshot_12.png
Screenshot_13.png

I designed the motor clamps and chassis in Solidworks and tried to assemble the parts and components to get an idea of the final outcome. There are three chassis: top chassis for mounting UNO, bottom chassis for mounting motors and driver(there is provision for battery also) and third chassis(caster wheel and ir mount) for mounting caster wheel and IR LEDs

I am attaching the STL file for motor clamp and DXF file for the three chassis and circular spacers(for bolts).

Soldering IR LEDs and Resistor

schematic IR.png
IMG20230228152638.jpg
IMG20230228152632.jpg

I used 220 ohms resistor for IR transmitter in series between cathode pin and ground. Used 4.7K ohm resistor for IR receiver in series between anode pin and ground. For getting the digital input from the IR receiver I connected a wire between anode pin of the IR receiver and 4.7K ohm resistor. To solder IR LEDs, resistors and wires I used zero PCB. In the image of zero PCB, the black wire is for ground, green for 5V and two yellow is for digital reading. Refer to the schematic attached.


Important Note:

There are some differences in using IR Module with LM393 Integrated circuit and IR LEDs with just resistors.

In IR Module there is a potentiometer to set the sensitivity for detecting the objects/surfaces and there is LM393 IC which is a precision voltage comparator which can give give you output in digital as well as analog signal. In using IR LEDs with just resistor, you cannot set the sensitivity, as in you cannot decided at what distance you want to detect the object.

The output signal from the IR module and the IR Receiver LED is exact opposite. In case of IR module when an object is placed in front of the pair of LEDs(non black surface) it will give the output signal as 0(LOW) and when there is no object placed(black surface) it will give the output signal as 1(HIGH). Inversely, in case of IR receiver LED when an object is placed is front of pair of LEDs(non black surface) is will give the output signal as 1(HIGH) and hen there is no object placed(black surface) it will give the output signal as 0(LOW).

Connection of All the Components

schematic components.png

Follow the above schematic for the connection of Motors, Driver, UNO, IR LEDs PCB and power supply. For the power supply I was using a programmable DC power supply and I had set the voltage as 12V and maximum current as 0.3A.

Programming

For the programming part, I took some reference online. I had to make slight modifications in the code since I was using IR LEDs with resistors instead of IR module. Here is the code:

/*
Original creator: https://circuitbest.com/line-follower-robot-car-with-arduino-uno-l298n-driver-ir-sensor/
*/


/*
The remix Version: https://www.instructables.com/Line-Following-Bot/
For the line following bot I used IR LEDs instead of IR module, so there were some changes in the original code.
The motor speed I have set is according to the power supply I was using: 12V0.3A
*/


// Left motor
#define in1 4
#define in2 5
#define enA 6


// Right motor
#define in3 8
#define in4 9
#define enB 10


 int M1_Speed = 85; // Left motor speed
 int M2_Speed = 65; // Right motor speed
 int LeftRotationSpeed = 85;  // Left Rotation Speed
 int RightRotationSpeed = 65; // Right Rotation Speed


 void setup() {


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


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


      pinMode(2, INPUT); // Left IR LEDs
      pinMode(3, INPUT); // Right IR LEDs


        // Turn off motors - Initial state
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW); 


}


void loop() {


  int LEFT_SENSOR = digitalRead(2);
  int RIGHT_SENSOR = digitalRead(3);


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


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


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


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


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


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


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


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


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


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


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

If you're using IR LEDs with resistor, you can upload the code mentioned above. However if you're using IR module, you can take the reference of the original creator.

Assembly

IMG20230228121141.jpg
IMG20230301210933.jpg
IMG20230301211102.jpg
IMG20230228183233edit.jpg
IMG_20230325_231827edit.jpg

The bot is divided into three chassis: on the bottom chassis I have mounted driver and motor and given the provision for battery to mount underneath the bottom chassis, on the top chassis I have mounted UNO and on the third chassis I have mounted caster wheel and IR LEDs PCB. The third chassis is suppose to be mounted onto the bottom chassis with the help of long bolt(3 inch) and top chassis is suppose to be mounted onto the bottom chassis with the help of standoff spacer. Refer to the images provided in the design step for reference.

While designing I had given the provision for all the holes on the chassis and motor clamp except for the IR LEDs PCB and caster wheel. For that I manually drilled the holes in PCB and the third chassis. Use cable ties to tidy up the wires.

Results

line following robot - Basic

Any feedback would be greatly appreciated.