Skip to main content

Line Follower Robot for beginers with arduino

hello guys welcome back again
sorry for very long time


i am gonna show you about PID based line follower robot
so what is pid

PID :

consept of pid is war with errors.
we try to programme a controller to automatically solve error by it self 

ERROR of Line follower robot : 
when ever line follower leave the black line it stops detecting so this programme teach controller that how to solve this problem automatically.



Line follower:
basically everyone knows that line follower needs ir sensor but you can also use color sensor but it is too costly than ir.
so we are going to use ir sensor and photodiode.


components :
5×ir leds
5×photodiodes
1×arduino
opamp
l293d



note: this is just helping gude you can copy programme but you have to make circuits by your self because it does not make any sense that i will tell you every thing about robot

i have show video below that how is this programe work

and its proof that this programme is working


i have described previously that have won in university by this robot.





programme :




int la = 8;
int lb = 9;
int lc = 10;
int ld = 11;
int le = 12;
int L1=2;
int L2=3;
int R1=4;
int R2=5;
int a=0;
int b=0;
int c=0;
int d =0;
int e=0;
int L = 13;
char q=0;

void setup()
{
  Serial.begin(9600);
   pinMode(la,INPUT);
   pinMode(lb,INPUT);
   pinMode(lc,INPUT);
   pinMode(ld,INPUT);
   pinMode(le,INPUT);
   pinMode(L1,OUTPUT);
   pinMode(L2,OUTPUT);
   pinMode(R1,OUTPUT);
   pinMode(R2,OUTPUT);
   pinMode(L,OUTPUT);
}
void loop()
{
  a=digitalRead(la);
  b=digitalRead(lb);
  c=digitalRead(lc);
  d=digitalRead(ld);
  e=digitalRead(le);
  if( a== 0 ){
   f_left();
   q='a';
  }
  else if ( b == 0 ){
   left();
   q='b';
  }
  else if (c==0){
    fow();
    q='c';
  }
  else if(d==0){
   right();
   q='d';
  }
  else if(e==0){
   f_right();
   q='e';
  }
 else if(d == 0 && e == 0){
    f_right();
    q='e';
 }
  else if ( a==0 && b==0){
     f_left();
     q='a';
  } 
  else if( b==0 && e==0&& d==0 && c==0){
    f_right();
    q='e';
  }
    else if(a==0 && b==0 && c==0 && d==0){
     f_left();
     q='a';
  }
     else if(a==1 && b==1 && c==1 && d==1 && e==1){ 
         if(q=='a'){
            f_left();
          }
         else if(q=='b')
            f_left();
          else if(q=='d')
            f_right();
          else if(q=='e')
            f_right();
          else if(q=='c')
            fow();
          else
          {
            led();
            delay(500);
            les();
            delay(500);
            led();
            stp();
          }
        }
       
  
  else if(a==0 && b==0 && c==0 && d==0 && e==0){
         if(q=='a'){
            f_left();
          }
          else if(q=='b'){
            f_left();
         }
          else if(q=='d'){
            f_right();
          }
          else if(q=='e'){
            f_right();
          }
          else
          {
            led();
            delay(500);
            les();
            delay(500);
            led();
            stp();
          }
  }
}



void fow(){
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  digitalWrite(R1,HIGH);
  digitalWrite(R2,LOW);
}
void rev(){
  digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  digitalWrite(R1,LOW);
  digitalWrite(R2,HIGH);
}
void f_right(){
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  digitalWrite(R1,LOW);
  digitalWrite(R2,HIGH);
}
void f_left(){
  digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  digitalWrite(R1,HIGH);
  digitalWrite(R2,LOW);
}
void right(){
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  digitalWrite(R1,LOW);
  digitalWrite(R2,LOW);   
}
void left(){
  digitalWrite(L1,LOW);
  digitalWrite(L2,LOW);
  digitalWrite(R1,HIGH);
  digitalWrite(R2,LOW);
}
void stp()
{
  digitalWrite(L1,LOW);
  digitalWrite(L2,LOW);
  digitalWrite(R1,LOW);
  digitalWrite(R2,LOW);
  
}
void led(){
  digitalWrite(L,HIGH);
}
void les(){
  digitalWrite(L,LOW);
}













its very basic programme and its for beginners

thank you.
if you have any query mail me every time
comment and follow.

 IF YOU FEEL THIS CODE WORK FOR YOUR PROJECTS 
AND WANT MORE . I WISH YOU DONATE 

Comments

Popular posts from this blog

Python Reads gmail

This is tutorial on how to read gmail emails with python programme : ----------------- #!/usr/bin/python __author__ = 'Robokishan' import email import imaplib import ctypes import getpass mail = imaplib.IMAP4_SSL('imap.gmail.com',993) unm = raw_input("insert Email : ") #pwd = raw_input("insert password : ") pwd = getpass.getpass("input : ") mail.login(unm,pwd) mail.select("INBOX") def loop():    mail.select("INBOX")    n=0    (retcode, messages) = mail.search(None, '(UNSEEN)')    if retcode == 'OK':             for num in messages[0].split() :          #print 'Processing '          n=n+1          print n          typ, data = mail.fetch(num,'(RFC822)')          for response_part in data:             if isinstance(response_part, tuple): ...

ArduPilot reverse engineering #1

its been a long time, from drone development and also from electronics and blogging, let it go, tonight it is ardupilot time, I have seen some algorithms working like get position and velocity from accelerometer data but haven't found anything yet. so was surfing through the code and found that AP_InertialNavEKF.h library is just fallback library for the ardupilot to switch between ekf and normal mode.  a comment from first line /* A wrapper around the AP_InertialNav class which uses the NavEKF filter if available, and falls back to the AP_InertialNav filter when EKF is not available */ /** now working on how can I implement on my own drone since my plans are different from ardupilot. so here i am now sleepless nights and go on until I finally make my quadcopter (the only incomplement project left).

How to make stoppable thread in python

Python multi threading: stoppable thread:     many of you heard about threading in python is very bad. its not easy to stop it but there are several method to do that thing happen .     so lets get started.     create file name called <filename>.py then paste this code in your text editor. import threading import time ##writer = Robokishan ##stopable thread class ThreadingExample(object):     """ Threading example class     The run() method will be started and it will run in the background     until the application exits.     """     #NOTE: STOPING THREAD IS BAD METHOD     def __init__(self, interval=1):         """ Constructor         :type interval: int         :param interval: Check interval, in seconds       ...