Ligth Follower Arduino Based Robot

6,444

11

21

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);
}

}

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    21 Discussions

    None
    amando96

    10 years ago on Introduction

    that was nice, waiting for the video! i'm trying to make a minibot with two 555's that follows light :) in theory it will work... i just have to see in reality xD

    16 replies
    None
    Chowmix12Chowmix12

    Reply 9 years ago on Introduction

    i also made a very similar light seeking robot, except, mine uses a 555 timer chip instead of arduino.. it also has a reverse relay.. for a lot cheaper...

    P1040478.JPGP1040470.JPGP1040463.JPG
    None
    mnovaChowmix12

    Reply 8 years ago on Introduction

    I do not have a Arduino board. I was trying to do this with just a 555 timer and LDRs.

    None
    Chowmix12s.gosiaco

    Reply 9 years ago on Introduction

    very discriptive... are the motors reacting to the sensors at all? if yes, try crossing the CdS cells. . if no, then try removing the potentiometer, and use the schematic above...

    None
    helloworld1amando96

    Reply 10 years ago on Introduction

    what do the 555's (the timers right?) actually do, and could i make a digital clock with one of them?

    None
    amando96helloworld1

    Reply 10 years ago on Introduction

    they time intervals sort of, and no you couldnt because you can never get an interval that is equal to one second, it would become wrong in like 5 minutes... you can use an RTC wich is a real time clock, that counts second, minutes, hours etc... every computer has one in the motherboard, thats why it has that small coin cell there :D they are cheap, so get one!! :D

    None
    helloworld1amando96

    Reply 10 years ago on Introduction

    oh cool, do you have any idea how you would wire that up to an lcd and some sort of microcontroller to be able to set it?

    None
    edson04

    9 years ago on Introduction

    Hi, which diode you use? and i bought the H brige l293e but its not the same i have 20 pin and in yours you have 16 pin and when i make the circuit with the diode i got a short court .. need some help please