line follower robot


line follower robots work on basic concept of reflection of light, we use light sensors usually available in the market as a pair of photo diode and an LED. The concept is the LED keeps emitting light and if any obstacle
comes in its way , then the obstacle will reflect the light and that reflected light falls on the photodiode.
Now as we all know the property of photo diode is that it conducts when light falls on it...now the photo diode is connected to a "D" pin , usually known as data pin/signal pin...so now according to process we get a HIGH or logic of 5V when obstacle is there and "0V" when nothing.






Now in the above diagram we can see that 3 pins are popping out of the sensor, namely + -D
..the "+" pin needs to be connected to 5V of arduino or any microcontroller you will be using.
Now connect the black color wire to GND pin of your arduino or known as ground...or simply one can declare a pin as LOW and connect the black wire to it also.
Now comes the yellow wire...this is the wire that gives you data or signal whether object is there or not, we need to connect this wire to a digital pin mostly depends on the type of sensor here if you are not using PWM then you can connect to any pin on arduino from D13-D2.

Now in same fashion connect left and right sensors...after wiring check everything and now upload this program assuming that 2 motors with a L293D motor driver are all ready hooked.

Now the basic working is when the sensors are on white part the value on data pin is HIGH and when they are on black line the value on data pin is LOW, as black color doesnt reflect light so photodiode stays inactive and hence giving a LOW, so using these conditions we can make some test cases and make the robot act accordingly by turning and changing the wheel direction.





//*line follower code for arduino*//
int s1,s2;
void setup()
{
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);        // these 4 pins 10,11,12,13 are for 2 motors
  pinMode(13,OUTPUT);
  pinMode(2,INPUT);             // these 2 pins 2 and 3 are for sensors
  pinMode(3,INPUT);
}
void loop()
{
  s1=digitalRead(2);
  s2=digitalRead(3);                                    //reading sensor values and storing them in variables l & r
  if(s1==HIGH && s2==HIGH)
  {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
  }
  else if(s1==HIGH && s2==LOW)                   //checking the conditions
  {
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
  }
  else if(s1==LOW && s2==HIGH)
  {
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
   }
 delay(100);
}
//*ends here*//


In similar way you can do your line follower by using WINAVR software also below ode just connect the hardware according to the bellow code and compile it finally a HEX file is generated just dump that hex file to microcontroller with avaliable tools like HIDBOOT flash etc...

Microcontroller:....ATmega-8
Clock:..............12mhz
compiler :WinAVR-20100110
Connection details

Left sensor-------------------------PORTC 0
Right sensor------------------------PORTC 1

Left motor +ve----------------------PORTD 7 M7
Left motor -ve----------------------PORTD 6 M6
Right motor -ve---------------------PORTD 5 M5
Right motor +ve---------------------PORTD 4 M4
***********************************************************************/

#include<avr/io.h>

int main(void)
{
  DDRC=0X00; // Initialization of PORTC as input for sensor
  PORTC=0X00;
  
  DDRD=0XF0; // Initailization of PORTD as output for MOTOR
  PORTD=0X00;
  
  while(1)
  {
if((PINC & 0X01)==0X01) //if Left Sensor comes upon the black line
{
PORTD=0X10;               // Turn LEFT
}
else if((PINC & 0X02)==0X02) // if Right Sensorcomes upon the black line
{
PORTD=0x40; // Turn RIGHT
}
else
{
PORTD=0X50; // Move Forward
}
  }

Comments

Popular posts from this blog

ADC....¡¡

RF REMOTE..

Making your own arduino...!!!