Project on line follower robot in visual basic


In this article i will provide you the programming of simple line follower robot. A line follower robot is an autonomous robot which follows black line on its own.It uses ATMEGA 16 microcontroller which take decision for the robot

Introduction to Line follower robot


Line follower robot is an autonomous robot that means it will follow the black line on its own without any control of the user. The kit i am using consist of two geared motors,a castor wheel,one ATMEGA 16 microcontroller,LCD display and three LDR sensors. LDR sensor are placed on left,center and right in front of the robot so that they will provide input to the microcontroller. Microcontroller will give instruction to the robot according to the program burned on it.

Logic used for programming


We are using LDR sensors because they will give different value for the different intensity of light that is reflected back by the colour of the surface on which the robot is placed. So the sensor will provide different values for black colour and white colour. Using these value we will be detecting the black line. Lets assume 1000 is value given when sensor is placed over black and 500 when placed over white. We first take mean for both values yht comes out to be 750. Mean is taken beacuse sensor will not give same value each time even if we place it on the same surface . So a range is taken that if the value is above 750 than it is on black and if below 750 it is on white surface.So this the method to detect the line by sensors

Motion of robot according to sensor positions


There will be many conditions that may occur like forward, right turn,left turn and turn can be sharp or slant.So we have to take every situation while programing.

1.When the center sensor is on the black and other two are on white than robot should go straight.

2.When left sensor is on black and other two are on white than robot has two take a slant left turn.

3.When the right sensor is on black and others are on white than robot has to take a slant right turn.

4.When the left and center sensors are on black and other on white than the robot has to take sharp left turn.

5.When the right and center sensors are on black and other on white than the robot has to take sharp right turn.

6.When all the sensors are on white than the robot should stop.

CODING


The coding is given below

$regfile = "m16def.dat"
$crystal = 1000000

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Start Timer1

Dim L As Integer , C As Integer , R As Integer
Dim Lb As Integer , Cb As Integer , Rb As Integer
Dim Lw As Integer , Cw As Integer , Rw As Integer
Dim Lbm As Integer , Lm As Integer , Cm As Integer , Rm As Integer
Cls
Lcd "place on black"
Waitms 5000
Lb = Getadc(0)
Cb = Getadc(1)
Rb = Getadc(2)

Cls
Lcd "place on white"
Waitms 5000
Lw = Getadc(0)
Cw = Getadc(1)
Rw = Getadc(2)

Lm = Lb + Lw
Lm = Lm / 2

Cm = Cb + Cw
Cm = Cm / 2

Rm = Rb + Rw
Rm = Rm / 2


Do
Cls
L = Getadc(0)
C = Getadc(1)
R = Getadc(2)

If L < Lm And C > Cm And R < Rm Then
Lcd "forward"
Pwm1b = 200
Portd.3 = 0
Pwm1a = 200
Portd.6 = 0

Elseif L > Lm And C < Cm And R < Rm Then
Lcd "Slant left turn"
Pwm1b = 70
Portd.3 = 0
Pwm1a = 170
Portd.6 = 0

Elseif L < Lm And C < Cm And R > Rm Then
Lcd "Slant right turn"
Pwm1b = 170
Portd.3 = 0
Pwm1a = 70
Portd.6 = 0

Elseif L > Lm And C > Cm And R < Rm Then
Lcd "Sharp left turn"
Pwm1b = 0
Portd.3 = 0
Pwm1a = 170
Portd.6 = 0

Elseif L < Lm And C > Cm And R > Rm Then
Lcd "Sharp right turn"
Pwm1b = 170
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0

Elseif L < Lm And C < Cm And R < Rm Then
Lcd "Stop"
Pwm1b = 0
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0

End If
Loop
End


More articles: Visual basic

Comments

Author: ravi kaushik27 Jul 2011 Member Level: Silver   Points : 1

Thanks Tousif. About compiler if you are making the program in visual basic than BASCOM-AVR and if embedded C than AVR-Studio.

I used AVR DUDE in order to burn the hex file on the microcontroller



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: