73809544 Line Follower ROBOT Micro Controller 8051

28
Line Follower ROBOT Microcontroller 8051 Introduction What is a line follower? Line follower is a machine that can follow a path. 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. Why build a line follower? Sensing a line and maneuvering the robot to stay on course, while constantly correcting wrong moves using feedback mechanism forms a simple yet effective closed loop system. As a programmer you get an opportunity to ‘teach’ the robot how to follow the line thus giving it a human-like property of responding to stimuli. Practical applications of a line follower : Automated cars running on roads with embedded magnets; guidance system for industrial robots moving on shop floor etc. Prerequisites: Knowledge of basic digital and analog electronics. (A course on Digital Design and Electronic Devices & Circuits would be helpful) C Programming Sheer interest, an innovative brain and perseverance! Background: I started with building a parallel port based robot which could be controlled manually by a keyboard. On the robot side was an arrangement of relays connected to parallel port pins via opto-couplers. The next version was a true computer controlled line follower. It had sensors connected to the status pins of the parallel port. A program running on the computer polled the status register of the parallel port hundreds of times every second and sent control signals accordingly through the data pins. The drawbacks of using a personal computer were soon clear – It’s difficult to control speed of motors As cable length increases signal strength decreases and latency increases. A long multi core cable for parallel data transfer is expensive. The robot is not portable if you use a desktop PC. The obvious next step was to build an onboard control circuit; the options – a hardwired logic circuit or a uC. Since I had no knowledge of uC at that time, I implemented a hardwired logic circuit using multiplexers. It basically mapped input from four sensors to four outputs for the motor driver according to a truth table. Though it worked fine, it could show no intelligence – like coming back on line after losing it, or doing something special when say the line ended. To get around this problem and add some cool features, using a microcontroller was the best option.

Transcript of 73809544 Line Follower ROBOT Micro Controller 8051

Page 1: 73809544 Line Follower ROBOT Micro Controller 8051

Line Follower ROBOT Microcontroller 8051

Introduction

What is a line follower?Line follower is a machine that can follow a path. 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.

Why build a line follower?Sensing a line and maneuvering the robot to stay on course, while constantly correcting wrong moves using feedback mechanism forms a simple yet effective closed loop system. As a programmer you get an opportunity to ‘teach’ the robot how to follow the line thus giving it a human-like property of responding to stimuli. Practical applications of a line follower : Automated cars running on roads with embedded magnets; guidance system for industrial robots moving on shop floor etc.

Prerequisites:Knowledge of basic digital and analog electronics. (A course on Digital Design and Electronic Devices & Circuits would be helpful) C Programming Sheer interest, an innovative brain and perseverance!

Background:I started with building a parallel port based robot which could be controlled manually by a keyboard. On the robot side was an arrangement of relays connected to parallel port pins via opto-couplers. The next version was a true computer controlled line follower. It had sensors connected to the status pins of the parallel port. A program running on the computer polled the status register of the parallel port hundreds of times every second and sent control signals accordingly through the data pins. The drawbacks of using a personal computer were soon clear – It’s difficult to control speed of motors As cable length increases signal strength decreases and latency increases. A long multi core cable for parallel data transfer is expensive. The robot is not portable if you use a desktop PC. The obvious next step was to build an onboard control circuit; the options – a hardwired logic circuit or a uC. Since I had no knowledge of uC at that time, I implemented a hardwired logic circuit using multiplexers. It basically mapped input from four sensors to four outputs for the motor driver according to a truth table. Though it worked fine, it could show no intelligence – like coming back on line after losing it, or doing something special when say the line ended. To get around this problem and add some cool features, using a microcontroller was the best option.

Page 2: 73809544 Line Follower ROBOT Micro Controller 8051

2.3. POWER SUPPLY UNIT (+5V)

Power supplies are designed to convert high voltage AC mains electricity to a suitable low voltage

supply for electronics circuits and other devices. A power supply can by broken down into a series of

blocks, each of which performs a particular function.

For a 5V regulated supply :

Fig. 2

Each of the block has its own function as described below

1. Transformer – steps down high voltage AC mains to low voltage AC.

2. Rectifier – converts AC to DC, but the DC output is varying.

3. Smoothing – smooths the DC from varying greatly to a small ripple.

4. Regulator – eliminates ripple by setting DC output to a fixed voltage.

TRANSFORMER

Transformers convert AC electricity from one voltage to another with little loss of power.

Transformers work only with AC and this is one of the reasons why mains electricity is AC. The two

types of transformers

Step-up transformers increase voltage,

Step-down transformers reduce voltage.

Fig. 3 Transformer

Page 3: 73809544 Line Follower ROBOT Micro Controller 8051

Most power supplies use a step-down transformer to reduce the dangerously high mains

voltage (230V in UK) to a safer low voltage. The input coil is called the primary and the output coil

is called the secondary. There is no electrical connection between the two coils, instead they are

linked by an alternating magnetic field created in the soft-iron core of the transformer. The two lines in

the middle of the circuit symbol represent the core.

Transformers waste very little power so the power out is (almost) equal to the power in. Note that

as voltage is stepped down current is stepped up. The ratio of the number of turns on each coil, called

the turns ratio, determines the ratio of the voltages. A step-down transformer has a large number of

turns on its primary (input) coil which is connected to the high voltage mains supply, and a small

number of turns on its secondary (output) coil to give a low output voltage.

Turns ratio = Vp = Np Vs Ns

And

Power Out = Power In Vs × Is Vp × Ip

Where

Vp = primary (input) voltage

Np = number of turns on primary coil

Ip = primary (input) current

Ns = number of turns on secondary coil

Is = secondary (output) current

Vs = secondary (output) voltage

RECTIFIER

Page 4: 73809544 Line Follower ROBOT Micro Controller 8051

A bridge rectifier can be made using four individual diodes, but it is also available in special

packages containing the four diodes required. It is called a full-wave rectifier because it uses all the AC

wave (both positive and negative sections). 1.4V is used up in the bridge rectifier because each

diode uses 0.7V when conducting and there are always two diodes conducting, as shown in the diagram

below. Bridge rectifiers are rated by the maximum current they can pass and the maximum reverse

voltage they can withstand (this must be at least three times the supply RMS voltage so the rectifier

can withstand the peak voltages). Please see the DIODES page for more details, including pictures of

bridge rectifiers. In this alternate pairs of diodes conduct, changing over the connections so the

alternating directions of AC are converted to the one direction of DC.

Fig. 4 OUTPUT – Full-wave Varying DC

Smoothing

Smoothing is performed by a large value electrolytic capacitor connected across the DC supply to

act as a reservoir, supplying current to the output when the varying DC voltage from the rectifier is

falling. The diagram shows the unsmoothed varying DC (dotted line) and the smoothed DC (solid line).

The capacitor charges quickly near the peak of the varying DC, and then discharges as it supplies

current to the output.

Fig. 5 Capacitor Voltage

Page 5: 73809544 Line Follower ROBOT Micro Controller 8051

Note that smoothing significantly increases the average DC voltage to almost the peak value

(1.4 × RMS value). For example 6V RMS AC is rectified to full wave DC of about 4.6V RMS (1.4V is

lost in the bridge rectifier), with smoothing this increases to almost the peak value giving

1.4 × 4.6 = 6.4V smooth DC.

Smoothing is not perfect due to the capacitor voltage falling a little as it discharges, giving a

small ripple voltage. For many circuits a ripple which is 10% of the supply voltage is satisfactory and

the equation below gives the required value for the smoothing capacitor. A larger capacitor will give

less ripple. The capacitor value must be doubled when smoothing half-wave DC.

Smoothing capacitor for 10% ripple, C = 5 × Io

Vs × f

Where,

C = smoothing capacitance in farads (F)

Io = output current from the supply in amps (A)

Vs = supply voltage in volts (V), this is the peak value of the unsmoothed DC

f = frequency of the AC supply in hertz (Hz), 50Hz in the UK

REGULATOR

Fig. 6 Regulator

Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable output voltages.

They are also rated by the maximum current they can pass. Negative voltage regulators are available,

mainly for use in dual supplies. Most regulators include some automatic protection from excessive

current ( 'overload protection') and overheating ( 'thermal protection'). Many of the fixed voltage

regulator ICs have 3 leads and look like power transistors, such as the 7805 +5V 1A regulator shown

on the right. They include a hole for attaching a heatsink if necessary.

Working Of Power Supply

Transformer

Page 6: 73809544 Line Follower ROBOT Micro Controller 8051

Fig. 7 Transformer Output

The low voltage AC output is suitable for lamps, heaters and special AC motors. It is not suitable

for electronic circuits unless they include a rectifier and a smoothing capacitor.

Transformer + Rectifier

Fig. 8 Rectifier Stage Output

The varying DC output is suitable for lamps, heaters and standard motors. It is not suitable for

electronic circuits unless they include a smoothing capacitor.

Transformer + Rectifier + Smoothing

Fig. 9 Filtered Output

Page 7: 73809544 Line Follower ROBOT Micro Controller 8051

The smooth DC output has a small ripple. It is suitable for most electronic circuits.

Transformer + Rectifier + Smoothing + Regulator

D 2

C 1

1 0 0 0 u f

1 N 4 0 0 7 + 5 V

V

L M 7 8 0 5

1 2

3

V I N V O U T

GND

J 1

123

D 3

g n d

D 4

D 1

Fig. 10 Power Supply

The regulated DC output is very smooth with no ripple. It is suitable for all electronic circuits.

2.3 MICROCONTROLLER UNIT

VARIOUS TYPE OF MICROCONTOLLERS:

First microcontroller is ‘8031’

FEATURES

(i) It is Intel’s product. Neither a microprocessor nor a microcontroller.

(ii) It is a 8-bit controller.

Page 8: 73809544 Line Follower ROBOT Micro Controller 8051

(iii) Internally no ROM is provided i.e. code is outside the chip.

Second microcontroller is ‘8051’

FEATURES

(i) It is a first complete 8-bit microcontroller.

(ii) It is a name of a family. In which the instruction set, pin configuration, architecture

are same, only memory storage capacity is different.

(iii) Internally PROM (programmable read only memory) is provided so it called one time

programmable (OTP).

Third microcontroller is ‘AT89C51’

FEATURES

(ii) It is ATMEL’s product.

(iii) It is a similar to 8051 microcontroller i.e. having same instruction set, pin configuration,

architecture.

(iv) It is a also 8-bit microcontroller. It’s cost is only Rs10 more than 8051.

(v) It uses EPROM (erasable programmable read only memory) or FLASH memory.

(vi) It is Multiple time programmable (MTP) i.e. 1000 times. So it is better than 8051.

(vii) In ‘AT89C51’, ‘C’ stands for CMOS technology used in the manufacturing of the I.C.

Page 9: 73809544 Line Follower ROBOT Micro Controller 8051

ATMEL89C52

DescriptionThe AT89C52 is a low-power, high-performance CMOS 8-bit microcomputer with 8Kbytes of Flash programmable and erasable read only memory (PEROM). The deviceis manufactured using Atmel’s high-density nonvolatile memory technology and iscompatible with the industry-standard 80C51 and 80C52 instruction set and pinout.The on-chip Flash allows the program memory to be reprogrammed in-system or by aconventional nonvolatile memory programmer. By combining a versatile 8-bit CPUwith Flash on a monolithic chip, the Atmel AT89C52 is a powerful microcomputerwhich provides a highly-flexible and cost-effective solution to many embedded controlapplications.

Page 10: 73809544 Line Follower ROBOT Micro Controller 8051
Page 11: 73809544 Line Follower ROBOT Micro Controller 8051

PIN DISCRIPTION

The ATMEL89C52 have a total of 40 pins that are dedicated for various functions such as I/O, RD, WR, address and interrupts. Out of 40 pins, a total of 32 pins are set aside for the four ports P0, P1, P2, and P3, where each port takes 8 pins. The rest of the pins are designated as Vcc, GND, XTAL1, XTAL, RST, EA, and PSEN. All these pins except PSEN and ALE are used by all members of the 8051 and 8031 families. In other words, they must be connected in order for the system to work, regardless of whether the microcontroller is of the 8051 or the 8031 family. The other two pins, PSEN and ALE are used mainly in 8031 based systems. Vcc Pin 40 provides supply voltage to the chip. The voltage source is +5 V.GND Pin 20 is the ground.XTAL1 and XTAL2 The 8051 have an on-chip oscillator but requires external clock to run it. Most often a quartz crystal oscillator is connected to input XTAL1 (pin 19) and XTAL2 (pin 18). The quartz crystal

Page 12: 73809544 Line Follower ROBOT Micro Controller 8051

oscillator connected to XTAL1 and XTAL2 also needs two capacitors of 30 pF value. One side of each capacitor is connected to the ground.

C2 XTAL2 C1 XTAL1

GND

It must be noted that there are various speeds of the 8051 family. Speed refers to the maximum oscillator frequency connected to the XTAL. For example, a 12 MHz chip must be connected to a crystal with 12 MHz frequency or less. Likewise, a 20 MHz microcontroller requires a crystal frequency of no more than 20 MHz. When the 8051 is connected to a crystal oscillator and is powered up, we can observe the frequency on the XTAL2 pin using oscilloscope. RST Pin 9 is the reset pin. It is an input and is active high (normally low). Upon applying a high pulse to this pin, the microcontroller will reset and terminate all activities. This is often referred to as a power –on reset. Activating a power-on reset will cause all values in the registers to be lost. Notice that the value of Program Counter is 0000 upon reset, forcing the CPU to fetch the first code from ROM memory location 0000. This means that we must place the first line of source code in ROM location 0000 that is where the CPU wakes up and expects to find the first instruction. In order to RESET input to be effective, it must have a minimum duration of 2 machine cycles. In other words, the high pulse must be high for a minimum of 2 machine cycles before it is allowed to go low.EAAll the 8051 family members come with on-chip ROM to store programs. In such cases, the EA pin is connected to the Vcc. For family members such as 8031 and 8032 in which there is no on-chip ROM, code is stored on an external ROM and is fetched by the 8031/32. Therefore for the 8031 the EA pin must be connected to ground to indicate that the code is stored externally. EA, which stands for “external access,” is pin number 31 in the DIP packages. It is input pin and must be connected to either Vcc or GND. In other words, it cannot be left unconnected.PSEN This is an output pin. PSEN stands for “program store enable.” It is the read strobe to external program memory. When the microcontroller is executing from external memory, PSEN is activated twice each machine cycle.ALE ALE (Address latch enable) is an output pin and is active high. When connecting a microcontroller to external memory, potr 0 provides both address and data. In other words the microcontroller multiplexes address and data through port 0 to save pins. The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 chip.I/O port pins and their functions

Page 13: 73809544 Line Follower ROBOT Micro Controller 8051

The four ports P0, P1, P2, and P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as output, ready to be used as output ports. To use any of these as input port, it must be programmed.Port 0 Port 0 occupies a total of 8 pins (pins 32 to 39). It can be used for input or output. To use the pins of port 0 as both input and output ports, each pin must be connected externally to a 10K-ohm pull-up resistor. This is due to fact that port 0 is an open drain, unlike P1, P2 and P3. With external pull-up resistors connected upon reset, port 0 is configured as output port. In order to make port 0 an input, the port must be programmed by writing 1 to all the bits of it. Port 0 is also designated as AD0-AD7, allowing it to be used for both data and address. When connecting a microcontroller to an external memory, port 0 provides both address and data. The microcontroller multiplexes address and data through port 0 to save pins. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1 it has address A0-A7. Therefore, ALE is used for de-multiplexing address and data with the help of latch 74LS373.Port 1 Port 1 occupies a total of 8 pins (pins 1 to 8). It can be used as input or output. In contrast to port 0, this port does not require pull-up resistors since it has already pull-up resistors internally. Upon reset, port 1 is configures as an output port. Similar to port 0, port 1 can be used as an input port by writing 1 to all its bits.Port 2 Port 2 occupies a total of 8 pins (pins 21 to 28). It can be used as input or output. Just like P1, port 2 does not need any pull-up resistors since it has pull-up resistors internally. Upon reset port 2 is configured as output port. To make port 2 input, it must be programmed as such by writing 1s to it.Port 3 Port 3 occupies a total of 8 pins (pins 10 to 17). It can be used as input or output. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although port 3 is configured as output port upon reset, this is not the way it is most commonly used. Port 3 has an additional function of providing some extremely important signals such as interrupts. Some of the alternate functions of P3 are listed below:P3.0 RXD (Serial input)P3.1 TXD (Serial output)P3.2 INT0 (External interrupt 0)P3.3 INT1 (External interrupt 1)P3.4 T0 (Timer 0 external input)P3.5 T1 (Timer 1 external input)P3.6 WR (External memory write strobe)P3.7 RD (External memory read strobe)

INSIDE THE 89C51Registers In the CPU, registers are used to store information temporarily. That information could be a byte of data to be processed, or an address pointing to the data to be fetched. In the 8051 there us only one data type: 8 bits. With an 8- bit data type, any data larger than 8 bits has to be broken into 8-bit chunks before it is processed.

A

B

R0R1R2R3R4

Page 14: 73809544 Line Follower ROBOT Micro Controller 8051

DPTR

PC (b)

(a) Some 8051 8-bit registers (b) Some 8051 16-bit registers

The most commonly used registers of the 8051 are A(accumulator), B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR (data pointer) and PC (program counter). All the above registers are 8-bit registers except DPTR and the program counter. The accumulator A is used for all arithmetic and logic instructions.Program Counter and Data PointerThe program counter is a 16- bit register and it points to the address of the next instruction to be executed. As the CPU fetches op-code from the program ROM, the program counter is incremented to point to the next instruction. Since the PC is 16 bit wide, it can access program addresses 0000 to FFFFH, a total of 64K bytes of code. However, not all the members of the 8051 have the entire 64K bytes of on-chip ROM installed. The DPTR register is made up of two 8-bit registers, DPH and DPL, which are used to furnish memory addresses for internal and external data access. The DPTR is under the control of program instructions and can be specified by its name, DPTR. DPTR does not have a single internal address, DPH and DPL are assigned an address each.

Flag bits and the PSW Register Like any other microprocessor, the 8051 have a flag register to indicate arithmetic conditions such as the carry bit. The flag register in the 8051 is called the program status word (PSW) register. The program status word (PSW) register is an 8-bit register. It is also referred as the flag register. Although the PSW register is 8-bit wide, only 6 bits of it are used by the microcontroller. The two unused bits are user definable flags. Four of the flags are conditional flags, meaning they indicate some conditions that resulted after an instruction was executed. These four are CY (carry), AC (auxiliary carry), P (parity), and OV (overflow). The bits of the PSW register are shown below:

CY PSW.7 Carry flagAC PSW.6 Auxiliary carry flag-- PSW.5 Available to the user for general purposeRS1 PSW.6 Register bank selector bit 1RS0 PSW.3 Register bank selector bit 0OV PSW.2 Overflow flag

DPH Program

Page 15: 73809544 Line Follower ROBOT Micro Controller 8051

F0 PSW.1 User definable bitP PSW.0 Parity flag

CY, the carry flag This flag is set whenever there is a carry out from the d7 bit. This flag bit is affected after an 8-bit addition or subtraction. It can also be set to 1 or 0 directly by an instruction such as “SETB C” and “CLR C” where “SETB C” stands for set bit carry and “CLR C” for clear carry.AC, the auxiliary carry flag If there is carry from D3 to D4 during an ADD or SUB operation, this bit is set: otherwise cleared. This flag is used by instructions that perform BCD arithmetic.P, the parity flag The parity flag reflects the number of 1s in the accumulator register only. If the register A contains an odd number of 1s, then P=1. Therefore, P=0 if Ahas an even number of 1s.OV, the overflow flag This flag is set whenever the result of a signed number operation is too large, causing the high order bit to overflow into the sign bit. In general the carry flags is used to detect errors in unsigned arithmetic operations.

MEMORY SPACE ALLOCATION1. Internal ROM

The 89C51 has a 4K bytes of on-chip ROM. This 4K bytes ROM memory has memory addresses of 0000 to 0FFFh. Program addresses higher than 0FFFh, which exceed the internal ROM capacity will cause the microcontroller to automatically fetch code bytes from external memory. Code bytes can also be fetched exclusively from an external memory, addresses 0000h to FFFFh, by connecting the external access pin to ground. The program counter doesn’t care where the code is: the circuit designer decides whether the code is found totally in internal ROM, totally in external ROM or in a combination of internal and external ROM.

2. Internal RAM The 1289 bytes of RAM inside the 8051 are assigned addresses 00 to 7Fh. These 128 bytes can be divided into three different groups as follows:

1. A total of 32 bytes from locations 00 to 1Fh are set aside for register banks and the stack.2. A total of 16 bytes from locations 20h to 2Fh are set aside for bit addressable read/write

memory and instructions.3. A total of 80 bytes from locations 30h to 7Fh are used for read and write storage, or what is

normally called a scratch pad. These 80 locations of RAM are widely used for the purpose of storing data and parameters by 8051 programmers.

Page 16: 73809544 Line Follower ROBOT Micro Controller 8051

BLOCK DIAGRAM

Page 17: 73809544 Line Follower ROBOT Micro Controller 8051

2.5 LCD UNIT:

LCD DisplayLiquid crystal displays (LCD) are widely used in recent years as compares to LEDs. This is due to the declining prices of LCD, the ability to display numbers, characters and graphics, incorporation of a refreshing controller into the LCD, their by relieving the CPU of the task of refreshing the LCD and also the ease of programming for characters and graphics. HD 44780 based LCDs are most commonly used.

Page 18: 73809544 Line Follower ROBOT Micro Controller 8051

LCD pin descriptionThe LCD discuss in this section has the most common connector used for the Hitatchi 44780 based LCD is 14 pins in a row and modes of operation and how to program and interface with microcontroller is describes in this section.

V c c

1 61 51 41 31 21 11 098

654321

7

1 61 51 41 31 21 11 0

98

654321

7

D 7

E

V c c

D 4

C o n t r a s tR S

G n d

R / W

G n d

D 0

D 3

D 6D 5

13

2

D 2D 1

Fig. LCD Pin Description Diagram

VCC, VSS, VEE

The voltage VCC and VSS provided by +5V and ground respectively while VEE is used for controlling LCD contrast. Variable voltage between Ground and Vcc is used to specify the contrast (or "darkness") of the characters on the LCD screen.

RS (register select)There are two important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, then allowing to user to send a command such as clear display, cursor at home etc.. If RS=1, the data register is selected, allowing the user to send data to be displayed on the LCD.

R/W (read/write)The R/W (read/write) input allowing the user to write information from it. R/W=1, when it read and R/W=0, when it writing.

EN (enable)The enable pin is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high power, a high-to-low pulse must be applied to this pin in order to for the LCD to latch in the data presented at the data pins. D0-D7 (data lines)The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCD’s internal registers. To displays the letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS =1. There are also command codes that can be sent to clear the display or force the cursor to the home position or blink the cursor.

Page 19: 73809544 Line Follower ROBOT Micro Controller 8051

We also use RS =0 to check the busy flag bit to see if the LCD is ready to receive the information. The busy flag is D7 and can be read when R/W =1 and RS =0, as follows: if R/W =1 and RS =0, when D7 =1(busy flag =1), the LCD is busy taking care of internal operations and will not accept any information. When D7 =0, the LCD is ready to receive new information.

3.INTERFACING OF LCD WITH MICROCONTROLLER

An intelligent LCD has two lines with 20 characters each line.The display contains two internal byte wide

registers, one for commands and second for characters to be displayed. It also contains a user programmed RAM area

that can be programmed to generate any desired character that can be formed using a dot matrix. To distinguish

between these two data areas, the hex command byte 80 will be used to signify that the display RAM address 00h is

chosen.

Page 20: 73809544 Line Follower ROBOT Micro Controller 8051

From diagram Port 1 of microcontroller is used for 8 bit data display on the LCD. Data lines of the LCD Pin

no.7 to pin no 14 are connected to the port 1 of the microcontroller. The control pin no.4 register select is connected

to P3.5, pin no.5 of LCD for Read/write is connected to P3.6 and the enable pin (6) is connected to microcontroller

Fig. LCD(JHD162A) interfaced with MCU

LCD pin description

Page 21: 73809544 Line Follower ROBOT Micro Controller 8051

BLOCK DIAGRAM

Pin Symbol I/O Description

1 VSS - Ground

2 VCC - +5V power supply

3 VEE - Power supply to control contrast

4 RS I/O RS=0 to select command register, RS=1 to select data register.

5 R/W I/O R/W=0 for write, R/W=1 for read

6 E I/O Enable

7 DB0 I/O The 8 bit data bus

8 DB1 I/O The 8 bit data bus

9 DB2 I/O The 8 bit data bus

10 DB3 I/O The 8 bit data bus

11 DB4 I/O The 8 bit data bus

12 DB5 I/O The 8 bit data bus

13 DB6 I/O The 8 bit data bus

14 DB7 I/O The 8 bit data bus

15 VCC I/O +5V power supply

16 VSS I/O Ground

Page 22: 73809544 Line Follower ROBOT Micro Controller 8051

MICRO-

CONTROLLER

DC SUPPLY CIRCUITRY(GND, 5V)

S1

BUZZER&

LED

LCD MODULE DRIVER CIRCUIT

MOT-1

S3

S4

H-BRIDGE

H-BRIDGE

S2

MOT-2

Page 23: 73809544 Line Follower ROBOT Micro Controller 8051
Page 24: 73809544 Line Follower ROBOT Micro Controller 8051
Page 25: 73809544 Line Follower ROBOT Micro Controller 8051
Page 26: 73809544 Line Follower ROBOT Micro Controller 8051

Software Line Follower Robots Microcontroller 8051:Software for write to AT89C2051 is robot1.hex ,which was written by C-language ,the source code is robot1.c compiled by using MIDE-51, you can download this compiler from here.

#include 8051io.h #include 8051reg.h extern register unsigned char speedleft,speedright; register unsigned char high,low,flag,time;

main() { P1=0x40; P3=0xff; high = 80; low = 30; flag = 0; time = 50; Start(); while(1) { P3|= 0x0f; Run(); } }Start() { char exit,key; exit =1; while(exit) { key = P1; if((key & 0x40)==0) exit=0; } } Run() { char sensors; sensors = (P3 &=0x0f); if((sensors & 0x01)==0) { TurnRight();

Page 27: 73809544 Line Follower ROBOT Micro Controller 8051

flag = 1; } else if((sensors & 0x08)==0) { TurnLeft(); flag = 2; } else if(sensors == 0x09) { Forward(high); flag = 0; } else if(((sensors==0x0b)||(sensors==0x0d))&&(flag==0)) Forward(low);}Forward(char speed) { P1=0x64; speedright = speed+10; speedleft = speed; delay(time); }TurnRight() { P1=0x68; speedright = low+5; speedleft = low; delay(time); }TurnLeft() { P1=0x54; speedright = low+5; speedleft = low; delay(time); }Reverse(char speed) { P1=0x58; speedright = speed; speedleft = speed+5; delay(time); }

Possible Improvements:

-Use of differential steering with gradual change in wheel speeds.-Use of Hysteresis in sensor circuit using LM339-Use of ADC so that the exact position of the line can be interpolated-Use of Wheel Chair or three wheel drive to reduce traction.-General improvements like using a low dropout voltage regulator, lighter chassis etc

References and Resources

Books:Programming and Customizing the AVR Microcontroller – Dhananjay V. GadreParallel Port Complete – Jan Axelson

Page 28: 73809544 Line Follower ROBOT Micro Controller 8051

Links:Atmel Corp.Makers of the AVR microcontrollerhttp://www.atmel.comAVRbeginners.nethttp://www.avrbeginners.net/AVR assembler tutorialTutorial for learning assembly language for the AVR-Single-Chip-ProcessorsAT90Sxxxx from ATMEL with practical examples.http://www.avr-asm-tutorial.net/One of the best sites AVR siteshttp://www.avrfreaks.netWinAVRAn open source C compiler for AVRhttp://sourceforge.net/projects/winavrPonyProgA widely used programmer. Support for newer chips is added periodically. Can alsoprogram PICs and EEPROMShttp://www.lancos.com/prog.htmlBasic Electronicshttp://www.kpsec.freeuk.com/Williamson LabsNice animated tutorials, articles and project ideas.http://www.williamson-labs.com/home.htmSmall Robot Sensorshttp://www.andrew.cmu.edu/user/rjg/websensors/robot_sensors2.htmlRobotics IndiaAn Indian site devoted to robotics. Must seehttp://www.roboticsindia.com/Seattle Robotics Societyhttp://www.seattlerobotics.org/

Line Follower ROBOTAward winner from VingPeaw Competition 2543, the robot built with 2051, L293D, andfour IR sensors. Simple circuit and platform, quick tracking andEasy to understand program using C language.http://www.kmitl.ac.th/~kswichit/LFrobot/LFrobot.htmTools: AVR StudioFor writing code in assembly and simulation of code. Current versions has AVR-GCCplug-in to write code in C.Compilers: IAR, Image Craft , Code Vision AVR, WinAVRProgrammers: Pony Prog, AVR Dude, AVRISP and many more.Evaluation Boards: STK200, STK500 from Kanda Systems