at89c52 based robocar by samad

5
CONSTRUCTION 56 • NOVEMBER 2009 ELECTRONICS FOR YOU WWW.EFYMAG.COM DAYANAND SHARMA AT89C52-BASED ROBOCAR SANI THEO Switch S1 is used for turning on the circuit to run the robot. An additional filter circuit, comprising a resistor and a capacitor for each IR sensor, is used for preventing interference with noise signals. Switch S2 acts as a hardware reset for the microcontroller in case the robot is not running properly. The microcontroller AT89C52 (IC4) is responsible for taking decisions if Fig. 1: Arrangement of IR LEDs and sensors on the front PCB PARTS LIST Semiconductors: IC1 - 7805, 5V regulator IC2, IC3 - L293D motor driver IC4 - AT89C52 microcontroller IC5 - NE555 timer T1 - 2N2222 npn transistor IRL1-IRL5 - 5mm IR LED LED1 - 5mm red LED Q1-Q3 - TSOP1738 IR sensor Resistors (all ¼-watt, ±5% carbon unless stated otherwise): R1 - 3.9-ohms, 2W R2 - 10-kilo-ohms R3, R4 - 3.3-kilo-ohms R5 - 470-ohms R6-R10 - 22-ohms R11-R13 - 100-ohms R14-R21 - 82-kilo-ohms or resistor network R22 - 1-kilo-ohms VR1 - 5.1-kilo-ohms preset Capacitors: C1, C10 - 0.1μF/25V electrolytic C2 - 10μF/25V electrolytic C3, C4 - 33pF ceramic C7-C9 - 4.7μF/25V electrolytic Miscellaneous: BATT - 4V×3 rechargeable battery X TAL1 - 14MHz crystal S1 - SPDT on/off switch S2 - Tactile switch M1 - 12V DC motor M2 - 12V bipolar stepper motor, 7.5°/step - Four wheels each of 75mm dia - Chassis 265×150mm - Heat sink for 7805 - Pulley and belt - Connectors and wires A robot can be defined as an electro-mechanical system with the capability of sens- ing its environment, manipulating it and acting according to the prepro- grammed sequence. It is a machine that appears intelligent due to the instructions it receives from a compu- ter inside it which handles multiple tasks. This article features a car robot— RoboCar—which uses a microcontrol- ler to detect obstacles and manipulate its direction as per the inputs from three infra-red (IR) sensors mounted in front of the car. Basic components of RoboCar The heart of the system is a micro- controller—Atmel AT89C52. It is programmed to accept inputs from its port p0 to sense the obstacles around it and control the steering to avoid any collision. There are three TSOP1738 IR sen- sors (Q1, Q2 and Q3) used in this project—one at the centre and the remaining two on the left and right to detect obstructions, if any, in front of the RoboCar (Fig. 1). In case of an obstacle, or a potential collision, the microcontroller controls the steering through a bipolar stepper motor which is driven by an L293D motor driver IC. L293D is a quadruple half-H driver IC with an output current rating of 600mA at voltages ranging from 4.5V to 36V. A DC motor is used for moving the car forward and backward, depending on the signals received from the three IR sensors. These sensors are used in any remotely-operated home appliance like TV, DVD player, etc. The IR sen- sor TSOP1738 operates at a frequency of 38 kHz. NE555 timer IC is used for generating a pulse of 38 kHz and transmitted through IR LEDs. There are five IR LEDs—two each on the left and right and one on the front of the robot. The reflected IR that beams from the obstacles are received by the sensors and sent to the microcontroller. The microcontroller is programmed in such a way that it takes the decision and changes the path of the robot as per the sensors’ inputs to avoid the obstacles. Circuit description The schematic diagram of an AT89C52- based RoboCar is shown in Fig. 2. This RoboCar is powered by a 12V rechargeable battery connected to a 5V regulator IC 7805 (IC1) through a current limiter R1. This 5V is used for supplying power to the microcontrol- ler AT89C52, IC NE555 and IR sensors TSOP1738.

Upload: sam

Post on 11-Mar-2015

137 views

Category:

Documents


1 download

DESCRIPTION

this is the car which is made by sam

TRANSCRIPT

Page 1: AT89C52 Based RoboCar by samad

cONSTRUcTION

56 • November 2009 • electronics for you w w w . e f y m a g . c o m

DayananD Sharma

aT89C52-BaSeD roBoCar

sani theo

Switch S1 is used for turning on the circuit to run the robot. An additional filter circuit, comprising a resistor and a capacitor for each IR sensor, is used for preventing interference with noise signals. Switch S2 acts as a hardware reset for the microcontroller in case the robot is not running properly.

The microcontroller AT89C52 (IC4) is responsible for taking decisions if

Fig. 1: Arrangement of IR LEDs and sensors on the front PCB

Parts ListSemiconductors: IC1 - 7805, 5V regulatorIC2, IC3 - L293D motor driverIC4 - AT89C52 microcontrollerIC5 - NE555 timerT1 - 2N2222 npn transistorIRL1-IRL5 - 5mm IR LEDLED1 - 5mm red LEDQ1-Q3 - TSOP1738 IR sensorResistors (all ¼-watt, ±5% carbon unless

stated otherwise): R1 - 3.9-ohms, 2WR2 - 10-kilo-ohmsR3, R4 - 3.3-kilo-ohmsR5 - 470-ohmsR6-R10 - 22-ohmsR11-R13 - 100-ohmsR14-R21 - 82-kilo-ohms or resistor

networkR22 - 1-kilo-ohmsVR1 - 5.1-kilo-ohms presetCapacitors: C1, C10 - 0.1μF/25V electrolyticC2 - 10μF/25V electrolyticC3, C4 - 33pF ceramicC7-C9 - 4.7μF/25V electrolyticMiscellaneous: BATT - 4V×3 rechargeable batteryXTAL1 - 14Mhz crystalS1 - SPDT on/off switchS2 - Tactile switchM1 - 12V DC motorM2 - 12V bipolar stepper motor,

7.5°/step - Four wheels each of

75mm dia - Chassis 265×150mm - Heat sink for 7805 - Pulley and belt - Connectors and wires

arobot can be defined as an electro-mechanical system with the capability of sens-

ing its environment, manipulating it and acting according to the prepro-grammed sequence. It is a machine that appears intelligent due to the instructions it receives from a compu-

ter inside it which handles multiple tasks. This article features a car robot—RoboCar—which uses a microcontrol-ler to detect obstacles and manipulate its direction as per the inputs from three infra-red (IR) sensors mounted in front of the car.

Basic components of roboCarThe heart of the system is a micro-controller—Atmel AT89C52. It is programmed to accept inputs from its port p0 to sense the obstacles around it and control the steering to avoid any collision.

There are three TSOP1738 IR sen-sors (Q1, Q2 and Q3) used in this project—one at the centre and the remaining two on the left and right to detect obstructions, if any, in front of the RoboCar (Fig. 1). In case of an obstacle, or a potential collision, the microcontroller controls the steering through a bipolar stepper motor which

is driven by an L293D motor driver IC. L293D is a quadruple half-H driver IC with an output current rating of 600mA at voltages ranging from 4.5V to 36V.

A DC motor is used for moving the car forward and backward, depending on the signals received from the three IR sensors. These sensors are used in any remotely-operated home appliance like TV, DVD player, etc. The IR sen-

sor TSOP1738 operates at a frequency of 38 kHz. NE555 timer IC is used for generating a pulse of 38 kHz and transmitted through IR LEDs. There are five IR LEDs—two each on the left and right and one on the front of the robot. The reflected IR that beams from the obstacles are received by the sensors and sent to the microcontroller. The microcontroller is programmed in such a way that it takes the decision and changes the path of the robot as per the sensors’ inputs to avoid the obstacles.

Circuit descriptionThe schematic diagram of an AT89C52-based RoboCar is shown in Fig. 2. This RoboCar is powered by a 12V rechargeable battery connected to a 5V regulator IC 7805 (IC1) through a current limiter R1. This 5V is used for supplying power to the microcontrol-ler AT89C52, IC NE555 and IR sensors TSOP1738.

Page 2: AT89C52 Based RoboCar by samad

cONSTRUcTION

58 • November 2009 • electronics for you w w w . e f y m a g . c o m

any obstacle is detected by the IR sen-sors. It drives the stepper motor (M1) so that the car changes track to avoid a collision with the obstacle.

Port 0 (P0.0 through P0.7) of the microcontroller is used as the input port that is connected to the sensors. Each of these port pins (P0.0 to P0.7) is pulled high through pull-up resis-tors R14-R21. Note that port pins P0.3 through P0.7 are not used in this ap-plication. You can use them to extend the application to make it a line fol-lowing robot by using similar sensors and making some changes in the code. Port 1 (P1.0 through P1.3) is used for driving the stepper motor through the driver IC L293D (IC2) and port 3 (P3.0 and P3.1) is used for driving the DC motor (M2) for forward or backward motion through another L293D (IC3) driver IC.

Each sensor used here is a 3-pin modular device, where the first and second pins are negative and positive supply terminals respectively and the third pin is the output terminal. A filter circuit comprising a 100-ohm resis-tor and a 4.7µF capacitor is used for powering each sensor. Normally, the output of the sensor is high. When an IR pulse of frequency 38 khz falls on the IR sensor, its output goes low. This low output is sensed by Port 0 of the microcontroller and an action is taken as per preprogrammed instructions.

Pin 31 of the microcontroller has to be pulled high so that it can fetch the codes from its internal memory. But if any external memory is used in the circuit, the pin should be pulled low.

Here, R2 and C2 are used for the power-on reset function. As soon as the power is switched on, a high pulse is applied to pin 9 of the microcontrol-ler to reset it. This action initiates the program and the RoboCar starts mov-ing forward.

how a roboCar worksAs soon as the circuit is powered on, the controller IC4 fetches the codes from its internal memory and sets its pin 10 high and pin 11 low. This signal Fi

g. 2

: Sch

emat

ic d

iagr

am o

f AT8

9C52

-bas

ed R

oboC

ar

Page 3: AT89C52 Based RoboCar by samad

cONSTRUcTION

60 • November 2009 • electronics for you w w w . e f y m a g . c o m

is fed to pin 2 and pin 7 of IC3, which drives the DC motor in one direction. This enables the car to move forward. IC5 is wired as an astable multivibrator to generate a 38kHz pulse.

The 38kHz pulses are amplified by transistor T1 to drive five IR LEDs. The IR sensors and LEDs are arranged in such a way that the output of the sensors is high where there is no ob-stacle near the car. But if there is any obstacle, the transmitted IR signals from the IR LED are reflected back from the obstacle that comes in the way. This makes the sensor output go low. This low output signal is fed to port 0 of the microcontroller. The output of sensor

Q1 is connected to P0.0, Q2 to P0.1 and Q3 to port P0.2.

As soon as the output of the left sensor Q1 is pulled low to P0.0=0, the controller alters the spin of the DC mo-tor, makes port P3=0 and stops the DC motor, thereby stopping the car for a moment. Then it drives port 1 in such a way that the stepper motor is rotated to the right, and the front steering wheels are also turned right, while the car con-tinues to move forward. After a few sec-onds, the controller drives the stepper motor in the reverse direction (turning it left), which brings the steering wheels to the straight position and moves the car forward. Similar is the case when

an obstacle is de-tected at the right sensor Q2.

In case there is an obstacle in the front, the centre sensor Q3 sends a low signal to port pin P0.2. This makes port P3=0 and the car stops. The steer-ing wheels are turned left mak-ing port P3.0=0

and P3.1=1, which moves the car in backward direction with the steering still turned. After a few seconds, the DC motor is stopped by making port P3=0. The steering is set in the straight position and the car moves forward by making the port P3.0=1 and P3.1=0.

Thus, when the port P3.0=0 and P3.1=1, the car moves in the reverse direction; when P3.0=1 and P3.0=0, the car moves in the forward direction and when P3.0=0 and P3.1=0, the car stops.

ConstructionFig. 3 shows the plan view of the mechanical model of the car. The rear wheel is driven by a belt, pulley and a DC motor. The pulley and drive belt for the rear wheels are taken from the HP Business Inkjet 1000 ink tank pump assembly.

If the polarity of the DC is reversed, the motor spins in the opposite direc-tion. The same concept is used for driv-ing the DC motor. The front wheels are mounted on a fibre gear which can be rotated in both directions using a gear and a stepper motor. The gears are taken from an old HP DeskJet 3325 paper-feed printer assembly and the stepper motor for steering control is taken from an old Epson Inkjet 460

printer assembly.I n o r d e r t o

avoid collision or friction between the main car chas-sis and the wheels, enough space has been provided be-tween them for their free rotation. The front PCB is mounted at a height to avoid collision with front wheels while turning. Two gears are used for reducing the speed when the car is run-ning on a rough surface. The main chassis is made of a thick fibre board.

Fig. 3: Plan view of the mechanical model of the RoboCar

Fig. 4: A single-side, actual-size PCB layout for the AT89C52-based RoboCar

Page 4: AT89C52 Based RoboCar by samad

cONSTRUcTION

electronics for you • November 2009 • 61w w w . e f y m a g . c o m

The circuit is assembled on a gen-eral-purpose PCB or on a PCB layout. The actual size, single-side PCB layout is shown in Fig. 4 and its component layout in Fig. 5.

The main PCB and the front PCB can be separated by cutting along the dotted line shown in the PCB layout.

The front PCB assembly is mounted on the front side of the robot as shown in Fig. 3. It is attached firmly on the

main chassis board with nuts, bolts and spacers. The main PCB is also mounted on the chassis board with nuts and bolts and spacers. Three 4V rechargeable bat-tery cells, taken from a laptop, can be placed between the main PCB and the chassis board (Fig. 6). The ‘charger input’ charging terminal has been provided in the PCB for charging the battery.

The main PCB and the front PCB are connected through CON1 and

CON2 with suitable length of wires.

SoftwareThe software code is written in C lan-guage using the free small device C compiler or SDCC. You can download SDCC from the link http://sourceforge.net/projects/sdcc/files/, free of cost. The compiler cre-ates some issues in Windows XP. In this project the code is compiled in a Windows 98 SE environment. The generated hex code is then burnt into

the microcontroller unit (MCU) using a suitable Atmel 89 series programmer such as one from Sunrom Technologies or Frontline Electronics. You should not remove the microcontroller from the zero insertion force (ZIF) socket until the programming is complete.

Steps for installation1. Install SDCC using SDCC-2.9.0-setup file. It will automatically install under c:\Program Files\SDCC

2. Copy ‘Robo1.c’ file under C:\Program Files\SDCC\Robocar

3. Open the MSDOS prompt and give the above path

4. Type ‘SDCC Robo1.c’ against the DOS prompt to compile it. If no errors are found in the code, it will generate the .lst and .ihx files in the same direc-tory where the robo1.c file is located

5. Convert the Robo1.ihx file to generate the robo1.hex file using ‘pack.ihx’ as: packihx robo1.ihx>robo1.hex.

6. Use the robo1.hex file to program the MCU

PrecautionOnce all the parts are assembled, it is necessary to check the operational

Fig. 5: Component layout for the PCB

Fig. 6: Author’s prototype of RoboCar

Page 5: AT89C52 Based RoboCar by samad

cONSTRUcTION

62 • November 2009 • electronics for you w w w . e f y m a g . c o m

Robo1.c #include <at89x52.h>void delay_ret(void);void delay_step(void);void left(void);void right(void);

int i,j,k;void main(void) {

P0=0xFF; /*initialise P0 as input for sensor*/for (i=0;i<10000;i++);

while(1) { P3=0xF2; /*move forward*/ switch(P0) /*check status of port P1*/ {case(0xFB):P3=0xF1; /*apply reverse direction to stop car*/for (i=0;i<30000;i++); P3=0x00; /*stop car*/ right(); /*turn right*/P1=0;P3=0xF1; /*move reverse*/delay_ret(); /*delay*/delay_ret(); /*delay*/left(); /*return to center*/P1=0;P3=0x00; /*stop the car*/for (i=0;i<3000;i++); /*wait a while*/P3=0xF2; /*move forward*/break;

case(0xFE):P3=0xF1; /*apply reverse direction

to stop car*/delay_ret(); P3=0x00; /*stop car*/ left(); /*turn left*/P1=0;P3=0xF2; /*move ahead*/delay_ret(); /*wait for some time*/right(); /*return to center posi-tion*/P1=0;break;

case(0xFD):P3=0xF1; /*apply reverse direction to stop car*/delay_ret(); P3=0x00; /*stop car*/ right(); /*turn right*/P1=0;P3=0xF2; /*move ahead*/delay_ret(); /*wait for some time*/left(); /*return to center posi-tion*/P1=0;break;

} } }

void delay_ret(void) /*delay routine to wait before*/ { /*steer-ing is returned back to straight*/int x,t;for (t=0;t<600;t++) { for (x=0;x<400;x++); }

}

void delay_step(void) /*delay routine for controlling speed of step-per*/ {int j;for (j=0;j<500;j++); }

void left(void) /*turn steering left*/ { for (k=0;k<9;k++) { P1=0x05; delay_step(); P1=0x09; delay_step(); P1=0x0A; delay_step(); P1=0x06; delay_step(); } P1=0x00; }

void right(void) /*turn steering right*/ { for (k=0;k<9;k++) { P1=0x05; delay_step(); P1=0x06; delay_step(); P1=0x0A; delay_step(); P1=0x09; delay_step(); } P1=0x00; }

function of the car on the repair bench itself before leaving it to move on the ground. You can lift the car, switch on the power and check the operation by putting your hand near the sensor to ensure each sensor is working perfect-

ly. You can adjust the range of sensing by varying the preset VR1. It is not recommended to keep the range very long because this would cause the car to keep moving forward and backward as it senses any obstacle, even far away

from it. Once you are sure that the car is operating well, you can leave it to move freely.

EFY note. The source code of this article is included in this month’s EFY-CD.

COMPONENTS. PRODUCTS. MACHINERY.