line follower robot is a mobile machine that can detect and follow line which is drawn on the floor

Upload: hasna-abdelwahab

Post on 06-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    1/54

    1

    CHAPTER ONE

    INTRODUCTION

    1.1 General Overview

    Line follower robot is a mobile machine that can detect and follow line

    which is drawn on the floor. 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. Robot should

    read for identifying his position in some time, after that, the control system

    (AVR) will create for the line follower some orders to respect components in

    purposes of making correct movements of the line follower.

    Sensing a line and maneuvering the line follower to stay on course, while

    constantly correcting wrong moves using feedback mechanism forms a simple

    yet effective closed loop system.

    Although a Line Followers purpose in life is to follow a line, other issues

    have to be discussed for example, if the track that it is following is on a table, it

    should also have some form of detecting the edge of the table so it wont fall Off.

    If the robot is moving fast, it has to have fast reflexes so that if the line turns itwill be able to compensate its direction so it wont leave the track.

    Line Follower needs light to move, but sometimes if an external light

    source is strong enough it might confuse the robot. If the robot is doing its

    preferred activity outdoors, a whole set of issues have to deal with, such as

    sunlight, dust, uneven terrain and other issues.

    The Line Follower in this project may not be able to handle all the

    conditions listed above, but as long as it follows the line it will be satisfied.

    Most, if not all Line Followers, are battery powered. They must have a way to

    define the direction in which they must go. They must also be able to accept

    input from the external world and use that input to decide what to do next.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    2/54

    2

    1.2 Components

    The block diagram below in figure 1.1 shows those basic four components to

    build the line follower which are:

    1- The sensors array.2- The microcontroller (ATmega16).3- Motor driver (L293D).4- Two Dc motors.

    Figure1.1 the line follower block diagram

    1.2.1 Sensors

    The sensors are one of the most important components of the functional

    line follower robot ;they are robots eyes, ears, sense of touch, balance and only

    source of input from external environment The line follower uses IR sensors to

    sense the line, an array of 2 IR LEDs (Tx) and sensors (Rx), facing the ground.

    The output of the sensors is an analog signal which depends on the amount of

    light reflected back, this analog signal is connected to the microcontrollers pins

    that contain an analog to digital converter (ADC).

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    3/54

    3

    1.2.2 Microcontroller

    A microcontroller often serves as the brain of a mechatronic system. It

    can be programmed to interact with both the hardware of the system and the

    user. Even the most basic microcontroller can perform simple math operations,

    control digital outputs, and monitor digital inputs. As the computer industry has

    evolved, so has the technology associated with microcontrollers. Newer

    microcontrollers are much faster, have more memory, and have a host of input

    and output features that dwarf the ability of earlier models. Most modern

    controllers have analog-to-digital converters, high-speed timers and counters,

    interrupt capabilities, outputs that can be pulse-width modulated, serial

    communication ports, etc.

    There are many types of microcontrollers but ATmega-16 is the one used

    in this project to control the robot movements.

    The ATmega16 is a low-power CMOS (complementary metal oxide

    semiconductor) 8-bit microcontroller based on the AVR enhanced RISC

    (reduced instruction set computing) architecture. By executing powerful

    instructions in a single clock cycle, the ATmega16 achieves throughputsapproaching 1 MIPS per MHz allowing the system to optimize power

    consumption versus processing speed.

    The AVR core combines a rich instruction set with 32 general purpose

    working registers. All the 32 registers are directly connected to the Arithmetic

    Logic Unit (ALU), allowing two independent registers to be accessed in one

    single instruction executed in one clock cycle. The resulting architecture is more

    code efficient while achieving throughputs up to ten times faster than

    conventional CISC microcontrollers.[4]

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    4/54

    4

    1.2.3 Motor driver

    Another component is the motor driver L293D which allows the

    microcontrollers to govern the movements of the line follower. Some of the

    microcontroller outputs are connected to the motor driver inputs that are how the

    microcontroller controls the motor movement throughout the output it gives to

    the motor driver.

    L293D is dual H-Bridge motor drive, so with one IC we can interface two

    DC motors which can be controlled in both clockwise and counter clockwise

    direction. L293D has output current of 600mA and peak output current of 1.2A

    per channel. Moreover for protection of circuit from back EMF output diods are

    included within the IC. The output supply has a wide range from 4.5V to 36V,

    which has made L293D the best choice for the DC motor driver.[7]

    1.2.4 DC motors

    The Direct Current (DC) motor is one of the first machines devised to

    convert electrical energy to mechanical power. Its origin can be traced to

    machines conceived and tested by Michael Faraday, the experimenter whoformulated the fundamental concepts of electromagnetism. These concepts

    basically state that if a conductor, or wire, carrying current is placed in a

    magnetic field, a force will act upon it. The magnitude of this force is a function

    of strength of the magnetic field, the amount of current passing through the

    conductor and the orientation of the magnet and conductor. The direction in

    which this force will act is dependent on the direction of current and direction of

    the magnetic field.

    Electric motor design is based on the placement of conductors (wires) in a

    magnetic field. A winding has many conductors, or turns of wire, and the

    contribution of each individual turn adds to the intensity of the interaction. The

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    5/54

    5

    force developed from a winding is dependent on the current passing through the

    winding and the magnetic field strength. If more current is passed through the

    winding, then more force (torque) is obtained. In effect, two magnetic fields

    interacting cause movement: the magnetic field from the rotor and the magnetic

    field from the stators attract each other. This becomes the basis of both AC and

    DC motor design.

    The figure1.2 below shows the state diagram for the line follower

    Figure 1.2 state diagram of the line follower

    The state diagram above in figure1.2 explains the strategy the line follower takes

    to deal with all possible conditions.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    6/54

    6

    1.3 The Objectives of the Project

    The main aim of the project is to design a line follower which is a simple

    robotics application, the follower designed for repetitive tasks which use the

    same path a lot and that helps to reduce the need for a human operator

    1.4 The Applications of the Line Follower

    The line follower is used in many applications, It might be used in a

    warehouse where the follower follows 'tracks' to and from the shelves they stock

    and retrieve from. The line follower is also can be used as a guider to guide

    the visitors from the entrance to the main office. There are cases where

    smarter versions of line followers are used to deliver mail within an office

    building and deliver medications in a hospital.

    1.5 Project Layout

    Chapter one represents a general overview of the line followers and its

    applications. Chapter two discusses the AVR microcontroller in general and

    ATmega16 microcontroller in details and the programming language used to

    write the control program. Chapter three shows architecture of the line follower

    and the components used in the design. Chapter four discusses the principle of

    operation of the line follower and explains the BASCOM code which controls

    the movement of the follower. Chapter five contains the recommendations and

    conclusion.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    7/54

    7

    CHAPTER TWO

    MICROCONTROLLER2.1 Introduction

    A microcontroller is a computer-on-a-chip or a single-chip computer.

    Micro suggests that the device is small, and controller tells that the device might

    be used to control objects, processes, or events. Another term to describe a

    microcontroller is embedded controller, because the microcontroller and its

    support circuits are often built into, or embedded in, the devices they control.

    Microcontrollers involves in all kinds of things these days. Any device

    that measures, stores, controls, calculates, or displays information is a candidate

    for putting a microcontroller inside. The largest single use for microcontrollers is

    in automobiles just about every car manufactured today includes at least one

    microcontroller for engine control, and often more to control additional systems

    in the car. In desktop computers, microcontrollers, inside keyboards, modems,

    printers, and other peripherals, in test equipment, microcontrollers make it easy

    to add features such as the ability to store measurements, to create and store user

    routines, and to display messages and waveforms. Consumer products that use

    microcontrollers include cameras, video recorders, compact-disk players, and

    ovens. And these are just a few examples.

    A microcontroller is similar to the microprocessor inside a personal

    computer. Examples of microprocessors include Intels 8086, Motorolas 68000,

    and Zilogs Z80. Both microprocessors and microcontrollers contain a (Central

    Processing Unit) CPU. The CPU executes instructions that perform the basic

    logic, math, and data moving functions of a computer. To make a complete

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    8/54

    8

    computer, a microprocessor requires memory for storing data and programs, and

    input/output (I/O) interfaces for connecting external devices like keyboards and

    displays.

    Microcontrollers are characterized by how many bits of data they process atonce, with a higher number of bits generally indicating a faster or more powerful

    chip. Eight-bit chips are popular for simpler designs, but 4-bit, 16-bit, and 32-bit

    architectures are also available.

    All microcontrollers have a defined instruction set, which consists of the

    binary words that cause the CPU to carry out specific operations. For example,

    the instruction 0010 0110 tells an 8052 to add the values in two locations. Thebinary instructions are also known as operation codes (Opcodes) for short. The

    opcodes perform basic functions like adding, subtracting, logic operations,

    moving and copying data, and controlling program branching.

    Inside, microcontrollers are little more than a carefully designed array of

    logic gates and memory cells, but modern fabrication processes allow thousands

    of these to fit on a single chip. Since the basic functions of a microcontroller

    performing arithmetic, logic, data-moving, and program branching functions are

    common ones that are useful in many applications, its practical to design a chip

    that performs these functions. The user accesses the abilities of the

    microcontroller by writing a program that performs the desired functions. The

    microcontroller contains all of the elements of a computer on a single chip.

    Using a microcontroller can reduce the number of components and thus the

    amount of design work and wiring required for a project. [4]

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    9/54

    9

    2.2 Architectures of Microcontrollers

    Every microcontroller must have memory space to store a program (code)

    and data. While code provides instructions to the CPU, the data provides the

    information to be processed. The CPU uses buses (wire traces) to access the code

    ROM (Read Only Memory) and RAM (Random Access Memory) memory

    space. There are two types of microcontroller architectures Harvard architecture

    and von Neumann architecture.

    2.2.1Von Neumann architecture

    In von Neumann Architecture the process of accessing the code or data could

    cause them to get in each other's way and slow down the processing speed of the

    CPU, because each had to wait for the other to finish fetching. The data and

    instructions use the same buses.

    Figure 2.1 von Neumann architecture

    2.2.2 Harvard architecture

    To speed up the process of program execution, some CPUs use Harvard

    architecture. In Harvard architecture, the instruction memory and the data

    memory are separate, have separate bus for the code and data memory, and

    sometimes have different sizes. [3]

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    10/54

    10

    Figure 2.2 Harvard architecture

    2.3 Atmel AVR

    The AVR is a modified Harvard architecture 8-bit RISC (Reduced

    Instruction Set Computer) single chip microcontroller which was developed by

    Atmel in 1996. The AVR was one of the first microcontroller families to use on-

    chip flash memory for program storage, as opposed to One-Time Programmable

    ROM, EPROM(Erasable Programmable Read Only Memory) , or EEPROM(

    Electrically Erasable Programmable Read Only Memory) used by other

    microcontrollers at the time. The Atmel AVR and the Microchip PIC are very

    similar (Harvard architecture) lines of microcontrollers.

    2.3.1 Advantages of Atmel AVR

    1. Cost. At the moment, the very lowest-price microcontroller available fromany manufacturer is the Atmel AVR ATtiny116 MHz FLASH.

    2. Speed: Not only are most AVRs capable of 20MHz (even really cheapones like the ATtiny25/45/85 and ATmega48), but they actually run at

    near 20 MIPS; the PIC chip only run at 5 MHz with a 20 MHz oscillator

    frequency. In addition, with the better addressing modes and registers of

    http://en.wikipedia.org/wiki/Modified_Harvard_architecturehttp://en.wikipedia.org/wiki/8-bithttp://en.wikipedia.org/wiki/Reduced_instruction_set_computerhttp://en.wikipedia.org/wiki/Microcontrollerhttp://en.wikipedia.org/wiki/Atmelhttp://en.wikipedia.org/wiki/Flash_memoryhttp://en.wikipedia.org/wiki/Programmable_read-only_memoryhttp://en.wikipedia.org/wiki/Programmable_read-only_memoryhttp://en.wikipedia.org/wiki/EPROMhttp://en.wikipedia.org/wiki/EPROMhttp://en.wikipedia.org/wiki/EEPROMhttp://en.wikipedia.org/wiki/EEPROMhttp://en.wikipedia.org/wiki/EEPROMhttp://en.wikipedia.org/wiki/EPROMhttp://en.wikipedia.org/wiki/Programmable_read-only_memoryhttp://en.wikipedia.org/wiki/Programmable_read-only_memoryhttp://en.wikipedia.org/wiki/Flash_memoryhttp://en.wikipedia.org/wiki/Atmelhttp://en.wikipedia.org/wiki/Microcontrollerhttp://en.wikipedia.org/wiki/Reduced_instruction_set_computerhttp://en.wikipedia.org/wiki/8-bithttp://en.wikipedia.org/wiki/Modified_Harvard_architecture
  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    11/54

    11

    the AVRs, most operation can be done in only one instruction, where it

    often takes more than one instruction to do the same thing on a PIC.

    3. Peripherals: Many Atmel AVR controllers, like many Microchip PICcontrollers, have a built-in 10 bit ADC. Some have LCD (Liquid Cristal

    Display) or USB drivers.

    4. One big advantage of AVRs is that they are supported by the GNUCompiler Collection (GCC)."

    2.3.2 Disadvantages of Atmel AVR

    1. Single source: only available from Atmel.

    2. Power: Atmel AVRs have fairly low power, but the TI MSP430 series

    has the lowest power of any microcontroller.

    3. Speed: near 20MIPS is great, but the SX chips regularly run at near

    50MIPS and can run at 75 or even 100 (in rare cases)

    2.3.3 Common misperceptions

    Some people think the fastest Microchip PIC (20 MHz 4:1 pipeline) is as

    fast as the fastest Atmel AVR (20 MHz 1:1 pipeline). They are wrong. The PIC

    is actually processing instructions at 5 MIPS and the AVR is at just under 20

    MIPS. Also, the AVR instruction set is larger, so in many cases, it is getting

    more done in fewer cycles. [9]

    http://www.piclist.com/techref/ti/msp430/index.htmhttp://www.sxlist.com/http://www.sxlist.com/http://www.piclist.com/techref/ti/msp430/index.htm
  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    12/54

    12

    2.3.4 Groups of Atmel AVR

    The AVR line is divided into two major groups; Tiny and Mega, with

    some additional special function versions for specific applications such as

    lighting, automotive, battery management, and LCD drivers.

    2.3.4.1 Mega AVR

    These are powerful microcontrollers with more than 120 instructions and

    lots of different peripheral capabilities, which can be used in different designs.

    Table 2.1 shows the types of mega AVR. Some of their characteristics are as

    follows:

    Program memory: 4K to 256K bytes. Package: 28 to 100 pins. Extensive peripheral set. Extended instruction set: They have rich

    instruction set.

    Table 2.1 types of mega AVR

    Part Num.Code

    ROM

    Data

    RAM

    Data

    EEPROM

    I/O

    pinsADC Timers

    AT mega 8 8K 1K 0.5K 23 8 3

    AT mega 16 16K 1K 0.5K 32 8 3

    AT mega 32 32K 2K 1K 32 8 3

    AT mega 64 64K 4K 2K 54 8 4

    AT mega 1280 128K 8K 4K 86 16 6

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    13/54

    13

    2.3.4.2 Tiny AVR

    As its name indicates, the microcontrollers in this group have less

    instructions and smaller packages in comparison to mega family. Some

    characteristics are as follows:

    Program memory: 1K to 8K bytes. Package: 8 to 28 pins. Limited peripheral set. Limited instruction set: the instruction sets are limited. For example,

    some of them do not have the multiply instruction.[3]

    2.4 ATmega16

    The Atmel AT mega 16 is equipped with 32 general purpose 8-bit

    registers that are tightly coupled to the processors arithmetic logic unit within

    the CPU. Also, the processor is designed following the Harvard Architecture

    format. That is, it is equipped with separate, dedicated memories and buses for

    program and data information. The register-based Harvard Architectures coupled

    with the RISC-based instruction set allows for fast and efficient program

    execution and allows the processor to complete an assembly language instruction

    every clock cycle. Atmel indicates the AT mega 16 can execute 16 million

    instructions per second when operating at a clock speed of 16 MHz.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    14/54

    14

    2.4.1 Atmega16 architecture overview

    The AT mega 16 has external connections for power supplies (Vcc, GND,

    Avcc, and AREF), an external time base (XTAL1 and XTAL2) input pins to

    drive its clock, processor reset(active low RESET), and four 8-bit ports (PA0-

    PA7, PB0-PB7, PC0-PC7, PD0-PD7), which are used to interact with the

    external world, these ports may be used as general purpose digital input/output

    (I/O) ports or they may be used for the alternate function. The ports are

    interconnected with the AT mega 16s CPU and internal subsystems via an

    internal bus. The AT mega 16 also contains a timer subsystem, an analog to

    digital converter (ADC), an interrupt subsystem, memory components, and acommunication subsystem.

    2.4.1.1 Analog to digital converter

    The AT mega16 is equipped with an eight-channel ADC. The ADC

    converts an analog signal from the outside world into a binary representation

    suitable for use by the microcontroller. The AT mega16 ADC has 10-bit

    resolution. This means that an analog voltage between 0 and 5V will be encoded

    into one of 1024 binary representations between (000)16 and (3FF) 16. This

    provides the AT mega16 with a voltage resolution of approximately 4.88 Mv.[2]

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    15/54

    15

    2.5 Pin Description

    Figure 2.3 below shows the pins of at mega 16 microcontroller:

    Figure 2.3 pin description of Atmega16

    VCC

    Digital supply voltage.

    GND

    Ground.

    Port A (PA7..PA0)

    Port A serves as the analog inputs to the digital (ADC). Port A also serves

    as an 8-bit bi-directional I/O port, if the (ADC) is not used. Port pins can provide

    internal pull-up resistors (selected for each bit). The Port A output buffers have

    symmetrical drive characteristics with both high sink and source capability.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    16/54

    16

    When pins PA0 to PA7 are used as inputs and are externally pulled low, they

    will source current if the internal pull-up resistors are activated. The Port A pins

    are tri-stated when a reset condition becomes active, even if the clock is not

    running.

    Port B (PB7..PB0)

    Port B is an 8-bit bi-directional I/O port with internal pull-up resistors

    (selected for each bit). The Port B output buffers have symmetrical drive

    characteristics with both high sink and source capability. As inputs, Port B pins

    that are externally pulled low will source current if the pull-up resistors are

    activated. The Port B pins are tri-stated when a reset condition becomes active,

    even if the clock is not running. Port B also serves the functions of various

    special features of the Atmega16 as listed on table below.

    Port C (PC7..PC0)

    Port C is an 8-bit bi-directional I/O port with internal pull-up resistors

    (selected for each bit). The Port C output buffers have symmetrical drive

    characteristics with both high sink and source capability. As inputs, Port C pins

    that are externally pulled low will source current if the pull-up resistors are

    activated. The Port C pins are tri-stated when a reset condition becomes active,

    even if the clock is not running. If the JTAG interface is enabled, the pull-up

    resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if

    a reset occurs. Port C also serves the functions of the JTAG interface and other

    special features of the Atmega16 as listed on table below.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    17/54

    17

    Port D (PD7..PD0)

    Port D is an 8-bit bi-directional I/O port with internal pull-up resistors

    (selected for each bit). The Port D output buffers have symmetrical drive

    characteristics with both high sink and source capability. As inputs, Port D pins

    that are externally pulled low will source current if the pull-up resistors are

    activated. The Port D pins are tri-stated when a reset condition becomes active,

    even if the clock is not running. Port D also serves the functions of various

    special features of the Atmega16 as listed on table below.

    RESET

    Reset Input. A low level on this pin for longer than the minimum pulse

    length will generate a reset, even if the clock is not running. Shorter pulses are

    not guaranteed to generate a reset.

    XTAL1

    Input to the inverting Oscillator amplifier and input to the internal clockoperating circuit.

    XTAL2

    Output from the inverting Oscillator amplifier.

    AVCC

    AVCC is the supply voltage pin for Port A and the ADC. It should be

    externally connected to VCC, even if the ADC is not used. If the ADC is used, it

    should be connected to VCC through a low-pass filter.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    18/54

    18

    AREF

    AREF is the analog reference pin for the ADC. [10]

    2.6 Power Saving Modes

    Idle Mode stops the CPU while allowing the USART, Two-wire interface,SRAM (Static Random Access Memory), Timer/Counters, SPI port, and

    interrupt system to continue functioning.

    Power-Down Mode saves the register contents but freezes the Oscillator,disabling all other chip functions until the next external interrupt or

    Hardware Reset.

    Power-Save Mode in which the Asynchronous Timer continues to run,allowing to maintain a timer base while the rest of the device is sleeping.

    ADC Noise Reduction Mode stops the CPU and all I/O modules exceptAsynchronous Timer, to minimize switching noise during A/D

    conversions.

    Standby Mode in which the crystal/resonator Oscillator is running whilethe rest of the device is sleeping. This allows very fast start-up combined

    with low-power consumption.

    Extended Standby Mode in which both the main Oscillator and theAsynchronous Timer continue to run.[9]

    2.7 Writing the Control Program

    When its time to write the program that controls the project, the options

    include using machine code, assembly language, or a higher-level language.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    19/54

    19

    2.7.1 Machine code

    The most fundamental program form is machine code, the binary

    instructions that cause the CPU to perform the desired operations.

    Machine code or machine language is a system of instructions and data executed

    directly by a computers central processing unit. Machine code may be regarded

    as a primitive (and cumbersome) programming language or as the lowest-level

    representation of a compiled and/or assembled computer program. Programs in

    interpreted languages are not represented by machine code, however, their

    interpreter (which may be seen as a processor executing the higher level

    program) often is. Machine code is sometimes called native code when referring

    to platform-dependent parts of language features or libraries. Machine code

    should not be confused with so called byte code, which is executed by an

    interpreter.

    Every processor or processor family has its own machine code instruction

    set. Instructions are patterns of bits that by physical design correspond to

    different commands to the machine. The instruction set is thus specific to a class

    of processors using (much) the same architecture.

    2.7.2 Assembly language

    One step removed from machine code is assembly language, where

    abbreviations called mnemonics (memory aids) substitute for the machine codes.

    The mnemonics are easier to remember than the machine codes they stand for.

    For example, in the 8052s assembly language, the mnemonic CLR C means

    clear the carry bit, and is easier to remember than its binary code (11000011).

    Since machine code is ultimately the only language that a CPU understands, you

    need some way of translating assembly-language programs into machine code.

    For very short programs, you can hand assemble, or translate the mnemonics

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    20/54

    20

    yourself by looking up the machine codes for each abbreviation. Another option

    is to use an assembler, which is software that

    runs on a desktop computer and translates the mnemonics into machine code.

    Most assemblers provide other features, such as formatting the program code and

    creating a listing that shows both the machine-code and assembly-language

    versions of a program sideby-side.

    2.7.3 Higher-level languages (H-L-L)

    A programming language such as C, FORTRAN, or Pascal that enables aprogrammer to write programs that are more or less independent of a particular

    type of computer. Such languages are considered high-level because they are

    closer to human languages and further from machine languages. In contrast,

    assembly languages are considered low-level because they are very close to

    machine languages. The main advantage of high-level languages over low-level

    languages is that they are easier to read, write, and maintain. Ultimately,

    programs written in a high-level language must be translated into machine

    language by a compiler or interpreter. The first high-level programming

    languages were designed in the 1950s. Now there are dozens of different

    languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP,

    Pascal, and Prolog. Higher-level languages also simplify programming by

    allowing you to do in one or a few lines what would require many lines of

    assembly code to accomplish. Interpreters and compilers are two forms of

    higher-level languages. An interpreter translates a program into machine code

    each time the program runs, while a compiler translates only once, creating a

    new, executable file that the computer runs directly, without re-translating. As a

    rule, interpreters are very convenient for shorter programs where execution speed

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    21/54

    21

    isnt critical. With an interpreted language, you can run your program code

    immediately after writing it, without a separate compile or assembly step. A

    compiler is a good choice when a program is long or has to execute quickly. A

    single language like BASIC may be available in both interpreted and compiled

    versions. [4]

    2.7.3.1 BASCOM-AVR

    BASCOM-AVR is a type of high level languages is four programs in one

    package, it is known as an IDE (Integrated Development Environment) it

    includes the program editor, the compiler, the programmer and the simulator all

    together.

    BASCOM-AVR is a compiler that uses a version of Basic very similar to

    QBASIC to produce programs for the AVR. BASCOM-AVR uses IDE which

    allows writing and editing programs, compiling them, testing them with a

    simulator and finally writing the program to the microcontroller for use in a

    circuit all from one program.

    Microcontrollers, such as the AVR, are controlled by software and they do

    nothing until they have a program inside them. The AVR programs are written

    on a PC (Personal Computer) using the BASCOM-AVR. This software is a type

    of computer program called compiler.[8]

    - Programming template

    ------------------------------------------------------------------

    1. Title Block

    Author:

    Date:

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    22/54

    22

    File Name:

    ------------------------------------------------------------------

    2. Program Description:

    ------------------------------------------------------------------

    3. Compiler Directives (these tell Bascom things about our hardware)

    $regfile = attiny26.datthe micro we are using

    $crystal = 1000000 the speed of the micro

    ------------------------------------------------------------------

    4. Hardware Setups

    setup direction of all ports

    Config Porta = Output LEDs on portA

    Config Portb =Input switches on portB

    5. Hardware AliasesLed0 alias portb.0 6. 22nitialize ports so hardware starts correctly

    Porta = &B11111111 turns off LEDs

    ------------------------------------------------------------------

    7. Declare Variables

    8. Initialise Variables

    9. Declare Constants

    ------------------------------------------------------------------

    10. Program starts hereDo

    Loop

    End end program

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    23/54

    23

    CHAPTER THREE

    ARCHITECTURE OF THE LINE FOLLOWER

    This chapter consist the design of the line follower, the car which used is a

    simple toy car that modified by taking out the most of it is component and just

    leave the main body which contains two dc motors, one in the front (for the front

    wheels) and the other one (for the rear wheels). This body is the basic

    construction that the circuit built on it.

    First of all the circuit built on a breadboard so as known, in electronics

    some experimentation is required to prototype (trial) specific circuits. A

    prototype circuit is needed before a PCB is designed for the final circuit. A

    breadboard is used to prototype the circuit. It has holes which components can be

    inserted and has electrical connections between the holes as per the figure 3.1

    below shows that. Using a breadboard means no soldering and a circuit can be

    constructed quickly and modified easily before a final solution is decided upon.

    Figure 3.1 breadboard

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    24/54

    24

    3.1 Motor Driver (L293D)

    One of the first realizations in robotics is that making something move

    isnt an easy task. Simply cant take a brain circuit and connect it to a motor

    and expect anything to happen. The motor will simply not working at the puny

    output signal from the brains, and stay stationary. What the brain needs is an

    enforcer (Muscle). Something to convince the motor to do things the way the

    brains want it to be done. There are many ways to strengthen (buffer) a signal so

    its strong enough to drive a large load like a motor. Transistors H-bridges

    circuit, buffer chips, and dedicated motor driving chips are all suitable choices.

    A motor driver is a device or group of devices that serves to govern in

    some predetermined manner the performance of an electric motor. A motor

    driver include automatic means for starting and stopping the motor, selecting

    forward or reverse rotation, selecting and regulating the speed, regulating or

    limiting the torque, and protecting against overloads and faults.

    3.1.1 (L293D) Description

    This device is a monolithic integrated high voltage, high current four

    channel driver. Drive inductive loads (such as relays solenoids, DC and stepping

    motors 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. The L293D is assembled in a 16 lead plastic package

    which has 4 center pins connected together and used for heat sinking.

    L293D is dual H-Bridge motor drive, so with one IC can interface two DC

    motors which can be controlled in both clockwise and counter clockwise

    direction. L293D has output current of 600Ma and peak output current of 1.2A

    http://en.wikipedia.org/wiki/Electric_motorhttp://en.wikipedia.org/wiki/Fault_(power_engineering)http://en.wikipedia.org/wiki/Fault_(power_engineering)http://en.wikipedia.org/wiki/Electric_motor
  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    25/54

    25

    per channel. Moreover for protection of circuit from back EMF output diods are

    included within the IC. The output supply has a wide range from 4.5V to 36V,

    which has made L293D a best choice for DC motor driver.

    3.1.2 Working theory of H-Bridge

    The name H-Bridge is derived from the actual shape of the switching

    circuit which controls the motion of the motor. It is also known as (Full Bridge).

    Basically there are four switching elements in the H-Bridge as shown in figure

    3.2 below.

    Figure 3.2 H-Bridge circuit

    As seen in the figure 3.2 above there are four switching elements named as

    High side left, High side right, Low side right, Low side left. When

    these switches are turned on in pairs motor changes its direction accordingly.

    Like, if we switch on High side left and Low side right then motor rotate in

    forward direction, as current flows from (+) power supply through the motor coil

    goes to ground via switch low side right. Similarly, when you switch on low side

    left and high side right, the current flows in opposite direction and motor rotates

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    26/54

    26

    in backward direction. This is the basic working of H-Bridge. So we have seen

    that using simple switching elements we can make our own HBridge, or other

    option we have is using an IC based Hbridge driver. [7]

    3.1.3 Pin configurations

    Figure 3.3 and table 3.1 below shows the pin configuration of L239D.

    Figure 3.3 pin configurations of (L293D)

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    27/54

    27

    Table 3.1 pin configuration of L293DNameFunctionPin Number

    Enable 1,2Enable pin for Motor 1; active highInput 1Input 1 for Motor 12

    Output 1Output 1 for Motor 13GroundGround (0V)4GroundGround (0V)5Output 2Output 2 for Motor 16Input 2Input 2 for Motor 17Vcc 2

    Supply voltage for Motors; 9-12V (up

    to 36V)8Enable 3,4Enable pin for Motor 2; active high9

    Input 3Input 1 for Motor 11Output 3Output 1 for Motor 1GroundGround (0V)2GroundGround (0V)3Output 4Output 2 for Motor 14Input 4Input 2 for Motor 15Vcc 1Supply voltage; 5V (up to 36V)6

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    28/54

    28

    3.2 Sensors

    A sensor is often defined as a device that receives and responds to a signal

    or stimulus. This definition is broad. In fact, it is so broad that it covers almost

    everything from a human eye to a trigger in a pistol. Sensors that are used in

    artificial systems must speak the same language as the devices with which they

    are interfaced. This language is electrical in its nature. Thus, it should be

    possible to connect a sensor to an electronic system through electrical wires.

    Hence, we use a somewhat narrower definition of sensors, which may be phrased

    as: A sensor is a device that receives a stimulus and responds with an electrical

    signal. The stimulus is the quantity, property, or condition that is sensed and

    converted into electrical signal.

    The purpose of a sensor is to respond to some kind of an input physical

    property (stimulus) and to convert it into an electrical signal which is compatible

    with electronic circuits. The sensors considered as a translator of a generally

    nonelectrical value into an electrical value. The sensors output signal may be in

    the form of voltage, current, or charge. These may be further described in terms

    of amplitude, frequency, phase, or digital code. This set of characteristics is

    called the output signal format. Therefore, a sensor has input properties (of any

    kind) and electrical output properties.

    3.2.1 IR LEDs

    A light-emitting diode (LED) is a semiconductor diode that emits incoheren

    narrow-spectrum light when electrically biased in the forward direction of the p-junction. The basic function of the emitter is to convert electricity into light. It work

    on the principle of recombination of the electron-hole pair. As in the conduction ban

    of a diode, electrons are the majority carrier and in the valence band, holes ar

    majority carrier. So when an electron from a conduction band recombines with a hol

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    29/54

    29

    of valance band, some amount of energy is released and this energy is in the form o

    light. The amount of energy released is depends upon the forbidden energy gap. Th

    color of the emitted light depends on the composition and condition of th

    semiconducting material used, and can be infrared (IR LED), visible, or near

    ultraviolet. LEDs are often used as small indicator lights on electronic devices and

    increasingly in higher power applications such as flashlights and area lighting. The IR

    Led has two legs, the leg which is longer is positive and other leg is negative as see

    in figure 3.4 below.

    Figure 3.4 IR LED (Tx)

    3.2.2 Photodiodes

    The photodiode is a p-n junction diode which is connected in reverse bias

    direction. The basic function of the detector is to convert light into electricity. As

    its name implies that it works effectively only when the certain number of

    photon or certain amount of light falls on it. When there is no fall of light on the

    photodiode it has an infinite resistance and act as an open switch but as the light

    starts falling on the photodiode, the resistance becomes low and when the full

    intensity of light fall on the photodiode then its resistance becomes zero and it

    starts act like a closed switch. The IR receiver shows in figure 3.5 below: [6]

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    30/54

    30

    Figure 3.5 photodiode (Rx)

    3.2.3 Circuit diagram of IR sensors

    The circuit diagram is shown below in Figure 3.6 and only one set of

    emitter/detector sensor is depicted. The remaining two are constructed in the

    same manner.

    Figure 3.6 circuit diagram of IR sensor

    A line sensor in its simplest form is a sensor capable of detecting a

    contrast between adjacent surfaces, such as difference in color. The theory of

    operation is simple when light shines on a white surface; most of the incoming

    light is reflected away from the surface. In contrast, most of the incoming light is

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    31/54

    31

    absorbed if the surface is black. Therefore, by shining light on a surface and

    having a sensor to detect the amount of light that is reflected, a contrast between

    black and white surfaces can be detected. Figure 3.7 shows an illustration of the

    basics just covered.

    Figure 3.7 the basic IR function

    By making use the reflecting light from the black and white surfaces, the

    objective of tracking a black line is simple and can be achieved by using the

    appropriate sensors. The sensors array consists of two IR transmitters (Tx) and

    receivers (Rx) pasted on the front of the car as shown in figure 3.8 below:

    Figure 3.8 the sensors positions

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    32/54

    32

    3.3 Interfacing the Components with Microcontroller

    The components can be connected with microcontroller directly or

    through a certain devices.

    3.3.1 IR sensor interface with the microcontroller

    The IR sensors array consist of: two LDEs (Tx) and two photo diodes

    (Rx), the positive legs of the LEDs are connected to the source through (2K)

    resistance to reduce the input voltage, and the negative legs are connected to the

    ground. By this way the LEDs emitting infrared rays. The photo diodes also

    having two legs, the positive legs are grounded and the negative legs are

    connected with the microcontroller to pins (A0, A1).

    3.3.2 Motor interface with the microcontroller

    The microcontroller sends a signal to L239D that acts as a switch. If the

    signal received by the L239D is high it will rotate the motor or else it wont do

    so. Note that microcontroller only sends a signal to a switch which gives the

    voltage required by the motor to rotate. Here using L293D which can be used tocontrol two motors. Pin connections for L239D shown below:

    En1 & En2 are given logic 1 from microcontroller or give 5V from outsideand are used to activate/deactivate one half of the H-bridge.

    V is the voltage supply to the motor(s). Vcc is the logic 1 or 5V. GND

    There are two DC motors front motor for front wheels and rear motor for

    rear wheels. The motors receive a signal from the microcontroller through the

    motor driver. The dc motors rotation depends on the polarity or the current

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    33/54

    33

    direction, thats why the motor driver is used. It has four available inputs and

    outputs, only two outputs are needed for each motor. The inputs of L239D are

    connected to the microcontroller ports (D1, D2, D3), D1 and D2 are connected to

    (PIN1, PIN2) respectively to drive the front motor bidirectional, D3 connected

    to(PIN4) to drive the rear motor. When the microcontroller sends a signal to the

    motor driver, this signal actually enables one of the outputs of the motor driver,

    so L293D allows the motor to rotate in the desired direction. The rear motor only

    goes forward tracing the line, so it doesnt need to run bidirectional and that is

    the reason of not connecting PIN5 with the microcontroller. The L293D-DC-

    motor-Interface can be represented in figure 3.9 below bellow:

    Figure 3.9 L293D and DC-motors interfacing

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    34/54

    34

    Table 3.2 Truth table of L293D

    IN1 IN2 Description

    1 1 Motor stops or breaks

    0 1 Motor runs anti-clock wise

    1 0 Motor runs clockwise

    1 1 Motor stops or breaks

    For the above truth table, the enable (EN) has to be set (1).

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    35/54

    35

    CHAPTER FOUR

    DESIGN AND PROGRAMMING OF THE LINE

    FOLLOWER

    4.1 Circuit Connection

    According to the main function of the line follower, which is to detect the

    path that specified by the user, two pair of IR transmitters and receivers has

    been connected to the terminals, transmitters connected to the power supply and

    the receivers connected to microcontroller(portA.0, portA.1) in order to sendsignal to the microcontroller, with this signal the car can define which case that it

    goes through, then it gives the suitable output for the motors through the L293D

    that takes the car back to the black line. The model can be represented in figure

    4.1 below. As it is clear, the microcontroller is the main object that the whole

    components of the circuit are connected to. The devices can be divided into two

    groups, first; the inputs of the Atmega16 microcontroller which are; the IRs

    transmitter and receivers, only the receivers are connected directly to the pins of

    the microcontroller, and the two other Irs transmitters are supplied from the

    power supply (+ 5v). The other group is the output devices; they are; the front

    motor, the rear motor, multi colors LEDs (Light Emitting Diodes), motor driver

    (L293D).

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    36/54

    36

    Figure 4.1 the circuit diagram

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    37/54

    37

    4.2 The Principle of Operation of the Line Follower

    The principle of operation of the follower is to send and receive signals

    from the right and left IR receivers which are located in the center of the car

    model, and send another signal to the microcontroller to take an action according

    to the input. The car should be put where the path (black line) is exactly above

    the right and the left IR receivers.

    While the microcontroller pins receives a specific signal from which is fed

    from both receivers Port A as (ADC) value of(+ 2.5v) that means the car should

    go forward, that happens when the black line is right under the IR receivers, the

    rear motor will receive (+ 5v) through the motor driver L293D, whenever one of

    the two IR receivers got out of the path to a plain surface (a white surface was

    taken in consideration), it directly sends a signal to the microcontroller reporting

    that the car got out of the desired path. So the front motor will rotate in the

    direction of the line in order to take the car back to its path.

    LEDs are used only to clarify the movement of the car, the two yellow

    front LEDs are showing that the car is in the right path, when the power is

    connected to the car, they flash ten times showing that the car is in the standby

    mode. There is a LED with a red color that lights when the car got out of the

    desired path which is already specified. Also there are two other LEDs; a right

    LED flashes when the front wheel rotates to the right direction, and another left

    LED also flashes when it goes to the left direction.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    38/54

    38

    4.3 Programming of the Microcontroller

    The program has been written by BASCOM-AVR programming language,

    its one of the simplest and easiest high-level programming languages that deal

    with Atmel-AVR microcontrollers, once it is a high-level language, the

    instructions of the program shows the logical statements that the car should

    physically execute according to the cases that the car might face in its way going

    forward. The following flowchart in figure 4.2 below clarifies the main idea of

    the program.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    39/54

    39

    Start

    FLASH THE TWO YELLOW LEDs

    TEN TIMES (STANDBY MODE)

    BOHT R. IR &

    L. IR INSIDE

    THE LINE?

    RUN THE REAR MOTOR

    AND THE TWO YELLOW

    LEDs

    YES

    R. IR DETECTS

    LINE & L. IR OUT

    OF LINE?

    NO

    YES

    ROTATE FRONT MOTOR TO THE RIGHT &

    RUN REAR MOTOR + RIGHT BLUE LED

    NO

    1

    2

    2

    2

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    40/54

    40

    Figure 4.2 Flowchart of the possible cases

    BOHT R. IR & L.

    IR OUTSIDE

    THE PATH

    STOP ALL MOTORS AND

    LIGHT RED LED

    NO

    2

    L. IR DETECTS

    LINE & R. IR

    OUT OF LINE?

    ROTATE FRONT MOTOR TOTHE LEFT & RUN REAR

    MOTOR + LEFT BLUE LED

    NO

    2

    2

    YES

    YES

    1

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    41/54

    41

    4.3.1 The cases might face the follower

    There are four cases that the car might face on its way; all of them should

    be completely defined in order to make the microcontroller able to deal with

    them. The first case is when the car is completely out of the path (the black line),at this case both of the IR transmitters is out of the path. The second case is when

    the car is inside the desired path, which means both of the IR transmitters are

    detecting the black line. The third when the car turns right of the line, leaving the

    path in its left, then only the left IR transmitter detects the black line, while the

    other detects the color of the surface (white surface). The fourth and the last case

    is, when the car turns left of the line, leaving the line in its right, at this case the

    right IR transmitter detects the black line, while the other detects the (white)

    surface.

    To be able to understand the conditions that the car may go through, it is

    essential to define the ports of the microcontroller; table 4.1 below identifies

    each port interface and when it should give an output signal:

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    42/54

    42

    Table 4.1 Ports connections

    Port I/O connected to Runs when Period

    Portd.1 O/P L293(IN 1) Power is on always

    Portd.2 O/P L293(IN 2) Power is on always

    Portd.3 O/P L293(IN 3) Power is on always

    Portc.0 O/P Red LED The car got out of path -

    Portb.0 O/P Left led The wheel turn left -

    Portb.1 O/P Right led The wheel turn right -

    Portb.2 O/PForward yellow right

    LEDAt standby mode 30 msec

    Portb.3 O/PForward yellow left

    LEDAt standby mode 30 msec

    Porta.1 I/P Right IR detectorAlways to detect the

    path-

    Porta.0 I/P Left IR detector

    Always to detect the

    path -

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    43/54

    43

    4.3.2 The explanation of the code

    The code starts with defining the micro type ($regfile =M16DEF.DAT)

    which means Atmega16, and specify the frequency used ($crystal = 10000000),

    then defining the ports as follows:

    Ports (D0, D1, D2, and D2) defined as an output ports thatconnected to L293D to control the motors.

    Port C0 defined as an output port that connected to the red led. Ports (B0, B1, B2, and B3) defined as an output ports connected to

    LEDs also.

    Part (a) of the code shows that after defining the ports, a variable has been

    reserved in the micro memory to detect a loop in which the forward yellow

    LEDs flashes for 10 times (ON for 30ms and OFF for 30ms) when the power

    ON, as the detectors shows that the car is in the standby mode. Next step a port

    A is configured as an ADC to receive the analog signal from the IR receivers.

    $regfile=M16DEF.DAT$crystal= 10000000ConfigPortd.0 =OutputConfigPortd.1 =OutputConfigPortd.2 =OutputConfigPortd.3 =OutputConfigPortc.0 =OutputConfigPortb.0 =OutputConfigPortb.1 =OutputConfigPortb.2 =Output

    ConfigPortb.3 =OutputDim Y AsByteFor Y = 1 To 10Portb.2 = 1Portb.3 = 1Waitms 30Portb.2 = 0

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    44/54

    44

    Portb.3 = 0Waitms 30NextConfigAdc=Single, Prescaler = 8 , Reference =InternalEnableInterruptsStart

    AdcPart (a) of the code

    The next part started with holding a word in the memory for two variables;

    Right1 and Left1, the first variable refers port A1, and the second refers to port

    A0, which are the right and the left IR transmitter connected to the ports

    mentioned respectively. The while-loop shows that when both right and left IR

    detectors at the same time detect less than 300 (ADC value) or about (+ 2.5v),then the microcontroller will give a signal (+ 5v) to the red LED that is

    connected to port C0. In other words, when the car is completely out of path,

    only the red LED will light up.

    Dim Left1 AsWordDim Right1 AsWordDim A AsByte

    M:DoLeft1 =Getadc(0)Right1 =Getadc(1)While Right1 < 300 And Left1 < 300Left1 =Getadc(0)Right1 =Getadc(1)Portc.0 = 1Portb.2 = 0Portb.3 = 0Portd.0 = 0Portd.1 = 0Portd.2 = 0Portd.3 = 0Waitms 300WendPortc.0 = 0

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    45/54

    45

    Part (b)

    Part ( c) is an If condition used to represent that when the left Rx read

    less than 400(digitally) then the program jump to loop defined as L, and if the

    right Rx read less than 400(digitally) then the program jump to loop defined asR. In case the conditions an above are not confirmed the port B2=1and port

    B3=1 which are connected to the forward yellow LEDs and a port D1=1, which

    connected to (input1) of the L293driver meaning that the rear motor is running,

    and all other ports are 0. To control the speed of the rear motor for the specific

    design, the micro sends signal (1) for 5ms and stop (0) for16ms.

    IfLeft1 < 400 ThenGosub LEndIfIfRight1 < 400 ThenGosub REndIfPortb.2 = 1Portb.3 = 1Portd.0 = 0Portd.1 = 1

    Portd.2 = 0Portd.3 = 0Waitms 5Portd.0 = 0Portd.1 = 0Portd.2 = 0Portd.3 = 0Waitms 16Loop

    End

    Part (c)

    In part (d) the loop L and R which mentioned in previous conditions are

    defined, in loop L port B0=1 which mean the left led flashes, port D1=1 and port

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    46/54

    46

    D3=1 to enable the L293D to rotate the forward motor to the right because the

    left receiver is out of path and need to rotate right to be in the path. For the loop

    R port B1=1 meaning that the right led flashes, port D (1 and 2) equal 1to

    enable the L293D to rotate the front motor to the left because the right receiver

    is out of the path and need to rotate left to stay on the track. In both loop L and

    R the rear motor runs for 5ms and stops for 16ms to drive the rear motor by

    specific speed.

    L:For A = 1 To 3Portb.0 = 1Portd.0 = 0

    Portd.1 = 1Portd.2 = 0Portd.3 = 1Waitms 5

    Portb.0 = 0Portd.0 = 0Portd.1 = 0Portd.2 = 0Portd.3 = 1

    Waitms 16NextGosub MR:

    For A = 1 To 3Portb.1 = 1Portd.0 = 0Portd.1 = 1

    Portd.2 = 0Portd.3 = 1Waitms 16NextGosub MR:For A = 1 To 3

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    47/54

    47

    Portb.1 = 1Portd.0 = 0Portd.1 = 1Portd.2 = 1Portd.3 = 0Waitms

    5Portb.1 = 0Portd.0 = 0Portd.1 = 0Portd.2 = 1Portd.3 = 0Waitms 16

    NextGosub M

    Part (d)

    4.3.3 The logical statements explanations of the code

    The program starts with the standby mode, the forward yellow LEDs

    should flash ten times by the time the power is on, as the detectors show that the

    car is in the standby mode, and it is ready to receive signals from the IR

    detectors. The number of the port of the LEDs has been referred to, previously inthe table 4.1.

    The next loop started with holding a word in the memory for two

    variables; Right1 and Left1, the first variable refers to the ADC port no. 1, and

    the second refers to the ADC port no. 0, which are the right and the left IR

    transmitter connected to the ports mentioned respectively. The while-loop shows

    that when both right and left IR detectors at the same time detect less than 300

    (ADC value) or about (+ 2.5v), then the microcontroller will give a signal (+ 5v)

    to the red LED that is connected to Portc.0. In other words, when the car is

    completely out of path, only the red LED will light up.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    48/54

    48

    Else if the car got out of the path to the right, in case that the path is

    curved to the left of the car, then the right IR transmitter will send an ADC value

    more than 300 (more than + 2.5v) to the Porta.0, by the time the other left IR still

    in the path with an ADC value of more than 300, then the microcontroller will

    send a signal to the L293D to enable the output1 and output2 that control the

    front motor in order to rotate the wheels of the car to the left, taking the car back

    to the path that is in the left. Another two signals will be sent, one to the L293D

    for enabling the rear motor while the car is turning left back to the path, and

    other is sent to the left blue LED to flash while the car turning left.

    When the car got out of the path, but this time to the left in case that the

    black live is curved to the right, then the left IR transmitter will send an ADC

    value more than 300 to the Port1.1 of the microcontroller, by the time that the

    right IR still located in the right path, then the microcontroller will send three

    signals, one to the L293D to enable the output3 and output4 which control the

    rear motor in order to rotate the wheel of the car to the right,. The second signal

    will also be sent to the L293D to run the rear motor to go forward, and the other

    signal is for flashing the blue right LED. The last case, when the car is

    completely inside of the path (the black line), then, both of the IR transmitters

    will detect the line, and send this signal to the microcontroller, then, only the rear

    motor will be active by enabling the its two outputs of the L293D. And the two

    forward yellow LEDs will light as long as the car is in the right way.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    49/54

    49

    CAPTER FIVE

    5.1 Conclusion

    A follower scheme has been done which mean that this van can runforward, turn right and turn left.

    (l293D) represents an interface unit with a microcontroller tocontrol the movements of the two motors.

    BASCOM-AVR compiler is an easy language compared with theother high level language.

    5.2 Recommendations

    Smart versions of followers can be used in many lifeapplications. Obstacle detectors can be add so that follower to

    stop when something crossover its way.

    The follower can be modifying to avoid things that might faceit and return to right path.

    Embedded magnets path can be used instead of drown line onthe surface, when its supplied with magnetic detectors, the

    follower follows the magnets path.

    The code can be modified and array of sensors can be increasedto satisfy a specific cases(sensitivity) and when the follower

    totally gets out of the right path the control program command

    the to reverse its movement to return to the course.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    50/54

    50

    References

    [1]- Dhananjay V.Gadre, Programming and customizing the AVRmicrocontroller McGraw-Hill 2001.

    [2]- Steven F.Barrett, Daniel J.Pack, Atmel AVR microcontroller

    primer Programming and Interfacing, Morgan & Claypool 2008.

    [3]-Muhammad Ali Mazidi, Sarmad Naimi, Sepeher Naimi, The

    AVR microcontroller and embedded system using assembly and C,

    Prentice hall.

    [4]-Jan Axelson, The microcontroller idea book, Lakeview

    Research 1997.

    [5]- Priyank Patill, , K.J.Somaiya,Line following robot, Mumbai

    India.

    [6]- Jacob Fraden, Hand book of modern sensors (third edition),

    San Diego California

    [7]-Krishna Nand Gupta and others, Motor driver L293D.

    [8]-Programming in BASCOM-AVR, David Swinscoe

    www.davidswinscoe.com

    [9]-http://www.atmel.com/products/avr/ , may 2011

    [10]- ATmega16 data sheet,Atmel Corporation 2003.

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    51/54

    51

    Appendices

    The control program

    $regfile="M16DEF.DAT"$crystal= 10000000ConfigPortd.0 =OutputConfigPortd.1 =OutputConfigPortd.2 =OutputConfigPortd.3 =OutputConfigPortc.0 =OutputConfigPortb.0 =OutputConfigPortb.1 =Output

    ConfigPortb.2 =OutputConfigPortb.3 =OutputDim Y AsByteFor Y = 1 To 10Portb.2 = 1Portb.3 = 1Waitms 30Portb.2 = 0Portb.3 = 0

    Waitms 30NextConfigAdc=Single, Prescaler = 8 , Reference =InternalEnableInterruptsStartAdc

    Dim Left1 AsWordDim Right1 AsWordDim A AsByteM:

    DoLeft1 =Getadc(0)Right1 =Getadc(1)While Right1 < 300 And Left1 < 300Left1 =Getadc(0)Right1 =Getadc(1)Portc.0 = 1

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    52/54

    52

    Portb.2 = 0Portb.3 = 0Portd.0 = 0Portd.1 = 0Portd.2 = 0

    Portd.3 = 0Waitms 300WendPortc.0 = 0

    IfLeft1 < 400 ThenGosub LEndIfIfRight1 < 400 ThenGosub R

    EndIfPortb.2 = 1Portb.3 = 1Portd.0 = 0Portd.1 = 1Portd.2 = 0Portd.3 = 0Waitms 5Portd.0 = 0Portd.1 = 0

    Portd.2 = 0Portd.3 = 0Waitms 16LoopEnd

    L:For A = 1 To 3Portb.0 = 1Portd.0 = 0

    Portd.1 = 1Portd.2 = 0Portd.3 = 1Waitms 5

    Portb.0 = 0Portd.0 = 0

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    53/54

    53

    Portd.1 = 0Portd.2 = 0Portd.3 = 1Waitms 16NextGosub

    MR:

    For A = 1 To 3Portb.1 = 1Portd.0 = 0Portd.1 = 1

    Portd.2 = 0Portd.3 = 1Waitms 16

    NextGosub MR:For A = 1 To 3Portb.1 = 1Portd.0 = 0Portd.1 = 1Portd.2 = 1Portd.3 = 0

    Waitms 5Portb.1 = 0Portd.0 = 0Portd.1 = 0Portd.2 = 1Portd.3 = 0Waitms 16

    NextGosub M

  • 8/2/2019 Line Follower Robot is a Mobile Machine That Can Detect and Follow Line Which is Drawn on the Floor

    54/54

    The line following van final design :