You are on page 1of 31

Building a Line Tracking Bot

with Collision Detection


Sample of Line Tracker Bot System
Line
sensor3
Object
detection
sensor Motor
Controller Motor
driver

Line Line
sensor1 sensor2

There are more examples from the


internet.
You can google it up or find the action at
YouTube.
Come up with your one idea.

Saturday, 11 August 2007 eleem383@gmail.com


The Controller

PIC16F877A
Relatively cheap
Easy to get
33 I/Os –quite a lot
All required features
needed are included

Saturday, 11 August 2007 eleem383@gmail.com


Basic PIC16F877A Circuit with Bootloader
and Serial Communication capability

Saturday, 11 August 2007 eleem383@gmail.com


The components
C1 470u electrolytic capacitor
C2 0.1uF ceramic/tantalum capacitor
C3 18p ceramic/tantalum capacitor
C4 18p ceramic/tantalum capacitor
IC1 PIC16F87x uController (don't forget the 40-pin DIL socket)
IC2 7805 voltage regulator
IC3 74HCT04 hex inverter (don't forget the 14-pin DIL socket)
LED1 3mm LED
Q1 20MHz CRSYTAL
R1 1k resistor
R2 10k resistor
S1 tack-switch
S2 toggle switch
X1 power supply
X2 DB9 Female 9-way serial port connector

Saturday, 11 August 2007 eleem383@gmail.com


1st program:
A simple output - LED

LEDs are connected to


pins of portB
A concept of digital
output.
Instead of LEDs, you
can connect to directly
to other TTL devices.

Saturday, 11 August 2007 eleem383@gmail.com


Programming example:
A simple output – LED pattern
The PIC uC used

The clock/oscillator frequency

PIC uC mode

Saturday, 11 August 2007 eleem383@gmail.com


CCS PCW
PIC C-compiler
Compiler used – CCS PCW PIC C-compiler
Simplifies coding of the µC.
Save the users from ‘register’ setups.
You can get the compiler from MCT lab. Please ask Mr.
Fahmi for a copy.
After compiling, the compiler will create a .HEX file. This
is the file that will be loaded into the uC.

Saturday, 11 August 2007 eleem383@gmail.com


Loading the code into the uC
We will load the code through a
bootloader method.
Before using this method, you
need to make sure that the uC
has been loaded with the
bootloader firmware.
Fresh uC ICs bought do not
contain this hardware.
Further explanation about this
later on.
For now, assume that the uC
has already been loaded with
the bootloader firmware.
We are current interest is the
PICBoot+

Saturday, 11 August 2007 eleem383@gmail.com


Line Tracker Bot: Line Sensor

Components: Super/Ultra bright LED, LDR as


detectors, and resistors.

Saturday, 11 August 2007 eleem383@gmail.com


Analog Inputs

Saturday, 11 August 2007 eleem383@gmail.com


Line Sensor

Actually, 1 set of transceiver (transmitter and receiver) is capable to make the bot to track the
line.
More transceiver sets would improve the tracking capability –increase speed (2nd objective in
line tracking after tracking itself)
However, coding would become considerably complex.
Google it up to find the various combinations.

Saturday, 11 August 2007 eleem383@gmail.com


Programming: Defining the serial
communication

Reading
analog input
and printing Defining the serial
communication

via serial
comm.
•Select particular ADC channel Printing to the serial
comm.
•Delay for electrical reasons
•Read that particular ADC channel

Saturday, 11 August 2007 eleem383@gmail.com


Note
Please refer to the PIC MCU C Compiler Reference Manual by CCS
for further information on analog input commands.
also available at ‘Help’ of PICC Compiler software

Saturday, 11 August 2007 eleem383@gmail.com


Displaying serial com on screen

The serial communication


is using the same line as
the one we used by the
bootloader software to
load the program.

Analog values should


be displayed here.

Saturday, 11 August 2007 eleem383@gmail.com


Note

The target here is to differentiate between


the line and the surface. The intensity
between the line and floor surface will
differ.
By that, you will have to set a certain value
(threshold) as a point that differentiates
the intensity on the line and the floor.
I will leave that for you to figure out.

Saturday, 11 August 2007 eleem383@gmail.com


Collision Detection > switch

Must be set up in the


following configuration.
The pull-up circuit.
Or else, it will give false
reading.
Reasoning: as if you want
to know ^.^
When switch is pushed,
output is ‘0’ or GND.
When switch is NOT
pressed, output is ‘pulled
up’ to ‘+5V’.

Saturday, 11 August 2007 eleem383@gmail.com


Programming example: Digital Input

Saturday, 11 August 2007 eleem383@gmail.com


SumoBot: The motors

DC motor with
Tamiya twin gearbox
used.
Cheap
Available
Easy mounting

Saturday, 11 August 2007 eleem383@gmail.com


Driving the motors
The motor driver used
here is the L293B.
Refer L293 datasheet for
more information on how
to operate.
RC2/CCP2 and
RC3/CCP3 are reserved to
control motor speed (using
PWM).
Other connections can be
changed up to the robot
builder.

Saturday, 11 August 2007 eleem383@gmail.com


Programming example:
Motor control

Saturday, 11 August 2007 eleem383@gmail.com


Programming example:
Motor control

Saturday, 11 August 2007 eleem383@gmail.com


The line following concept

There are a lot of examples out there in the world wide web.
Some sites:
http://robotroom.com/
http://www.wrighthobbies.net/guides/linefollower.htm

Saturday, 11 August 2007 eleem383@gmail.com


Going a little further

Controllers
Code download
Inputs
Outputs
PIC16F87x Series

Pin layouts differ between the 876 and


877.
Please refer to the datasheet (available
online) for the pin layout.
The layouts differ but some notations and
function remain. Again please have a look
at the datasheet.

Saturday, 11 August 2007 eleem383@gmail.com


Code Transfer

From current knowledge – 2 methods


ICSP (In-Circuit Serial Programming) –some
call it as the ‘burner’
Bootloader

Saturday, 11 August 2007 eleem383@gmail.com


ICSP

Can call it as a hardware programmer


Available at uC lab and MCT lab. The programmer at MCT lab however is not working properly.
Different manufacturers have different software to drive the ICSP
You can construct your own if you want to. –JDM programmer
At uC lab, the programmer is by FED. Please ask the lab assistant there.
At MCT lab, programmer is called the JDM programmer –its free -
Saturday, 11 August 2007 eleem383@gmail.com
ICSP –JDM Programmer

‘Search for JDM Programmer 2’


Saturday, 11 August 2007 eleem383@gmail.com
Bootloader – a description
A bootloader is a program that stays in the
microcontroller and communicates with the PC
(usually through the serial interface).

The bootloader receives a user program from the PC and


writes it in the flash memory, then launches this
program in execution.

Bootloaders can only be used with those


microcontrollers that can write their flash memory
through software.

The bootloader itself must be written into the flash


memory with an external programmer.

In order for the bootloader to be launched after each


reset, a "goto bootloader" instruction must exist
somewhere in the first 4 instructions;

There are two types of bootloaders, some that require


that the user reallocate his code and others that by
themselves reallocate the first 4 instructions of the
user program to another location and execute them
when the bootloader exits.

Ref: http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
Saturday, 11 August 2007 eleem383@gmail.com
Bootloader
Works on a firmware basis, not hardware.
Faster
Does not have to be removed
The same configuration can be used as serial
communication.
Hex inverter acts as the buffer/converter between
the PC’s serial communication (RS232) and the
PIC’s internal serial communication (UART)
Hex inverter used as cheap substitute of the
MAX232 IC.
Don’t forget the socket for the IC!
The currently used – PICBoot+ (can use others –
if you want to)
Need to load the firmware first – using ICSP – a
one time operation (as long as your uC is not
damaged ^^)
Download software and firmware from below.

Ref: http://www.microchipc.com/PIC16bootload/
Saturday, 11 August 2007 eleem383@gmail.com
Using the ICSP –JDM Programmer

Saturday, 11 August 2007 eleem383@gmail.com

You might also like