Line Following Robot
Line Following Robot
Line Following Robot
MINIPROJECT DOCUMENTATION
1
TABLE OF CONTENTS
1. PROJECT INTRODUCTION
1.1 Introduction/Application areas
1.2 Required Components and Equipments.
2. DESIGN
2.1 Block Diagram and Description
2.2 Schematic
2.3 Board File
3. PROGRAMMING
3.1 Explanation of special pur pose registers
3.2 Code
4. TOOLS USED
4.1 AVR studio/Win AVR/AVRGCC
4.2 C Code
5. CONCLUSION
2
1. PROJECT INTRODUCTION
1.1 INTRODUCTION
APPLICATION AREAS:
PREREQUISITES:
3
1.2 REQUIRED COMPONENTS AND EQUIPMENTS
Microcontroller Atmega 85 15
Roboco n Kit.
IR Sensors
RS-232 Cable.
4
2. DESIGN
SAMPLE TRACK
5
DESCRIPTION
INPUT SYSTEM:
Sensor Circuit:
General Description:
7
Overview of Schematic:
The 555 is used as a astable multivibrator. The frequency of the 555 is tuned
using the potentiometer. The outputof 555 is given to the IR transmitter.
TSOP detects a freq uency o f 38 KHz. The output of TSOP goes low when it
receives this frequency. Hence t he output pin is normally high because,
though the IR LED is co ntinuouslytransmitting, due to no white line,
nothing is reflected back to the TSOP. The indication LED is off.When an
white line is encountered, the output o f TSOP goes low, as the required
frequency is reflected fro m the white line. This o utput is connected to the
cathode of the LED, which then t urns ON.
INFRA-RED SENSOR
Introduction
8
An LED is usually a small area source, often with extra optics added
to the chip that shapes its radiation pattern. LED's are often used as small
indicator lights on electro nic devices and increasingly in higher power
applicatio ns such as flashlights and area lighting. The color of t he emitted
light depends o n the composition and condition of t he semiconducting
Example:
R1 = 10K
R2 = 10k
C1 = 100uF
F = ~ 0.48 Hz
T= ~ 2 sec
This generates an outp ut pulse with a time period 2sec.
9
555IC as an AstableMultivibrator
TSOP Module
Description
10
can directly be decoded by a microprocessor. TSOP17..is the standard IR
remote contro l receiver series, supporting all major transmission codes.
Block Diagram
11
Working of IR Sensor
12
PROCESSING SYSTEM:
Micro Controller:
CMOS 8-bit microco ntroller with 8 K bytes of flash memory. Its high density
non-volatile memory compatible with standard AVR instruction set makes
it a powerful controller that pro vides highly flexible and cost effective
solutio n to contro l app licatio ns.Micro -cont roller wo rks according to the
program written in it. Micro-contro llers are “embedded” inside some other
device so that they can control the features or actions of the prod uct.
Anot her name for a micro -controller therefore is “embedded controller”.
Micro-co ntrollers are dedicated to o ne task and run one specific pro gram.
13
Features
• RISC Architecture
– 130 Powerful Instructions – Most Single Clock Cycle Execution
– 32 x 8 General Purp ose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-chip 2-cycle Multiplier
• Peripheral Features
– One 8-bit Timer/Counter with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Capture mode
– Three PWM Channels
– Pro grammable Serial USART
– Master/Slave SPI Serial Interface
– Pro grammable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analo g Comparator
• Operating Voltages
– 4.5 - 5.5V for ATmega8515
• Speed Grades
– 0 - 16 MHz for ATmega8515
Motor Drivers are the ICs used to drive motors when interfaced with
Microcontrollers. These ICs give a higher voltage output ranging from 4.5V
to 36V for logic 1 input. The mo tor driver ICs generally used L293D,
ULN2003 series, etc.
These ICs are used to drive bot h DC mo tors and stepp er motors.
L293D IC
The L293 and L293D are quadrup le high -current half-H drivers. The
L293 is designed to pro vide bidirectio nal drive currents of up to 1 A at
15
All inp uts are TTL compatible. Each output is a complete totem-po le
drive circuit, with a Darlington transistor sink and a pseudo-Darlingto n
source. Drivers are enabled in pairs, with drivers 1 and 2 enabled b y 1,2EN
and drivers 3 and 4 enabled by 3,4EN. When an enable input is high, the
associated drivers are enabled and their outputs are active and in phase with
their inputs. When the enable input is lo w, those drivers are disabled and
their outputs are off and in the high-impedance state. With the proper data
inputs, each pair of drivers forms a full-H (or brid ge) reversible d rive
suitable for solenoid o r moto r applications. On the L293, external high -
speed output clamp diodes should be used for inductive transient
suppression. A VCC1 terminal, separate from VCC2, is provided fo r the
logic inputs to minimize device power dissipation. The L293 and L293D are
16
Pin Diagram
Block Diagram
17
Circuit Diagram
NOTE
Here the inp ut pins 2, 7 and their respective output p ins 3, 6 are enabled by
enabling EN1 i.e. giving vcc to pin 1
Similarly, t he input pins 10, 5 and their respective p ins 11, 4 are enabled by
enabling EN2 i.e. giving vcc to p in 9.
18
SERIAL COMMUNICATION:
19
20
USART:
Registers).
• Asynchronous or Synchronous Operation.
• Master or Slave Clocked Synchro nous Operatio n.
• High Resolution Baud Rate Generator.
• Suppo rts Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits.
• Odd or Even Parity Generation and Parit y Check Supported by Hardware.
21
AVR USART vs. AVR UART –Compatibility:
However, the receive buffering has two impro vements that will affect
the compatibility in some special cases like
•A second Buffer Register has been added. The two Buffer Registers
operate as acircular FIFO b uffer. Therefore the UDR must o nly be read once
for eachincoming data. More important is the fact that the Error Flags (FE
and DOR) and the ninth data bit (RXB8 ) are buffered wit h t he data in the
receive b uffer. Therefore the status b its must always be read before the UDR
Register is read. Otherwise the erro r status will be lost since the buffer state
is lost.
•The Receiver Shift Register can now act as a third b uffer level. This is done
byallowing the received data to remain in t he serial Shift Register (see
Figure 64) if the Buffer Registers are full, until a new start bit is detected.
The USART is therefore more resistant to Data Overrun (DOR) error
cond itions.
The following control bits have changed name, but have same functionality
and register location:
22
• CHR9 is changed to UCSZ2
• OR is changed to DOR
Table: 2.5.2 Calculation of baud rate and UBRR value as per Operating modes
23
Note: 1. The baud rate is defined to be the transfer rate in bit per second
(bps).
BAUD Baud rate (in bits per second, bps)
fOSC System Oscillator clock frequency
UBRR Co ntents of the UBRRH and UBRRL Registers, (0 -4095)
24
BOARD DIAGRAM:
25
2.2 SCHEMATIC:
26
2.3 BOARD:
Bit 7 RXC : receive comp lete ; bit is set when unread data is in receiver
buffer
Bit 5 UDRE: UART Data Register Empty
28
The UCSRC Register shares the same I/O locatio n as the UBRRH Register.
29
INC Rd Increment Register Rd = Rd + 1 Z,N,V,S 1
DEC Rd Decrement Register Rd = Rd -1 Z,N,V,S 1
TST Rd Test for Zero or Negative Rd = Rd · Rd Z,C,N,V,S 1
CLR Rd Clear Register Rd = 0 Z,C,N,V,S 1
SER Rd Set Register Rd = $FF None 1
SBIW Rdl,K6 Subtract Immediate from Word Rdh:Rdl = Rdh:Rdl - K 6 Z,C,N,V,S 2
Branch Instructions:
31
ST -X,Rr Store Indirect and Pre-Decrement X=X-1, (X)=Rr None 2*
ST Y,Rr Store Indirect (Y) = Rr None 2*
ST Y+,Rr Store Indirect and Post-Increment (Y) = Rr, Y=Y+1 None 2
ST -Y,Rr Store Indirect and Pre-Decrement Y=Y-1, (Y) = Rr None 2
ST Y+q,Rr Store Indirect with displacement (Y+q) = Rr None 2
ST Z,Rr Store Indirect (Z) = Rr None 2
ST Z+,Rr Store Indirect and Post-Increment (Z) = Rr, Z=Z+1 None 2
ST -Z,Rr Store Indirect and Pre-Decrement Z=Z-1, (Z) = Rr None 2
ST Z+q,Rr Store Indirect with displacement (Z+q) = Rr None 2
LPM None Load Program Memory R0 = (Z) None 3
IN Rd,P In Port Rd = P None 1
OUT P,Rr Out Port P = Rr None 1
PUSH Rr Push register on Stack STACK = Rr None 2
POP Rd Pop register from Stack Rd = STACK None 2
32
CLN None Clear negative flag N=0 N 1
SEZ None Set zero flag Z=1 Z 1
CLZ None Clear zero flag Z=0 Z 1
SEI None Set interrupt flag I=1 I 1
CLI None Clear interrupt flag I=0 I 1
SES None Set signed flag S=1 S 1
CLN None Clear signed flag S=0 S 1
SEV None Set overflow flag V=1 V 1
CLV None Clear overflow flag V=0 V 1
SET None Set T-flag T=1 T 1
CLT None Clear T-flag T=0 T 1
SEH None Set half carry flag H=1 H 1
CLH None Clear half carry flag H=0 H 1
NOP None No operation None None 1
SLEEP None Sleep See instruction manual None 1
WDR None Watchdog Reset See instruction manual None 1
33
4.TOOLS USED:
Introduction to AVR
tasks.
34
Save and Open Projects
All projects are saved with yo ur selected name with the ending APS .
When the user wants to reopen a pro ject, this can be done under the file
menu and the recent ly used file list, or under the project menu, open project.
After build ing, assembling o r compiling the project, the build output
window prompts with messages. If any errors occur, the user can double-
click on the message, and the marker will show correct position in the source
window.
Startup wizard
click on the wanted project and it will automatically open and restore to its
last settings.
New project
35
The following screen opens up:
36
Click on New Project tab in the pop-up windo w and the following screen
opens up.
37
Click on AVR GCC in Project .
The following screen opens up. Type in the name of your project –
myleds. Check the boxes ‘Create file’ and ‘Create Folder’. Creating
separate folders for d ifferent pro jects will help you maintain them properly.
Since the folder does not exist, AVR Studio will pro mpt you saying, the
folder does not exist and it will create a new folder. Say ‘yes’ to this prompt.
Click on Finish .
38
Device selection
We have to select which device we are going to use , in this project
we use AVR Simulator as debug platform and AT mega 8515 as device.
39
AVR Stud io creates a folder called myleds in the path specified by
you and a project named myleds.aps and a source file named myleds.c
Key in t he blinking.c program. Click o n the File Save icon. Now you
have written Ccode, you need to compile the p rogram. For this, you need to
select the microcontroller and the sp eed at which it works. The
microcontroller we are using is ATmega8515 and the speed at which it is
working is 8MHz .These two parameters are set as follows in the Project
Options in Device and Frequency optio ns.
40
The Project Options screen opens up by clicking on the Edit Current
ConfigurationOptions ico n.
41
Now, that we have set the Project Options, we will comp ile it. This can be
done by clicking on the Build Active Configuration icon.
When the Build is successful, you are intimated that the Build has gone
through with 0 warnings. This display will be in the Build Window.
42
If there are errors, you will need to correct those and do a Build again. The
Build will create many files, but the one we are interested in will be the
.hex file. This is a file whichcan be downloaded to the GRIET trainer kit and
executed
Generally the program for the required application is written in edit plus and
stored with ‘.c’ extension. The WINAVR cd provides some example
programs. Fro m that copy any one o f the bat file (generally they are with
.bat extension).
Let the program written by us be name.c .Now copy any one of bat file
provided in WINAVR cd and replace its name by name.bat. Now editing has
to be done by rep lacing led by name and now the batch file looks like
AVR-gcc-g-oc-mmcu=atmega85 15 -c-name.c
AVR-gcc-g--mmcu=atmega8515-c-o name.out,name.o
AVR-objcopy-j.text-O ihex name.outname.hex
The batch file created can be run by doub le clicking it and thereb y we find
3 files name.hex,name.out,name.o. Now o pen the AVRstudio software and
click o n the tools b utton as shown in the figure above (only after connecting
the b oard to the cpu). The AVRPROG soft ware comes with one o f the tools
supplied with AVRstud io.
If the board is
not connected
properly we wil
receive a
message as
follows:
43
This message ind icates
that the board is not
detected. Check once
again the connector and
reset the IC properly (the
IC can be reset by
44
Program to toggle the LEDs
#include<avr/io.h>
void main()
{
inti,j;
DDRD=0xff; //to make port d o utput for LEDs
PORTD=0xff; //making all LEDs Off
while(1)
{
}
}
45
Program for Buzzer
#include<avr/io.h>
void main()
{
unsigned char status;
inti,j;
DDRD=0xff; //making as output for buzzer
PORTD=0Xff; //internal pull ups
while(1)
{
PORTD=0xef; //buzzer switched off
for(i=0;i<200;i++)
for(j=0;j<200;j++);// delay
PORTD=0xff; //buzzer on
for(i=0;i<200;i++)
for(j=0;j<200;j++);
}
}
46
Program for Motor
/* pro gram for driving the motor in forward and reverse directions
motor1 are connected to portb p ins 0 and 1
differential input to the pins causes the motor to rotate*/
#include<avr/io.h>
void main()
{
inti,j;
DDRB=0xff; //for driving the motors making the portb as outp ut.
PORTB=0xff; //internal pull ups
while(1)
{
PORTB=0 xaa; //mak ing motor turn in forward directio n
for (i=0; i<10000;i++)
for(j=0;j<10000;j++); //delay
PORTB=0 x55; //making motor turn in reverse direction
for (i=0; i<10000;i++)
for(j=0;j<10000;j++);
}
}
47
Program for Sensors
#include<avr/io.h>
void main()
{
{
status=PINA;
PORTD=0xff; //making LEDs off
if((status&(0x07))==0x00)
PORTD=0x3f; //making LEDs on
}
}
48
Programs to interface sensor and motors
#include<avr/io.h>
#include<avr/delay.h>
void delay();
void main()
{
DDRB=0xff;
DDRA=0x00;
{
if((PINA&0x01)==0x00)
{
PORTD=0x3f;//leds and buzzer on
PORTB=0 x11;//left
delay();
PORTB=0xaa;//forward
49
delay();
PORTB=0 x22;//right
delay();
PORTB=0 xaa;//forward
delay();
PORTD=0xef;//leds and b uzzer off
}
else PORTB = 0xaa;
}
}
void delay()
{
int i,j;
for(i=0;i<6000;i++)
for(j=0;j<6000;j++);
}
50
4.2 C CODE:
#include<avr/io.h>
int main()
{
DDRA=0x00; //Sensor Input
DDRB=0xff; //Motor Output
DDRC=0x00; //Switches Input
DDRD=0xff; //Leds,Buzzer Output
PORTA=0xff;
PORTC=0xff;
while(1)
{
if(!(PINC&0x02))
{
51
goto x;
}
}
x: while(1)
{
while((PINA&0x03)==0x03) //STRAIGHT
{
{
PORTB=0x50;
}
}
while((PINA&0x03)==0x00) //STOP
{
{
PORTB=0x00;
}
}
if((PINA&0x03)==0x01) //RIGHT
{
PORTD=0x10; //Buzzer ON
52
while((PINA&0x03)==0x01)
{
PORTB=0x40;
}
PORTD=0xC0; //Buzzer OFF
}
if((PINA&0x03)==0x02) //LEFT
{
PORTD=0x10; //Buzzer ON
while((PINA&0x03)==0x02)
{
PORTB=0x10;
}
PORTD=0xC0; //Buzzer OFF
}
}
}
53
CONCLUSION:
It has been a great learning experience working o n our project - The Line
Follower. In this new age where the effort o f man is min imized by using
machines, the emergence of robo ts has helped improve many facets of life.
The line follower is one of those simple
yet efficient robots which are extensively used in developed industries in
transporting goods to and fro along a specific path which inturn lessens the
burden of the workers and improves the working of the ind ustry.
The main aim of o ur project was to
develo p a miniature linefollower in which we have succeeded. We look
forward to develop an industry oriented line follower where it can help
increase the efficiency of the industry.
54