Ligth Follower Arduino Based Robot

by kurtbadelt in Circuits > Robots

6633 Views, 11 Favorites, 0 Comments

Ligth Follower Arduino Based Robot

01.jpg
07.jpg
08.jpg
09.jpg
10.jpg
11.jpg
20.jpg
21.jpg
22.jpg
23.jpg
Driver L293b.jpg
PCB Alpha.JPG
12.jpg
13.jpg
14.jpg
15.jpg
16.jpg
17.jpg
18.jpg
19.jpg
This is my very first robot, a ligth follower Robot

1. Tamiya caterpillar kit
2. Tamiya twin gearbox
3. Arduino Diecimila
4. H bridge L293e
5. 8 Diodes
6. Bread board
7. 2 Photo resistance
8 lot of wires

the Source Code:

int pinMotorL1=2;
int pinMotorL2=3;
int pinMotorR1=8;
int pinMotorR2=9;
int pinEnableL = 4;
int pinEnableR = 5;
int valPWM = 175;

void setup()
{
// begin the serial communication
Serial.begin(9600);
pinMode(pinMotorL1, OUTPUT);
pinMode(pinMotorL2, OUTPUT);
pinMode(pinMotorR1, OUTPUT);
pinMode(pinMotorR2, OUTPUT);
pinMode(pinEnableL, OUTPUT);
pinMode(pinEnableR, OUTPUT);
}

void ForwardR(){
digitalWrite(pinEnableR,valPWM);
digitalWrite(pinMotorR1,HIGH);
digitalWrite(pinMotorR2,LOW);
}
void ForwardL(){
digitalWrite(pinEnableL,valPWM);
digitalWrite(pinMotorL1,HIGH);
digitalWrite(pinMotorL2,LOW);

}
void BackwardR(){
digitalWrite(pinEnableR,valPWM);
digitalWrite(pinMotorR1,LOW);
digitalWrite(pinMotorR2,HIGH);

}
void BackwardL(){
digitalWrite(pinEnableL,valPWM);
digitalWrite(pinMotorL1,LOW);
digitalWrite(pinMotorL2,HIGH);
}
void StopR(){
digitalWrite(pinEnableR,valPWM);
digitalWrite(pinMotorR1,HIGH);
digitalWrite(pinMotorR2,HIGH);

}
void StopL(){
digitalWrite(pinEnableL,valPWM);
digitalWrite(pinMotorL1,HIGH);
digitalWrite(pinMotorL2,HIGH);
}

void StopAll(){
StopR();
StopL();
}

void goForward(){
ForwardR();
ForwardL();
}

void goBackward(){
BackwardR();
BackwardL();
}

void TurnR(){
ForwardL();
BackwardR();
}
void TurnL(){
ForwardR();
BackwardL();
}

void move(byte val){
if(val==0){
// Serial.println("Caso 0-Adelante");

goForward();
delay(1000);
StopAll();

}else
if(val==1){
// Serial.println("Caso 1-Atras");

goBackward();
delay(1000);
StopAll();
}else
if(val==2){
// Serial.println("Caso 2-Derecha");

TurnR();
delay(1000);
StopAll();

}else
if(val==3){
//Serial.println("Caso 3-Izquierda");

TurnL();
delay(1000);
StopAll();

}
else{
//Serial.println("no valido ninguno");
goForward();
delay(1000);
StopAll();
}
}

void loop()
{
float ojoDerecho = analogRead(1);
float ojoIzquierdo = analogRead(0);

//adelante
move(0);
//Derecha
if(ojoDerecho > ojoIzquierdo){
move(2);
}
//Izquierda
else if(ojoIzquierdo > ojoDerecho){
move(3);
}

}