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
IF YOU FEEL THIS CODE WORK FOR YOUR PROJECTS
AND WANT MORE . I WISH YOU DONATE
Comments
Post a Comment