Line Following Robot

Background Knowledge:

What you'll need:

1 - 9 Volt Battery

1 - 9 Volt Battery Harness

1 - SPST Switch

1 - Breadboard

1 - Arduino UNO

1 - LM298N motor controller

2 - IR proximity sensors

2 - DC motors with wheels

Wheels and Chassis Kit (Make this)

The Line Following Robot project, utilizing an Arduino, LM298N motor controller, and IR sensors, is designed to create an autonomous robotic system capable of tracking and following a predetermined path or line on a surface. The IR sensors, positioned underneath the robot, continuously monitor the surface, generating signals based on the reflected infrared light. The Arduino processes these inputs, implementing a control algorithm that adjusts the LM298N motor controller to regulate the power supplied to the DC motors. This dynamic motor control allows the robot to make precise movements, maintaining alignment with the line. The project serves as an educational tool, offering hands-on experience in sensor integration, motor control, and programming with Arduino. Additionally, it can be extended to include features like obstacle avoidance, providing a foundational platform for understanding and experimenting with robotics concepts in various educational settings.

Parts for Consideration

LM298N

The L298N is a dual H-bridge motor driver integrated circuit (IC) widely used for controlling and driving DC motors and stepper motors. Developed by STMicroelectronics, the L298N is designed to handle high currents and voltages, making it suitable for a variety of robotic and motor control applications.

Key features of the L298N motor controller include:

In summary, the L298N motor controller is a versatile and robust solution for driving and controlling DC motors and stepper motors in various electronic projects and applications. Its dual H-bridge design, high current/voltage capabilities, and compatibility with different control systems make it a popular choice among hobbyists and engineers for motor control projects.

LM298N Pinout

The L298N motor controller has a 15-pin configuration, and each pin serves a specific function in controlling and driving motors. Here's an explanation of the pinout:

It's essential to provide appropriate external power supplies to the Vs and Vss pins, and the logic control signals (ENA, IN1, IN2, ENB, IN3, IN4) are typically controlled by a microcontroller or other digital control circuits. Careful attention to the logic levels and power requirements is crucial for proper operation of the L298N motor controller.

IR Proximity Sensor

An IR Proximity Sensor designed for line-following applications is a key component in robotics and automation. This sensor is specifically tailored to detect infrared light, allowing it to distinguish between contrasting surfaces, such as a dark line on a lighter background. Here's a summary of its features and functionality:

Infrared Sensing Technology: The IR Proximity Sensor utilizes infrared light to detect variations in reflectivity on the surface beneath it. This makes it particularly useful for tracking lines on surfaces, like a contrasting track on the ground.

Emitter and Receiver Pair: The sensor typically consists of an infrared emitter and a photodiode receiver. The emitter sends out infrared light, and the receiver measures the intensity of the reflected light. The difference in reflectivity helps the sensor determine the position of the line.

Analog Output: These sensors often provide analog output, delivering a voltage signal proportional to the intensity of the reflected infrared light. The analog signal can be processed by a microcontroller to make decisions about the robot's movement based on the detected line.

Adjustable Sensitivity: Many IR Proximity Sensors for line followers come with adjustable sensitivity settings. This allows users to fine-tune the sensor's response to varying lighting conditions or different surface types.

The pinout of an IR Proximity Sensor can vary between different models and manufacturers, but here is a general overview of the typical pin configuration for such sensors:

VCC (Power Supply): This pin is used to connect the sensor to the positive power supply. It usually requires a voltage within a specified range (commonly 3.3V or 5V), as indicated by the manufacturer.

GND (Ground): Connect this pin to the ground (0V) of the power supply. It establishes the reference potential for the sensor.

Signal Output: The sensor provides an output signal that corresponds to the intensity of the reflected infrared light. This pin carries the analog or digital signal, depending on the specific sensor model. In some sensors, there might be both analog and digital output pins.

Various Notes

Adjustment (if available): Some IR Proximity Sensors come with a sensitivity adjustment potentiometer. If present, this pin allows you to adjust the sensor's sensitivity to better suit the environmental conditions or the type of surface being detected.

Emitter (LED): In sensors with a separate emitter and receiver, this pin is connected to the infrared LED (Light Emitting Diode) that emits the infrared light used for detection.

Receiver (Photodiode): In sensors with a separate emitter and receiver, this pin is connected to the photodiode that receives the reflected infrared light. The intensity of the received light is used to determine the surface characteristics.

It's crucial to refer to the datasheet or documentation provided by the specific manufacturer for accurate pinout information, as variations can exist. Additionally, when integrating the sensor into a circuit, ensure proper voltage levels, and take note of any polarity considerations.

Building the Project

2. Write the Arduino Sketch

// Made by MakerLessons


int ENA = 11; //ENA connected to digital pin 11

int ENB = 3; //ENB connected to digital pin 3

int MOTOR_A1 = 10; // MOTOR_A1 connected to digital pin 10

int MOTOR_A2 = 9; // MOTOR_A2 connected to digital pin 9

int MOTOR_B1 = 6; // MOTOR_B1 connected to digital pin 6

int MOTOR_B2 = 5; // MOTOR_B2 connected to digital pin 5


int RIGHT = A0; // RIGHT IR sensor connected to analog pin A0

int LEFT = A1; // LEFT IR sensor connected to analog pin A1


// the setup function runs once when you press reset or power the board

void setup() {

  

pinMode(ENA, OUTPUT); // initialize ENA pin as an output

pinMode(ENB, OUTPUT); // initialize ENB pin as an output

pinMode(MOTOR_A1, OUTPUT); // initialize MOTOR_A1 pin as an output

pinMode(MOTOR_A2, OUTPUT); // initialize MOTOR_A2 pin as an output

pinMode(MOTOR_B1, OUTPUT); // initialize MOTOR_B1 pin as an output

pinMode(MOTOR_B2, OUTPUT); // initialize MOTOR_B2 pin as an output

pinMode(RIGHT, INPUT); // initialize RIGHT IR pin as an input

pinMode(LEFT, INPUT); // initialize LEFT IR pin as an input


}


// the loop function runs over and over again forever

void loop() {

  

if (analogRead(RIGHT)<=35 && analogRead(LEFT)<=35) //compare the both sensor to decide the direction

{

  //MOVE FORWARD//

  

  analogWrite(ENA, 100); // set right motors speed

  analogWrite(ENB, 100); // set left motors speed

  

  //run right motors clockwise

  digitalWrite(MOTOR_A1, LOW);

  digitalWrite(MOTOR_A2, HIGH);

  //run left motors clockwise

  digitalWrite(MOTOR_B1, HIGH);

  digitalWrite(MOTOR_B2, LOW);

}

else if (analogRead(RIGHT)<=35 && !analogRead(LEFT)<=35) //compare the both sensor to decide the direction

{

  //MOVE RIGHT//

  

  analogWrite(ENA, 255); //set right motors speed

  analogWrite(ENB, 255); //set left motors speed

  

  //run right motors clockwise

  digitalWrite(MOTOR_A1, LOW);

  digitalWrite(MOTOR_A2, HIGH);

  //run left motors anti-clockwise

  digitalWrite(MOTOR_B1, LOW);

  digitalWrite(MOTOR_B2, HIGH);

}

else if (!analogRead(RIGHT)<=35 && analogRead(LEFT)<=35) //compare the both sensor to decide the direction

  //MOVE-LEFT//

  

  analogWrite(ENA, 255); //set right motors speed

  analogWrite(ENB, 255); //set left motors speed


  //run right motors anti-clockwise

  digitalWrite(MOTOR_A1, HIGH);

  digitalWrite(MOTOR_A2, LOW);

  //run left motors clockwise

  digitalWrite(MOTOR_B1, HIGH);

  digitalWrite(MOTOR_B2, LOW);

}

else if (!analogRead(RIGHT)<=35 && !analogRead(LEFT)<=35) //compare the both sensor to decide the direction

  //STOP//

  

  analogWrite(ENA, 0); //set right motors speed

  analogWrite(ENB, 0); //set left motors speed


  //stop right motors

  digitalWrite(MOTOR_A1, LOW);

  digitalWrite(MOTOR_A2, LOW);

  //stop left motors

  digitalWrite(MOTOR_B1, LOW);

  digitalWrite(MOTOR_B2, LOW);

  }

}

3. Understand the Code

int MOTOR_A1 = 10; // MOTOR_A1 connected to digital pin 10

pinMode(MOTOR_A1, OUTPUT); // initialize MOTOR_A1 pin as an output

pinMode(RIGHT, INPUT); // initialize RIGHT IR pin as an input

{

 //MOVE FORWARD//

     analogWrite(ENA, 100); // set right motors speed

analogWrite(ENB, 100); // set left motors speed

//run right motors clockwise

digitalWrite(MOTOR_A1, LOW);

digitalWrite(MOTOR_A2, HIGH);

//run left motors clockwise

digitalWrite(MOTOR_B1, HIGH);

digitalWrite(MOTOR_B2, LOW);

}

4. Upload and Monitor

5. Experiment and Observe

Considerations:

Questions: