Site icon Circuit Ideas for You

Arduino Line Follower Robot Circuit

This project is for Arduino Line Follower Robot Circuit.

Robot can follow black line on white floor.

It use Arduino, L298N motor driver and two IR sensors.

IR sensors see line and send signal to Arduino.

Arduino control motors and move robot on path.

Very simple and fun project.

Good for learning and school use.

Arduino Coding:

int leftIR = 2;
int rightIR = 3;
int in1 = 5;
int in2 = 6;
int in3 = 9;
int in4 = 10;

void setup() {
  pinMode(leftIR, INPUT);
  pinMode(rightIR, INPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void loop() {
  int leftVal = digitalRead(leftIR);
  int rightVal = digitalRead(rightIR);

  if (leftVal == 1 && rightVal == 1) {
    forward();
  } 
  else if (leftVal == 0 && rightVal == 1) {
    leftTurn();
  } 
  else if (leftVal == 1 && rightVal == 0) {
    rightTurn();
  } 
  else {
    stopMotor();
  }
}

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

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

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

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

Code Explanation:

Circuit Working:

Parts List:

Part NameQuantity
Arduino UNO R31
L298N Motor Driver1
IR Sensor2
DC Motors with Wheels4
7V to 12V Battery1
SPST Toggle switch1
Robot Chassis1

IR sensors keeps watching the surface.

If both see white then robot goes straight.

If left sensor see black then robot turns left.

If right sensor see black then robot turns right.

If both see black then robot stops or wait.

Arduino read sensor signal.

Then send command to L298N driver.

Driver control motor speed and direction.

Robot follow black line on white floor by itself.

How to Build:

To build a Arduino Line Follower Robot Circuit follow the below steps:

Conclusion:

This is simple Arduino Line Follower Robot Circuit.

Good for learning Arduino basics.

IR sensors see the line.

Arduino read signals and run motors with L298N driver.

Robot move and follow path by itself.

Easy to make and is good for beginners and school project.

References:

How do I make a line follower robot with three IR sensor using Arduino Uno? 

Exit mobile version