Project tutorial
Line Following Robot

Line Following Robot © CC BY

line following robot setup using an L298N motor driver with an Arduino and two proximity sensor modules.

  • 1,282 views
  • 0 comments
  • 5 respects

Components and supplies

About this project

well, i want to add a line following system in my robot (chunchunmaru) so first i made this small setup and try to add proximity sensors to it.

watch the video

Code

Untitled fileC/C++
int mot1=9;
int mot2=6;
int mot3=5;
int mot4=3;
const int buttonPin1 = A0;
int left=13;
int right=12;

int Left=0;
int Right=0;
int buttonState = 0;    

void LEFT (void);
void RIGHT (void);
void STOP (void);

void setup()
{
  pinMode(mot1,OUTPUT);
  pinMode(buttonPin1,INPUT);  
  pinMode(mot2,OUTPUT);
  pinMode(mot3,OUTPUT);
  pinMode(mot4,OUTPUT);

  pinMode(left,INPUT);
  pinMode(right,INPUT);

  digitalWrite(left,HIGH);
  digitalWrite(right,HIGH);
  
  
}

void loop() 
{

   buttonState = digitalRead(buttonPin1);

 if (buttonState == HIGH) {
 
analogWrite(mot1,255);
analogWrite(mot2,0);
analogWrite(mot3,255);
analogWrite(mot4,0);

while(1)
{
  Left=digitalRead(left);
  Right=digitalRead(right);
  
  if((Left==0 && Right==1)==1)
  LEFT();
  else if((Right==0 && Left==1)==1)
  RIGHT();
}
 }
 else {
    }
}

void LEFT (void)
{
   analogWrite(mot3,0);
   analogWrite(mot4,30);
   
   
   while(Left==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Right==0)
    {
      int lprev=Left;
      int rprev=Right;
      STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot1,255);
    analogWrite(mot2,0); 
   }
   analogWrite(mot3,255);
   analogWrite(mot4,0);
}

void RIGHT (void)
{
   analogWrite(mot1,0);
   analogWrite(mot2,30);

   while(Right==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Left==0)
    {
      int lprev=Left;
      int rprev=Right;
     STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot3,255);
    analogWrite(mot4,0);
    }
   analogWrite(mot1,255);
   analogWrite(mot2,0);
}
void STOP (void)
{
analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);
}

Schematics

line_f_rob_3_PzXYEImJfR.jpg
Line f rob 3 pzxyeimjfr

Comments

Similar projects you might like

MeArm Robot Arm - Your Robot - V1.0

Project tutorial by Benjamin Gray

  • 19,302 views
  • 3 comments
  • 34 respects

Arduino-Based Butler Robot

Project showcase by Arnov Sharma

  • 1,005 views
  • 1 comment
  • 3 respects

Stair Climbing Robot

Project tutorial by Jason Jaeger

  • 15,134 views
  • 9 comments
  • 52 respects

Easiest Line Follower Robot

Project tutorial by Zubayer Al Billal Khan

  • 12,720 views
  • 10 comments
  • 30 respects

Controlling A Roomba Robot With Arduino And Android Device

Project tutorial by MJRoBot

  • 11,385 views
  • 4 comments
  • 12 respects

Graphical Programming Obstacle Avoidance Robot

Project tutorial by Team KittenBot

  • 2,651 views
  • 1 comment
  • 14 respects
Add projectSign up / Login