line tracing robot
TRANSCRIPT
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
BLACK LINE TRACER AND OBSTACLE AVOIDANCE
AUTONOMOUS ROBOT
Mini Project Report Submitted
By
DON MATHEW
In partial fulfilment of Sixth semester of
Bachelor of Technology
In
ELECTRONICS AND COMMUNICATION
OF
COCHIN UNIVERSITY OF SCIENCE AND TECHNOLOGY
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
COLLEGE OF ENGINEERING, POONJAR
KOTTAYAM-686 582
E-mail:-:[email protected]
Website:-http://www.cep.ac.in
Dept of Electronics and Communication College of Engineering Poonjar
1
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
ABSTRACT
Robotics is the science and technology of robots, their design, manufacture, and
application. Robotics requires a working knowledge of electronics, mechanics, and software.
Although the appearance and capabilities of robots vary vastly, all robots share the features of
a mechanical, movable structure under some form of autonomous control. This project
develops a line follower robot that detects a line drawn on a plain surface and moves through
it. The path can be visible like a black line on a white surface (or vice-versa) or it can be invisible
like a magnetic field. Sensing the line and constantly correcting wrong moves using feedback
mechanism forms an effective yet complex closed loop system. The robot also works on
another mode in which it detect and avoid the obstacles on the path. In this mode the
robot choose another path for its movement when an obstacle is detected. The user has the
option of setting the modes in which the robot should manure. The project implements line
tracking techniques and obstacle avoidance in microcontroller based embedded system. The
system also controls the motors that moves the robot through its path.
Dept of Electronics and Communication College of Engineering Poonjar
2
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
CONTENTS
1. INTRODUCTION 01
2. REQUIREMENTS FOR THE PROJECT 02
3.1 HARDWARE REQUIREMENTS 02
3.2 SOFTWARE REQUIREMENTS 02
3. BLOCK DIAGRAM 03
4. BLOCK LEVEL DESCRIPTION 04
5. CIRCUIT DIAGRAM 05
6. DESIGN 06
7. CIRCUIT PARTS 07
7.1 REGULATED POWER SUPPLY 09
7.2 MOTION CONTROL 09
7.3 H-BRIDGE MOTOR CONTROL 10
7.4 IR SENSOR 18
7.5 COMPARATOR 18
7.6 D.C. MOTORS 19
8. WORKING 20
9. PCB LAYOUT 21
10. FLOW CHART 23
11. PROGRAM CODE24
12. APPLICATIONS 32
13. FUTURE SCOPES 32
Dept of Electronics and Communication College of Engineering Poonjar
3
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
14.LIMITATIONS 32
15. RESULTS AND CONCLUSIONS 33
16. BIBLIOGRAPHY 34
Dept of Electronics and Communication College of Engineering Poonjar
4
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
1. LIST OF FIGURES
Figure 1 Block Diagram 07
Figure 2 Circuit Diagram 10
Figure 3 Block Diagram of Regulated Power Supply 13
Figure 4 Regulated Power Supply Circuit Diagram 14
Figure 5 L293D Block Diagram 15
Figure 6PIC 16F877A 17
Figure 7 IR sensor25
Figure 8 PCB Layout 30
Figure 9PCB Layout 31
Figure 10Flow chart 33
Dept of Electronics and Communication College of Engineering Poonjar
5
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
1. INTRODUCTION
The word "robot" originates from the Czech word for forced labour or serf. Robots are
electronic devices intended to perform a desired function. Many refer to them as "machines",
however, a drill press is a machine, yet it requires an operator to perform its function, where
robots can be programmed to do it themselves. Robots have the potential to change our
economy, our health, our standard of living, our knowledge and the world in which we live.
Robotics is not only a science, but it is also an art. There are many different versions of robots
that can be made.
The Line follower robot is a mobile machine that can detect and follow the line drawn on the
floor. Generally, the path is predefined like a black line on a white surface Therefore, this kind
of Robot should sense the line with its Infrared Ray (IR) sensors that installed under the robot.
After that, the data is transmitted to the processor by specific transition buses. Hence, the
processor is going to decide the proper commands and then it sends them to the driver and
thus the path will be followed by the line follower robot. If there is any obstacle on the path of
the robot, it takes a deviation.
Dept of Electronics and Communication College of Engineering Poonjar
6
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
2. REQUIREMENTS FOR THE PROJECT
Both hardware and software are required for the successful completion of the project
2.1 HARDWARE REQUIREMENTS
Hardware requirements include
PIC 16F877A: It is a 40 pin microcontroller chip Bridge Rectifier: Used in power supply LM 7805: Voltage regulator Crystal oscillator: 4 MHZ for clock signal generation Tact switch: Used for resetting PIC and mode selection Resistors: Various ranges of carbon resisters are required
10K, 1K, 4.7K, 100Ω, 220Ω, 470 Ω Capacitors: Various electrolytic & paper capacitors are used
0.1µF, 100µF, 1000µF, 22pF Transistors: BC547 Sensors: TSOP 1738, IR LED, Photodiode Motor control: L293D is used Comparator: LM358N for deriving digital outputs Motor: BO Motor 45 rpm Tyre Castor wheel: for sliding over the surface
2.2 SOFTWARE REQUIREMENT
Software requirements include
MicroC Simulation software PICkit 2 v2.61
3.BLOCK DIAGRAM
Dept of Electronics and Communication College of Engineering Poonjar
7
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
IR LIGHT
SURFACE
LEFT LINE MIDDLE LINE RIGHT
SENSOR SENSOR SENSOR SENSOR SENSOR
PIC 16F877A
MOTOR
DRIVER
MOTOR MOTORFigure 1
Dept of Electronics and Communication College of Engineering Poonjar
8
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
4.BLOCK LEVEL DESCRIPTION
The PIC microcontroller requires a +5V voltage supply and for other section of the circuit too. So a related dc voltage of 5V can be delivered from the 230V supply. The 230V supply is step downed to an appropriate value and after that it is rectified and regulated by IC 7805 voltage regulator. In order to facilitate high emission we employ IR LEDs. The rays emitted by these LEDs incident on the surface on which the line is drawn. The various operation of the system is controlled by software that is embedded in the PIC. We use PIC16F877A microcontroller due to its high number of I/O pins. It also employs more number of registers. The two line sensors track the path and the left, middle and right obstacle sensor senses the obstacle. The output from the line sensor and obstacle sensor is given to the PIC. Motor moves according to the instructions from the PIC.
5. CIRCUIT DIAGRAM
Dept of Electronics and Communication College of Engineering Poonjar
9
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
Figure 2
6. DESIGN
Dept of Electronics and Communication College of Engineering Poonjar
10
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
PIC 16F877A, the central controller operates at 5v. The control IC for motor , L293D has an operating voltage of 9V.So these voltage levels are produce from a 230V ac supply by a 230V:9V transformer followed by two 9V and 5V dc regulators. The operating voltageof all other sections are hence divided at 5V. The value for resistance affects the source IR brightness ,for maximum brightness we set resistance to give the maximum allowable forward current for the IR led. For the proper operation point of IR LED current required is .051 A critically. So we connect a resistor R1 in series with LED for proper current control. The IR detector operates with proper light sensing at an operating current value equal to 0.05 A. So resistance to be connected in series with IR detector is R=V/I=5/0.05=100Ω .When operated at a current of 0.5mA BC547 operates at the quiescent value. So resistance series with BC547 is 5V/0.5mA =10R. PIC 16F877A operates at a clock frequency of 20 MHz (use 4MHz).
6.1 VOLTAGE REGULATOR
o To maintain a constant dc output voltage.
o It also rejects any ac ripple voltage that is not removed by the filter.
o It includes protective features such as short circuit protection, current limiting, thermal shutdown, or over-voltage protection.
The 230v ac mains input is stepped down to 12v and fed to Bridge rectifier input. The rectified output is pulsating and is fed to the capacitive filter for smoothening. To obtain regulated output a voltage regulator IC (LM7805) is used. Hence 5v dc regulated output is obtained. But here in robot for mobile applications we use a battery source of 9v or 12v which is directly given to LM7805 voltage regulator and the required 5v is obtained. Otherwise for testing and development process of the robot we can use the circuit with direct ac input into the transformer.
6.2 MOTION CONTROL
Dept of Electronics and Communication College of Engineering Poonjar
11
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
This is done with help of output commands from PIC microcontroller. IC L293D is used to drive the 45rpm motor as the PIC can’t directly drive 12v motors. L293D - The Device is a monolithic integrated high voltage, high current four channel driver designed to accept standard DTL or TTL logic levels and drive inductive loads and switching power transistors. To simplify use as two bridges each pair of channels is equipped with an enable input. This device is suitable for use in switching applications at frequencies up to 5 kHz
7.CIRCUIT PARTS
7.1 REGULATED POWER SUPPLY:
Transformer Rectifier Filter Voltage regulator
Block diagram of regulated power supply
Figure 3 Transformer
o Used for voltage transformation.o Step-down transformer used for down-conversion of ac line voltage to a smaller
peak voltage.o Step down in voltage achieved by decreasing the voltage and proportionally
increasing the current.
Rectifiero Converts the sinusoidal ac voltage into either positive or negative pulsating dc.
Dept of Electronics and Communication College of Engineering Poonjar
12
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
o P-N junction diode, which conducts when forward biased and practically does not conduct when reverse biased, can be used for rectification.
o Rectifiers may be either half-wave rectifiers or full-wave rectifiers (centre-tap or bridge) type.
o Bridge rectifier is used because output for the entire cycle of input voltage is obtained.
Filtero To reduce ac components from the rectifier output voltage.o Capacitive filters are used with less charging time and more discharging time.o The RC charge time of the filter capacitor must be short and the RC discharge
time must be long to eliminate ripple action when using this filter. In other words, the capacitor must charge up fast with preferably no discharge at all.
The entire process of rectification and filtering is obtained using a 1A Bridge IC.
Voltage regulatoro To maintain a constant dc output voltage. o It also rejects any ac ripple voltage that is not removed by the filter. o It include protective features such as short-circuit protection, current limiting,
thermal shutdown, orover-voltage protection.
Regulated power supply circuit diagram
Figure 4
The 230v ac mains input is stepped down to 12v and fed to Bridge rectifier input. The rectified optput is pulsating and is fed to the capacitive filter for smoothening. To obtain regulated
Dept of Electronics and Communication College of Engineering Poonjar
13
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
output a voltage regulator IC (LM7805) is used. Hence 5v dc regulated output is obtained. But here in robot for mobile applications we use a battery source of 9v or 12v which is directly given to LM7805 voltage regulator and the required 5v is obtained. Otherwise for testig and development process of the robot we can use the circuit with direct ac input into the transformer.
7.2 MOTION CONTROL:
This is done with help of output commands from PIC microcontroller. Here an ic L293D is used to drive the 45rpm geared motor as the PIC can’t directly drive 12v motors.
L293D - The Device is a monolithic integrated high voltage,high current four channel driver designed to accept standard DTL or TTL logic levels and drive inductive loads and switching power transistors.To simplify use as two bridges each pair of channels is equipped with an enable input. A separate supply input is provided for the logic, allowing operation at a lower voltage and internal clamp diodes are included. This device is suitable for use in switching applications at frequencies up to 5 kHz.
Figure 5
7.3 H-BRIDGE MOTOR CONTROL
DC motors are generally bi-directional motors. That is, their direction of rotation
Dept of Electronics and Communication College of Engineering Poonjar
14
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
can be changed by just reversing the polarity. But once the motors are fixed, control
becomes tricky. This is done using the H-Bridge.
IN1 IN2 IN3 IN4 OPERATION1 0 1 0 BOTH MOTORS FORWARD (MOVES FORWARD)1 0 0 1 RIGHT MOTOR BACKWARD, LEFT MOTOR FORWARD (TURN RIGHT)0 1 1 0 RIGHT MOTOR FORWARD, LEFT MOTOR BACKWARD (TURN LEFT)
Dept of Electronics and Communication College of Engineering Poonjar
15
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
7.4 PIC 16F877A
Figure 6
a)Microcontroller Core Features:
• Only 35 single word instructions to learn
Dept of Electronics and Communication College of Engineering Poonjar
16
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
• All single cycle instructions except for program branches which are two cycle
• Operating speed: DC - 20 MHz clock input
• 8K × 14 word Flash program memory, 368×8 bytes RAM,
256×8 bytes of EEPROM Data Memory
• Direct, indirect and relative addressing modes
• Power-on Reset (POR)
• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation
• Programmable code protection
• Power saving SLEEP mode
• Selectable oscillator options
• Low power, high speed CMOS FLASH/EEPROM technology
• Fully static design
• In-Circuit Serial Programming (ICSP) via two pins
• Single 5V In-Circuit Serial Programming capability
• Processor read/write access to program memory
b)Peripheral Features:
• Port A: 6bit bidirectional port
• Port B , C,D: 8bit and Port E:3 bit bidirectional port
• Timer0: 8-bit timer/counter with 8-bit pre-scalar
• Timer1: 16-bit timer/counter with pre-scalar, can be incremented during
SLEEP via external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, pre-scalar and postscalar
• Two Capture, Compare, PWM modules (CCP modules)
• 10-bit, 5 - channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI (Master mode) and I2C
(Master/Slave)
Universal Synchronous Asynchronous Receiver
Dept of Electronics and Communication College of Engineering Poonjar
17
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
• Transmitter (USART/SCI) with 9-bit address detection
• Brown-out detection circuitry for Brown-out Reset (BOR)
c )MEMORY ORGANIZATION
There are three memory blocks in each of these PIC micro MCUs. The Program Memory and
Data Memory have separate buses so that concurrent access can occur. The third block is
EEPROM.
i )Program Memory Organization
The PIC16F87X devices have a 13-bit program counter capable of addressing an 8K x 14
program memory space. The PIC16F877/876 devices have 8K x 14words of FLASH program
memory. Accessing a location above the physically implemented address will cause a wrap
around. The reset vector is at 0000h and the interrupt vector is at 0004h.
ii )Data Memory Organization
The data memory is partitioned into multiple banks which contain the General Purpose
Registers and the Special Function Registers. Bits RP1 (STATUS<6>) andRP0 (STATUS<5>) are the
bank select bits. Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are
reserved for the Special Function Registers. Above the Special Function Registers are General
Purpose Registers, implemented as Static RAM. All implemented banks contain Special Function
Registers. Some “high use” Special Function Registers from one bank may be mirrored in another
bank for code reduction and quicker access.
d )DATA EEPROM AND FLASH PROGRAM MEMORY
Dept of Electronics and Communication College of Engineering Poonjar
18
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
The Data EEPROM and FLASH Program Memory are readable and writable during
normal operation over the entire VDD range. A bulk erase operation may not be issued from
user code (which includes removing code protection). The data memory is not directly mapped
in the register file space. Instead it is indirectly addressed through the Special Function
Registers (SFR). There are six SFRs used to read and write the program and data EEPROM
memory. EECON1, EECON2, EEDATA, EEDATH, EEADR EEADRH. The EEPROM data memory
allows byte read and writes. When interfacing to the data memory block, EEDATA holds the 8-
bit data for read/write and EEADR holds the address of the EEPROM location being accessed.
The registers EEDATH and EEADRH are not used for data EEPROM access. These devices have
up to 256 bytes of data EEPROM with an address range from 0h to FFh. The program memory
allows word reads and writes. Program memory access allows for checksum calculation and
calibration table storage. A byte or word write automatically erases the location and writes the
new data (erase before write). Writing to program memory will cease operation until the write
is complete.
i )Reading the Data EEPROM Memory
To read a data memory location, the user must write the address to the EEADR register,
clear the EEPGD control bit (EECON1<7>) and then set control bit RD (EECON1<0>). The data is
available in the very next instruction cycle of the EEDATA register; therefore it can be read by
the next instruction. EEDATA will hold this value until another read operation or until it is
written to by the user (during a write operation).
ii)Writing to the Data EEPROM Memory
To write an EEPROM data location, the address must first be written to the EEADR
register and the data written to the EEDATA register. The write will not initiate if the above
sequence is not exactly followed. It is strongly recommended that interrupts be disabled during
this code segment. Additionally, the WREN bit in EECON1 must be set to enable writes. This
mechanism prevents accidental writes to data EEPROM due to unexpected code execution (i.e.,
Dept of Electronics and Communication College of Engineering Poonjar
19
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
runaway programs). The WREN bit should be kept clear at all times, except when updating the
EEPROM. The WREN bit is not cleared by hardware.
e)I/O PORTS
Some pins for these I/O ports are multiplexed with an alternate function for the
peripheral features on the device. In general, when a peripheral is enabled, that pin may not be
used as a general purpose I/O pin.
f)PORTA and the TRISA Register
PORTA is a 6-bit wide bi-directional port. The corresponding data direction register is
TRISA. Setting a TRISA bit (=1) will make the corresponding PORTA pin an input (i.e., put the
corresponding output driver in a hi-impedance mode). Clearing a TRISA bit (=0) will make the
corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected
pin).Reading the PORTA register reads the status of the pins, whereas writing to it will write to
the port latch. All write operations are read-modify-write operations. Therefore, a write to a port
implies that the port pins are read; the value is modified and then written to the port data latch.
Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. The
RA4/T0CKI pin is a Schmitt Trigger input and an open drain output. All other PORTA pins have TTL
input levels and full CMOS output drivers. Other PORTA pins are multiplexed with analog inputs
and analog VREF input. The operation of each pin is selected by clearing/setting the control bits
in the ADCON1 register (A/D Control Register1). The TRISA register controls the direction of the
RA pins, even when they are being used as analog inputs. The user must ensure the bits in the
TRISA register are maintained set when using them as analog inputs.
g)PORTB and the TRISB Register
Dept of Electronics and Communication College of Engineering Poonjar
20
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register is
TRISB. Setting a TRISB bit (=1) will make the corresponding PORTB pin an input (i.e., put the
corresponding output driver in a hi-impedance mode). Clearing a TRISB bit (=0) will make the
corresponding PORTB pin an output (i.e., put the contents of the output latch on the selected
pin). Three pins of PORTB are multiplexed with the Low Voltage Programming function;
RB3/PGM, RB6/PGC and RB7/PGD. The alternate functions of these pins are described in the
Special Features Section. Each of the PORTB pins has a weak internal pull-up. A single control bit
can turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak
pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are
disabled on a Power-on Reset of PORTB’s pins, RB7:RB4, have an interrupt on change feature.
Only pins configured as inputs can cause this interrupt to occur (i.e. any RB7:RB4 pin configured
as an output is excluded from the interrupt on change comparison).The input pins (of RB7:RB4)
are compared with the old valuelatched .
h)PORTC and the TRISC Register
PORTC is an 8-bit wide, bi-directional port. The corresponding data direction register is
TRISC. Setting a TRISC bit (=1) will make the corresponding PORTC pin an input (i.e., put the
corresponding output driver in a hi-impedance mode). Clearing a TRISC bit (=0) will make the
corresponding PORTC pin an output (i.e., put the contents of the output latch on the selected
pin). PORTC is multiplexed with several peripheral functions (Table 3-5). PORTC pins have Schmitt
Trigger input buffers. When the I2C module is enabled, the PORTC (3:4) pins can be configured
with normal I2C levels or with SMBUS levels by using the CKE bit (SSPSTAT <6>).When enabling
peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some
peripherals override the TRIS bit to make a pin an output, while other peripherals override the
TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is
enabled, read-modify write instructions (BSF, BCF, XORWF) with TRISC as destination should be
avoided.
i)PORTD and TRISD Registers
Dept of Electronics and Communication College of Engineering Poonjar
21
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as
an input or output.
j)PORTE and TRISE Registers
This section is not applicable to the PIC16F873 or PIC16F876. PORTE has three pins,
RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7, which are individually configurable as inputs or
outputs. These pins have Schmitt Trigger input buffers. I/O PORTE becomes control inputs for the
microprocessor port when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make sure
that the TRISE<2:0> bits are set (pins are configured as digital inputs). Ensure ADCON1 is
configured for digital I/O. In this mode, the input buffers are TTL. Register 3-1 shows the TRISE
register, which also controls the parallel slave port operation. PORTE pins are multiplexed with
analog inputs. When selected as an analog input, these pins will read as ’0’s. TRISE controls the
direction of the RE pins, even when they are being used as analog inputs. The user must make
sure to keep the pins configured as inputs when using them as analog inputs
k)TIMER0 MODULE
The Timer0 module timer/counter has the following features: 8-bit timer/counter, Readable and
writable, 8-bit software programmable prescaler, Internal or external clock select, Interrupt on
overflow from FFh to 00h, Edge select for external clock. Timer mode is selected by clearing bit
T0CS (OPTION_REG<5>).Counter mode is selected by setting bit T0CS (OPTION_REG<5>). In
counter mode, Timer0 will increment either on every rising or falling edge of pin RA4/T0CKI. The
incrementing edge is determined by the Timer0 Source Edge Select bit T0SE (OPTION_REG<4>).
Clearing bit T0SE selects the rising edge. The TMR0 interrupt is generated when the TMR0
register overflows from FFh to 00h. This overflow sets bit T0IF (INTCON<2>). The interrupt can be
masked by clearing bit T0IE (INTCON<5>). Bit T0IF must be cleared in software by the Timer0
module interrupt service routine before re-enabling this interrupt.
i)Using Timer0 with an External Clock
Dept of Electronics and Communication College of Engineering Poonjar
22
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
When no prescaler is used, the external clock input is the same as the prescaler output.
The synchronization of T0CKI with the internal phase clocks is accomplished by sampling the
prescaler output on the Q2 and Q4 cycles of the internal phase clocks. Therefore, it is necessary
for T0CKI to be high for at least 2Tosc (and a small RC delay of 20 ns) and low for at least 2Tosc
(and a small RC delay of 20 ns).
l)TIMER1 MODULE
The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H and
TMR1L), which are readable and writable. The TMR1 Register pair (TMR1H:TMR1L) increments
from 0000h to FFFFh and rolls over to 0000h. The TMR1 Interrupt, if enabled, is generated on
overflow, which is latched in interrupt flag bit TMR1IF (PIR1<0>). This interrupt can be
enabled/disabled by setting/clearing TMR1 interrupt enable bit TMR1IE (PIE1<0>).Timer1 can
operate in one of two modes: As a timer and as a counter.
7.5 IR SENSOR
Dept of Electronics and Communication College of Engineering Poonjar
23
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
It consists of an infrared emitting diode (λ = 950nm) and a photodiode mounted to face
each other on a converging optical axis in a black plastic housing. The phototransistor responds
to radiation from the emitting diode only when no object is present within its field of view. This
sensor is physically modified so that the emitter and detector face the same direction and thus
the modified sensor serves the purpose of an optical-reflective sensor. The sensor has a focal
length of 8mm, thus the surface must be at an optimum distance of 1.6cm. The original and
modified sensors are shown below.
Figure 77.6 COMPARATOR
A comparator is a circuit which compares a signal voltage applied at one input of
an op-amp with a known reference voltage at the other input, and produces either a high
or a low output voltage, depending on which input is higher. The reference voltage is generated
by the 50k POT and given to all the comparators to the non-inverting input. When the
respective sensor is on the line, the emitted light is absorbed by the line and the transistor is
the cut-off mode, thus a potential of 4.6V is given to the inverting input which is greater than
Vref (which is chosen to be 2.5V), thus the output of the comparator goes low. When the
sensor is not on the line (reflective white surface) the potential across the detector is usually
0.6V. Thus the output of the comparator goes high (the non-inverting input has a greater
Dept of Electronics and Communication College of Engineering Poonjar
24
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
potential). Thus the output of the comparator goes low only when the sensor is over the line.
The comparator is open collector, and hence a pull-up resistor of 10 kΩis required at the
output.
7.7 D.C. MOTORS
DC motors are widely used, inexpensive, small and powerful for their size.Reduction
gearboxes are often required to reduce the speed and increase the torque output of the motor.
Unfortunately more sophisticated control algorithms are required to achieve accurate control
over the axial rotation of these motors. Although recent developments in stepper motor
technologies have come a long way, the benefits offered by smooth control and high levels of
acceleration with DC motors far outweigh any disadvantages. several characteristics are
important when selecting DC motors and these can be split into two specific categories. The
first category is associated with the input ratings of the motor and specifies its electrical
requirements, like operating voltage and current. The second category is related to the motor's
output characteristics and specifies the physical limitations of the motor in terms of speed,
torque and power.
7.8 CRYSTAL OSCILLATOR
The clock frequency is provided by one 4Mhz crystal which is connected acrossthe OSC1 & OSC2 pins. This provides an instruction execution time of 200ns.
8. WORKING
Dept of Electronics and Communication College of Engineering Poonjar
25
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
Common features required for line followers:
Follow a black line Stop if the line disappears Avoid an obstacle if present
The line following robot will need to see the line, therefore we require a light detector of some sort. Also the line follower robot needs to do this regardless of the ambient conditions. So the robot will also need its own illumination source.
The basic steps to be performed include:
facilitation of emission of light rays detection of reflected rays processing the received signal enable proper motor operation
LINE FOLLOWING MODE
The line is tracked by the IR sensor. It consists of an infrared emitting diode and a photodiode. In order to facilitate light emission we employ IR LEDs. The rays emitted by these LEDs incident on the surface on which the line is drawn. The white surfaces on which the lines are drawn, reflects these emitted rays. These emitted rays are detected by photodiodes. On the other hand the black coloured surface absorbs the rays. The photodiode responds to radiation from the emitting diode and its output is fed to the comparator. Comparator compares the input with a reference voltage level and converts it to a digital value. These different outputs are fed to the input of the ADC of PIC16F877A. The PIC is so programmed to trace the black coloured surface or black line. The motor driving IC L293D facilitates different motor operations and helps the circuit trace the path correctly.
OBSTACLE DETECTION MODE
Obstacle detection is made possible by using three sensors for detecting obstacles present at the front end, right and left ends. If the rays emitted by the LEDs get sensed by the sensor TSOP 1738 with no delay, then it indicates the presence of no obstacle. In case of the presence of any obstacle the line follower stops further proceeding. The circuit then checks for any available path without obstacle for further traversal and continue its motion in that path if any. The motor driving IC L293D facilitates different motor operation.
Dept of Electronics and Communication College of Engineering Poonjar
26
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
9.PCB LAYOUT
Figure 8
Dept of Electronics and Communication College of Engineering Poonjar
27
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
Figure 9
The pcb layout was designed and simulated with help of software named orcad.
STEPS IN PCB MAKING The pcb layout made with proteus was printed on a paper The pcb layout was printed on a copper clad by pressing the printed layout with a hot
iron box The layout obtained on the copper clad is verified and connections are darkened Holes for placing components were drilled The printed copper clad was dipped in ferrous sulphate solution and was placed in sun
light The etching was completed in 10 mins and the printed circuit boad was ready The components were soldered into the pcb
Dept of Electronics and Communication College of Engineering Poonjar
28
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
10. FLOW CHART
Figure 10
Dept of Electronics and Communication College of Engineering Poonjar
29
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
11. PROGRAM
// Directives
#define SW PORTB.F7
#define OBLED PORTD.F4
#define LFLED PORTD.F5
#define LIN1 PORTD.F2
#define LIN2 PORTD.F3
#define RIN1 PORTC.F4
#define RIN2 PORTC.F5
#define TSOPR PORTA.F0
#define TSOPM PORTA.F1
#define TSOPL PORTA.F2
#define PHSL PORTD.F0
#define PHSR PORTD.F1
// End Directives
// Variables
char mode = 0,ir_stat = 1,turn_cnt=0,turn_mode=0;
// End Variables
// Initialize MCU
voidinit_mcu ( )
Dept of Electronics and Communication College of Engineering Poonjar
30
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
ADCON1 = 0x06;
TRISA = 0xFF; // set port A as input port
TRISB = 0xFF; // set port B as input port
TRISC = 0x00; // set port C as output port
TRISD = 0x03; /* set last 2 ports of D as input and other ports as output ports*/
PORTC = 0x00; // out 00 to port C
PORTD = 0x00; // out 00 to port D
Delay_ms (1000);
OBLED = 1;
LFLED = 1;
While (SW==1)
;
OBLED = 0;
LFLED = 0;
Delay_ms (2000);
// End Initialize MCU
// ROUTINES FOR LINE DETECTION
// Vehicle Move Straight
Void move_strt ( )
LIN1 = 1; // left motor rotates forward
LIN2 = 0;
Dept of Electronics and Communication College of Engineering Poonjar
31
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
RIN1 = 1; // right motor rotates forward
RIN2 = 0;
// End Vehicle Moves Straight
// Vehicle Moves Reverse
Void move_rvrs ( )
LIN1 = 0;
LIN2 = 1; //left motor rotates backward
RIN1 = 0;
RIN2 = 1; // right motor rotates backward
// End Vehicle Moves Reverse
// Vehicle Moves Right
Void move_rght ( )
LIN1 = 1; // left motor rotates forward
LIN2 = 0;
RIN1 = 0;
RIN2 = 1; //right motor rotates backward
Delay_ms (20);
// End Vehicle Moves Right
Dept of Electronics and Communication College of Engineering Poonjar
32
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
// Vehicle Moves Left
void move left()
LIN1 = 0;
LIN2 = 1; //left motor rotates backward
RIN1 = 1; //right motor rotates forward
RIN2 = 0;
Delay_ms (20);
// End Vehicle Moves Left
// Vehicle Stops
Void vhcl_stop ( )
LIN1 = 0; // left motor stops
LIN2 = 0;
RIN1 = 0; // right motor stops
RIN2 = 0;
// End Vehicle Stop
// Main Routine
// ROUTINE FOR OBSTACLE DETECTION
Void main ()
Dept of Electronics and Communication College of Engineering Poonjar
33
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
init_mcu ( ); //initialise the controller unit
While (1)
if (SW==0)
Delay_ms(300);
If (mode==0)
mode = 1;
else if(mode==1)
mode = 0;
If (mode==1) //mode for obstacle detection
If (ir_stat==1)
PWM1_Init(38000); //PWM inputs to TSOP
PWM1_Start();
PWM1_Set_Duty(20);
ir_stat = 0;
OBLED = 0;
LFLED = 1;
if(TSOPM==1 && TSOPR==1 && TSOPL==1) //no obstacle
move_strt(); //moves straight
Dept of Electronics and Communication College of Engineering Poonjar
34
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
else if((TSOPM==1&&TSOPR==1&&TSOPL==0)||(TSOPM==0&&TSOPR==1&&TSOPL==0)) //obstacle at left or at left & middle
move_rght(); //moves right
else if((TSOPM==1&&TSOPR==0&&TSOPL==1)||(TSOPM==0&&TSOPR==0&&TSOPL==1)) //obstacle at right or at right & middle
move_left(); // moves left
else if(TSOPM==0 && TSOPR==1 && TSOPL==1) // obstacle at mibble
vhcl_stop(); //stops
move_rvrs(); // moves reverse
Delay_ms(500);
vhcl_stop(); //stops
if(turn_cnt>=5)
turn_cnt = 0;
if(TSOPR==1 &&turn_mode==0) // no obstacles at right
//checks if movement to right is possible
if(turn_cnt<=2)
move_rght(); //moves right
Delay_ms(150);
Dept of Electronics and Communication College of Engineering Poonjar
35
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
turn_cnt++;
else
turn_mode = 1; //mode for left
else if(TSOPL==1 &&turn_mode==1) //no obstacles at left
//checks if movement to left is possible
if(turn_cnt>=2 &&turn_cnt<=5)
move_left(); //moves left
Delay_ms(150);
turn_cnt++;
else
turn_mode = 0; //mode for right
turn_cnt = 0;
else if(mode==0) //line detection mode
PWM1_Stop(); // cuts off TSOP
ir_stat = 1;
Dept of Electronics and Communication College of Engineering Poonjar
36
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
OBLED = 1;
LFLED = 0;
if(PHSL==1 && PHSR==1) // both sensors on the line
move_strt(); // moves straight
else if(PHSL==0 && PHSR==1) // left sensor off the line
move_rght(); // moves right
else if(PHSL==1 && PHSR==0) //right sensor off the line
move_left(); //moves left
else // both sensors off the line
vhcl_stop(); // stops
// End Main Routine
Dept of Electronics and Communication College of Engineering Poonjar
37
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
12. APPLICATIONS
Industrial automated equipment carriers. Automated traffic. Tour guides in museums and other similar applications. Second wave robot reconnaissance operations. In large office buildings for message transfer. Medicine transportation in hospitals.
13. FUTURE SCOPE
Software control of the line type (dark or light) to make automatic detection possible. Obstacle detecting sensors to avoid physical obstacles and continue on the line. Distance sensing and position logging & transmission.
14. LIMITATIONS
Calibration is difficult and it is not easy to set a perfect value The steering mechanism is not easily implemented in huge vehicles and impossible for
non electric vehicles. Few curves are not made efficiently and must be avoided Lack of four wheel drive makes it not suitable for a rough terrain Use of IR even though solves a lot of problems pertaining to interference, makes it hard
to debug a faulty error. Lack of speed control makes the robot unstable at times.
Dept of Electronics and Communication College of Engineering Poonjar
38
BLACK LINE TRACER AND OBSTACLE AVOIDANCE AUTONOMOUS ROBOT
15. RESULTS AND DISCUSSIONS
The project “BLACK LINE TRACER AND OBSTACLE AVOIDANCEAUTONOMOUS ROBOT”
is completed successfully. The robot is made with proper functioning of line tracking and
obstacle detection. We are thankful to all those who gave us valuable help and guidance to
complete our project work successfully.
16.BIBLIOGRAPHY
1) DESIGN WITH PIC MICROCONTROLLERS : JOHN.B.PEATMAN
WEBSITES
1) http://www.microchip.com
2) http://www.electronicsforu.com
3) http://ieeexplore.ieee.org
4) http://www.extremeelectronics.co.in
Thank You...!
Dept of Electronics and Communication College of Engineering Poonjar
39