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 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*//
pinMode(12,OUTPUT); // these 4 pins 10,11,12,13 are for 2 motors
pinMode(2,INPUT); // these 2 pins 2 and 3 are for sensors
s2=digitalRead(3); //reading sensor values and storing them in variables l & r
if(s1==HIGH && s2==HIGH)
else if(s1==HIGH && s2==LOW) //checking the conditions
else if(s1==LOW && s2==HIGH)
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...
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
DDRC=0X00; // Initialization of PORTC as input for sensor
DDRD=0XF0; // Initailization of PORTD as output for MOTOR
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
PORTD=0X50; // Move Forward