+ All Categories
Home > Documents > 53189679 Project Report Final

53189679 Project Report Final

Date post: 04-Apr-2018
Category:
Upload: sikandar-mirza
View: 215 times
Download: 0 times
Share this document with a friend

of 67

Transcript
  • 7/29/2019 53189679 Project Report Final

    1/67

    CHAPTER 1

    PROJECT INTRODUCTION

    INTRODUCTION

    Nowadays robot has been widely used in var ious fields like industries, academic, researchand development, militar ies and others. This chapter defines the robot, the project onintelligent spy robot. There ar e objective and scope of project those give the direction tosuccessfully complete this project. The project is to build an intelligent spy r obot that hascapability to display the movement live on LCD, to detect if any obstacle on its path andstops there, to detect chunks of metal and is equipped with laser which is replica for a gun .

    1

  • 7/29/2019 53189679 Project Report Final

    2/67

  • 7/29/2019 53189679 Project Report Final

    3/67

    1.1 Robots

    Robots have increasingly being used in industries, especially in manufacturing andassembling in major industrialized countries. There ar e some advantages of using robot, theyare:

    y Reduce labour cost.

    y Improved the work quality.

    y Elimination of dangerous or undesirable jobs.

    y Controlled and faster inventory.

    y Increase precision.

    Robot that are capable to perform complicated motion and have exter nal sensor such asvision, tactile or force sensing are requir ed for a more complicated applications such aswelding, painting, grinding and assembly. This is because these operations resulted in theincrease of interaction between the robot and its surrounding. A robot by definition is amachine that looks like a human being and perfor ms various complex acts, walking andtalking of a human being. It is also defined as fictional machine whose lack of capacity forhuman emotions is often emphasized. By general convention a robot is a programmablemachine that imitates the actions or appearance of an intelligent creature such as human.

    From the Robot Institute of Amer ica, robot is defined:

    A robot is a programmable multifunctional manipulator designed to move material, part,tools or specialized device through var iable programmed motion for the performance of avariety of tasks.

    British Robot Association (BRA) defines robot as:

    A programmable device with a minimum of four degrees of freedom designed to bothmanipulate and transport parts, tools or specialized manufacturing implements through

    variable programmed motion for the performance of the specific manufacturing task (AlSalameh, 2000)

    2

  • 7/29/2019 53189679 Project Report Final

    4/67

    Robotics is the branch of technology that deals with the design, construction, operation,structural disposition, manufacture and application of robots. Robotics is related to software,engineering, electronics and mechanics.

    Need of Robots

    Often, robots are used to do jobs that could be done by humans. However, there are manyreasons why robots may be better than humans in per for ming certain tasks.

    SpeedRobots may be used because they are FASTER than people at carrying out tasks.

    This is because a robot is really a mechanism which is controlled by a computer - and weknow that computers can do calculations and process data very quickly.

    Hazardous Environment

    Robots may be used because they can work in places where a human would be in danger.For example, robots can be designed to withstand greater amounts of

    ` heat

    ` radiation,` chemical fumes

    than humans could.

    Repetitive Tasks

    Sometimes robots are not really much faster than humans, but they are good at simply doingthe same job over and over again. This is easy for a robot, because once the robot has been

    programmed to do a job once, the same program can be run many times to carry out the job

    many times. And the robot will not get bored as a human would.

    EfficiencyEfficiency is all about carrying out tasks without waste. This could mean

    ` not wasting time

    ` not wasting materials

    ` not wasting energy

    Accuracy

    Accuracy is all about carr ying out tasks very precisely. In a factory manufacturing items,

    each item has to be made identically. When items are being assembled, a robot can positionparts within fractions of a millimetre.

    AdaptabilityAdaptability is where a certain robot can be used to carry out more than one task. A simpleexample is a robot being used to weld car bodies. If a different car body is to bemanufactured, the program which controls the robot can be changed. The robot will thencar ry out a differ ent ser ies of movements to weld the new car body.

    3

  • 7/29/2019 53189679 Project Report Final

    5/67

    1.2 Purpose of the Project

    Intelligent spy robot project has been designed for the spying purpose. There are many spy orsur veillances camera widely used for home or organization security system. Some of thedesign able to control via computer by using XBEE that have the wide r ange of transmit andreceive data. With this device the human will able to control and see the wireless visualsystem via computer from other location.

    In military, the wireless camera has been used as their first line force to survey the enemylocation from their base. By using this robot, they can save their soldier live because beforethey move to enemy location they alr eady know the enemy situation and percentage to theywin in the war will be increase. The main objective behind making this robot is to providelittle or small help to our police depar tment and army. It can be used for SPYINGPURPOSES to get the confidential details of anybody from remote area without makingour life in danger. The camera which would be installed can pr ovide the live streaming of

    the places where a human cannot reach ( especially during natural calamities likeearthquakes).

    To accomplish this task we have installed a r obot with a camera which can help thepur pose of spying. Along with the camera we have installed other devices metal detector,obstacle sensor and a laser ( used as r eplica for gun).

    4

  • 7/29/2019 53189679 Project Report Final

    6/67

    1.3 Objective

    There are four main objectives in this project.

    The first objective of this project is the wir eless visual system which is used to human

    monitor the robot vision via mobile. To build the wireless visual system, the wireless camerawill be applied on the robot and the wireless camera will transmit the visual around the robotto the receiver on the LCD.

    The second objective is to build the obstacle sensor that the robot capable to stop movingwhen ther e are obstacles detected. To build a robot with ability to detect obstacle, theobstacle sensor is needed. There are many type of obstacle avoider sensor. The regular

    obstacle avoider sensor used is Infra Red sensor (IR) because it is easy to use and cheap. TheIR sensor operation is when there are object detected, the light on IR will shoot to the objectand deflect the light to IR receiver so that the voltage from drop from deflection will beanalyzed by the microcontroller to r esponse.

    The third objective is to build the metal detector that the robot is capable to detect chunks ofmetal on its path and a buzzer alarm is initiated which detects the presence of chunks ofmetal.

    The last objective is to install a laser on the robot which can be used as a replica of gun to fireon the enemy whenever an enemy is seen on the LCD screen.

    5

  • 7/29/2019 53189679 Project Report Final

    7/67

    1.4 Lit erature Review

    Conducting the literature r eview is done prior to undertaking the project. This will criticallyprovide as much infor mation as needed on the technology available and methodologies usedby other research counter parts around the world on the topic. This chapter provides thesummar y of literature reviews on topics related to spy robot or robot that has capability to

    sur vey the environment via wir eless vision system including robot with obstacle sensor andmetal detector.

    Mobile Operat ed Robot

    Conventionally, Wireless- contr olled robots use rf cir cuits, which have the drawbacks oflimited working range, limited fr equency range and the limited control. Use of a mobile

    phone for robotic control can overcome these limitations. It provides the advantage of robustcontrol, working range as large as the coverage area of the service provider,

    Although the appearance and the capabilities of robots vary vastly, all robots share the featureof a mechanical, movable structure under some form of control. The Control of robotinvolves three distinct phases: perception, processing and action. Generally, the preceptorsare sensor s mounted on the robot, processing is done by the on-board microcontroller or

    processor, and the task is per for med using motors or with some other actuators.

    The robot, is controlled by a mobile phone that makes call to the mobile phone attached to therobot in the course of the call, if any button is pressed control corresponding to the button

    pressed is heard at the other end of the call. This tone is called dual tone multi frequencytome (DTMF) robot receives this DTMF tone with the help of phone stacked in the robotThe received tone is processed by the atmega16 microcontroller with the help of DTMF

    6

  • 7/29/2019 53189679 Project Report Final

    8/67

    decoder MT8870 the decoder decodes the DTMF tone in to its equivalent binary digit andthis binary number is send to the microcontroller, the microcontroller is pre-pr ogrammed totake a decision for any give input and outputs its decision to motor drivers in order to drivethe motors for forward or backwar d motion or a turn.The mobile that makes a call to the mobile phone stacked in the r obot acts as a remote. Sothis simple robotic project does not r equire the construction of receiver and transmitter units.

    DTMF signalling is used for telephone signalling over the line in the voice frequency band tothe call switching centre. The version of DTMF used for telephone dialling is known as touchtone.DTMF assigns a specific frequency ( consisting of two separate tones) to each key s that it caneasily be identified by the electronic cir cuit. The signal generated by the DTMF encoder isthe direct algebraic submission, in real time of the amplitudes of two sine (cosine) waves ofdifferent frequencies, i.e., pressing 5 will send a tone made by adding 1336hz and 770hz tothe other end of the mobile.

    Obstacle Sensing Robot

    Such robots include sensors that require no physical contact with the object being detected.They allow a robot to see an obstacle without actually having to come into contact with it.This can prevent possible entanglement, allow for better obstacle avoidance (over touch-feedback methods), and possibly allow software to distinguish between obstacles of differentshapes and sizes. There are several methods used to allow a sensor to detect obstacles from adistance.

    Infrared Light Based Sensor

    Another ver y popular method uses projected light waves, usually infrared, to detect obstacles.This system projects a pulse of light and looks for the reflection. Properties of the reflectedlight are analyzed to determine characteristics about the object detected. Light has theadvantages of travelling extremely fast, allowing for fast sensor response time, highresolution, and less error to account for. Light from this type of sensor is often formed into anarrow beam or many times a laser is used. This provides good resolution over largedistances.

    7

  • 7/29/2019 53189679 Project Report Final

    9/67

    IR Proximity Sensor with two emitters IR Ranging Sensor

    Hardware

    Camera: Omni vision OV9655 1.3 megapixel 160x128 to 1280x102 resolution

    Range: 100m indoors, 1000m line-of-site

    Sensor s: IR Light based sensors, metal sensor s.

    Drive: Tank-style treads with dif ferential drive via four precision DC gearmotors (100:1 gearreduction)

    Speed: 20cm - 40cm per second (approx 1 foot/sec or .5 mile/hour)

    Chassis: Machined Aluminium

    Dimensions: 120mm long x 100mm wide x 80mm tall (5" x 4" x 3")

    Power: 7.2V 2AH Li-poly battery pack - 4+ hours per charge

    Tools: Drill machine, Mallet, screw driver, sniper, Iron, solder wir e, soldering paste(flux),glue gun,

    Soft ware

    Keil micro vision for writing C- code for the robot.

    SPI-PGM software for transferr ing the hex files to Microcontroller

    Spy robot is the robot that has ability to spy and to survey the environment or situation atcer tain place using wireless camera. The visual gathering from the spy robot can be recordedand viewed by human directly. This project will build a spy robot that has ability to detectobstacle and stop moving. Other s this project will build a robot with wireless visual systemthat the user can observe and control the situation via computer and mobile.

    8

  • 7/29/2019 53189679 Project Report Final

    10/67

    For the conclusion to build an intelligent spy robot and to obtain the objective of this projectthe following component needed:

    i. Wireless camera to the human able to monitor surrounding using computerii. IR sensor to robot able to detect obstacle.

    iii. DC Motor for the robot to move.iv. Metal Detector to detect chunks of metal.

    9

  • 7/29/2019 53189679 Project Report Final

    11/67

    CHAPTER 2

    PROJECT METHODOLOGY

    Methodology

    A pr oper planning is needed to ensure this project is completed on time and follow theobjective. The developing process of The I ntelligent Spy Robot involves in design of themain controller circuit includes the electronics and motorization, hardware and simulationsand etc. Therefore, this chapter discusses the methods and materials employed in the designand fabr ication of the project, as well as its manner of operation. Basically, this pr oject is aninterdisciplinar y field that ranges in scope from the design of mechanical, electricalcomponents and software development

    2.1.0 Mechanical Part

    To build the intelligent spy r obot, several specifications need to apply, for the robot has thecapability as the spy r obot. The intelligent spy robot must have the wheel for the robot tomove and twin motor needed to move the wheel. The obstacle sensor need to place in front ofthe robot to the robot has capability to detect obstacle beside it. This project using the metaldetector to the robot stop moving when there is metal detected. The metal detector must be

    place at the place that easily to detect metal like at the top of the robot.The last mechanical part is the wireless visual system or wireless camera. The wirelesscamera needs to be placed at the top of the robot and there are need mechanism for thecamera to has capability to turn up and down for the r obot able to survey the surr oundingenvironment.

    10

  • 7/29/2019 53189679 Project Report Final

    12/67

  • 7/29/2019 53189679 Project Report Final

    13/67

    Pneumatic Act uators

    Pneumatic actuators use compressed gas to force the movement of pistons through the use ofpumps and valves and so allow movement of the robotic par t. Pneumatic actuators wor k onthe same pr inciples as hydraulic actuators using a series of valves, pumps and pistons togenerate movement in the robot. Gripper s usually use compressed gas because electrics are

    too dangerous and hydraulics can become too messy if they were to leak.

    2.2.3 Motor :- We require 6v to 12 v DC motor for driving the spy robot.

    Wheels

    The wheels connected to geared motors are shown below.

    The basic purpose of wheels connected to geared motors is to convert the rotational torque ofshaft (which moves due to the rotation of gears), to linear motion for the robot. Positioningand alignment of wheels is necessary for the smooth motion of robot. Also, they are to befixed on the shaft in such a manner that they rotate only on the movement of shaft and unlikecaster are not free to rotate as such.

    Wheels are the most important part for any robot for its linear motion and so knowledgeabout their proper use is necessar y for any person related to the field.

    12

  • 7/29/2019 53189679 Project Report Final

    14/67

    Gear Mechanism in Motors

    A gear is a component within a transmission device that transmits rotational torque byapplying a for ce to the teeth of another gear or device. A gear is dif ferent from a pulley inthat a gear is a round wheel that has linkages ("teeth" or "cogs") that mesh with other gearteeth, allowing force to be fully transferr ed without slippage. Depending on their construction

    and arrangement, geared devices can transmit forces at different speeds, torques, or in adifferent direction, from the power source.

    The most common situation is for a gear to mesh with another gear, but a gear can mesh withany device having compatible teeth, such as linear moving racks.

    The gear's most important feature is that gears of unequal sizes ( diameter s) can be combinedto produce a mechanical advantage, so that the rotational speed and torque of the second gearare different from those of the fir st. In the context of a particular machine, the term "gear"also refers to one particular arr angement of gears among other arrangements ( such as "firstgear "). Such arrangements are often given as a r atio, using the number of teeth or geardiameter as units.

    Mechanical advantage:

    Intermeshing gears in motion

    The interlocking of the teeth in a pair of meshing gears means that their circumferencesnecessar ily move at the same rate of linear motion (e.g. meters per second, or feet perminute). Since rotational speed (e.g. measured in revolutions per second, r evolutions perminute, or radians per second) is proportional to a wheel's circumferential speed divided byits radius, we see that the lar ger the radius of a gear, the slower will be its rotational speed,when meshed with a gear of given size and speed. The same conclusion can also be reached

    by a different analytical process: counting teeth. Since the teeth of two meshing gears arelocked in a one to one correspondence, when all of the teeth of the smaller gear have passedthe point where the gears meet i.e., when the smaller gear has made one revolution -- not allof the teeth of the larger gear will have passed that point -- the lar ger gear will have made lessthan one revolution. The smaller gear makes mor e revolutions in a given per iod of time; itturns faster. The speed ratio is simply the reciprocal r atio of the number s of teeth on the two

    gear s.

    (Speed A * Number of teeth A) = (Speed B * Number of teeth B)

    This ratio is known as the gear ratio.

    The torque ratio can be determined by considering the force that a tooth of one gear exerts ona tooth of the other gear. Consider two teeth in contact at a point on the line joining the shaftaxes of the two gears. I n general, the force will have both a radial and a tangentialcomponent. The radial component can be ignored: it merely causes a sideways push on theshaft and does not contribute to turning. The tangential component causes turning. The torque

    13

  • 7/29/2019 53189679 Project Report Final

    15/67

    is equal to the tangential component of the force into radius. Thus we see that the lar ger gearexper iences greater torque; the smaller gear less. The torque r atio is equal to the ratio of theradii. This is exactly the inverse of the case with the velocity ratio. Higher torque implieslower velocity and vice versa. The fact that the torque ratio is the inverse of the velocity ratiocould also be inferred fr om the law of conservation of energy. Here we have been neglectingthe effect of fr iction on the torque ratio. The velocity ratio is truly given by the tooth or size

    ratio, but fr iction will cause the torque ratio to be actually somewhat less than the inverse ofthe velocity ratio.

    14

  • 7/29/2019 53189679 Project Report Final

    16/67

    DC MOTORS-

    These motors run on DC. Here, in our case, the motors used are brushed DC electric motor. Abrushed DC motor is an internally commutated electric motor designed to be run from a DCpower source.

    Simple two-pole DC motor-

    DC Motor Rot ation

    When the coil is powered, amagnetic field is generatedaround the ar mature. The leftside of the armature is pushed

    away from the left magnetand drawn toward the r ight,causing rotation.

    The ar matur e continues torotate.

    When the ar matur e becomeshorizontally aligned, thecommutator rever ses thedirection of current through

    the coil, reversing themagnetic field. The processthen repeats.

    2.2.4 Driving cicuit:-Physical motion of some form helps differentiate a robot from acomputer. It would be nice if a motor could be attached directly to a chip that controlled themovement. But, most chips can't pass enough current or voltage to spin a motor. Also, motors

    tend to be electrically noisy (spikes) and can slam power back into the control lines when themotor direction or speed is changed.

    Specialized circuits ( motor dr ivers) have been developed to supply motors with power and toisolate the other ICs from electrical problems. These circuits can be designed such that theycan be completely separate boards, reusable from project to project.

    A very popular circuit for driving DC motors (ordinar y or gearhead) is called an H-br idge.It's called that because it looks like the capital letter 'H' when viewed on a discrete schematic.

    15

  • 7/29/2019 53189679 Project Report Final

    17/67

    The great ability of an H-bridge circuit is that the motor can be driven forward or backward atany speed, optionally using a completely independent power source.

    An H-bridge design can be really simple for prototyping or really extravagant for addedprotection and isolation. An H-br idge can be implemented with various kinds of components(common bipolar tr ansistors, FET transistors, MOSFET transistors, power MOSFETs, or

    even chips).

    2.2.5 Interfacing circuit:- We have use two interfacing circuits for spy robot, camerainterfacing circuit and DTMF interfacing cicuit .

    16

  • 7/29/2019 53189679 Project Report Final

    18/67

    CHAPTER 3

    DTMF ( Dual Tone Multiple Frequency)

    3.1 DTMF Is Dual Tone Multi-Frequency Tones

    These are the tones that you hear when you press keys on a telephone keypad. The reason forusing this standard is that you can buy a single, very accurate IC (usually used in answer ingmachines and the like) that takes care of all the filtering, amplifying and interpretingnecessar y to determine which key was pressed. And because it's just an analog audio signalthat is being exchanged, it can use a number of ordinary, low-cost transmitter/receiver pairsfor sending that audio signal.

    The design of the circuit for decoding DTMF tones is pretty straightforward. The CM8870 ICinterprets the tones as a 4- bit digital signal. Then microcontroller checks for the decodeddigital signal and compare it with the program installed it. After decoding it will make motorsoper ational through H-BRIDGE (controls clockwise and anticlockwise motion of motorshaft)

    DTMF (dual-tone multi-frequency) signals

    NCFREQUENCIES 1209 1336 1477 1633

    697 1 2 3 A

    770 4 5 6 B

    852 7 8 9 C

    941 * 0 # D

    When all put together, It will send the DTMF tones over an old 900MHz cordless phone,providing a range of several hundr ed feet. Because of the modular nature of this system, inthe future I could swap out the cordless phone for a newer one, or a pair of FRS radios, orsome other tr ansmitter/receiver pair. It doesn't really matter .

    So then based on which key is pressed, the robot will be able to interpret the tone such to turnon motors and move about.

    17

  • 7/29/2019 53189679 Project Report Final

    19/67

    3.2 Theory of Operation

    So what ar e these tones?

    In DTMF there are 16 distinct tones. Each tone is the sum of two frequencies: one from a lowand one from a high frequency group.There are four differ ent frequencies in each group.

    Your phone only uses 12 of the possible 16 tones. If you look at your phone, there are only 4rows (R1, R2, R3 and R4) and 3 columns (C1, C2 and C3). The rows and columns selectfrequencies from the low and high frequency group respectively. The exact value of thefrequencies are listed in Table 3 below:

    TABLE 3: DTMF Row/Column FrequenciesLOW-FREQUENCI ES

    ROW # FREQUENCY (HZ)

    R1: ROW 0 697

    R2: ROW 1 770

    R3: ROW 2 852

    R4: ROW 3 941

    HIGH-FREQUENCIES

    COL # FREQUENCY (HZ)

    C1: COL 0 1209

    C2: COL 1 1336

    C3: COL 2 1477

    C4: COL 3 1633

    C4 not used in phones

    Thus to decipher what tone frequency is associated with a particular key, look at your phoneagain. Each key is specified by its row and column locations. For example the "2" key is row0 (R1) and column 1 (C2). Thus using the above table, "2" has a frequency of 770 + 1336 =

    2106 Hz The "9" is row 2 (R3) and column 2 (C3) and has a fr equency of 852 + 1477 = 2329Hz.

    The following graph is a captured screen from an oscilloscope. It is a plot of the tonefrequency for the "1" key:

    18

  • 7/29/2019 53189679 Project Report Final

    20/67

    You can see that the DTMF gener ated signal is very distinct and clear. The horizontal axis isin samples. The frequency of the tone is about 1900 Hz - close to the 1906 Hz predicted byTable 3 (697+1209).

    3.3 DTMF Components:

    NAME OF COMPONENTS QUANTITY

    6_ LED

    _ RESISTORS 7-1K,3-11K,1-10K=11

    _ DTMF DECODER IC 8870 1

    _ CRYSTAL OSCILATOR 1

    _ CERAMIC CAPACITOR 4

    _ 5 PIN CONNECTOR 1

    _ 2 PIN CONNECTOR 1

    19

  • 7/29/2019 53189679 Project Report Final

    21/67

    3.4 DTMF Decoder

    The M-8870 is a full DTMF Receiver that integrates both bandsplit filter and decoderfunctions into a single 18-pin DIP or SOI C package. Manufactured using CMOS processtechnology, the M-8870 offers low power consumption (35 mW max) and precise datahandling. Its filter section uses switched capacitor technology for both the high and low

    group filters and for dial tone rejection. Its decoder uses digital counting techniques to detectand decode all 16 DTMF tone pairs into a 4- bit code. External component count is minimized

    by provision of an on- chip differential input amplifier, clock generator, and latched tri-stateinterface bus. Minimal external components required include a low-cost 3.579545 MHzcolour burst crystal, a timing resistor, and a timing capacitor.

    The M-8870-02 provides a power-down option which, when enabled, drops consumptionto less than 0.5 mW. The M-8870-02 can also inhibit the decoding of fourth column digits

    20

  • 7/29/2019 53189679 Project Report Final

    22/67

    3.5 Pin Diagram of MT8870

    21

  • 7/29/2019 53189679 Project Report Final

    23/67

    CHAPTER 4

    H Bridge DC Motor Driver

    4.1 Circuit Diagram

    22

  • 7/29/2019 53189679 Project Report Final

    24/67

  • 7/29/2019 53189679 Project Report Final

    25/67

    4.3 Mot or Speed

    You can also pulse the motor control line, (A or B) on and off. This powers the motor in shortburst and gets varying degrees of torque, which usually translates into variable motor speed.

    But if you want to be able to control the motor in both forward and reverse with a processor,you will need more cir cuitry. You will need an H-Bridge. Notice the "H"- lookingconfiguration in the next graphic. Relays configured in this fashion make an H-Bridge. The"high side dr ivers" are the r elays that control the positive voltage to the motor. This is calledsourcing curr ent.The "low side drivers" are the relays that control the negative voltage to sink current to themotor. "Sinking current" is the term for connecting the circuit to the negative side of the

    power supply, which is usually ground.

    So, you turn on the upper left and lower right circuits, and power flows through the motorforward, i.e.: 1 to A, 0 to B, 0 to C, and 1 to D.

    Then for reverse you turn on the upper right and lower left circuits and power flows throughthe motor in reverse, i.e.: 0 to A, 1 to B, 1 to C, and 0 to D.

    24

  • 7/29/2019 53189679 Project Report Final

    26/67

    4.4 Semiconductor H- Bridges

    We can better control our motor by using transistors or Field Effect Transistors (FETs).Most of what we have discussed about the relays H-Bridge is true of these cir cuits. You don'tneed diodes that were across the relay coils now. You should use diodes across yourtransistors though. See the following diagram showing how they are connected.

    These solid state circuits provide power and ground connections to the motor, as did the relaycircuits. The high side drivers need to be current "sources" which is what PNP transistors andP-channel FETs are good at. The low side drivers need to be current "sinks" which is what

    NPN transistors and N-channel FETs are good at.If you turn on the two upper circuits, the motor resists turning, so you effectively have a

    breaking mechanism. The same is tr ue if you turn on both of the lower circuits. This isbecause the motor is a generator and when it tur ns it generates a voltage. If the ter minals ofthe motor are connected ( shorted), then the voltage generated counteracts the motors freedomto turn. It is as if you are applying a similar but opposite voltage to the one generated by themotor being turned. Vis--vis, it acts like a brake.

    To be nice to your transistors, you should add diodes to catch the back voltage that isgenerated by the motor's coil when the power is switched on and off. This fly back voltagecan be many times higher than the supply voltage.

    25

  • 7/29/2019 53189679 Project Report Final

    27/67

    Transistors, being a semiconductor device, will have some resistance, which causes them toget hot when conducting much current. This is called not being able to sink or source verymuch power, i.e.: Not able to provide much curr ent from gr ound or from plus voltage.Mosfets are much more efficient, they can provide much more current and not get as hot.They usually have the flyback diodes built in so you don't need the diodes anymore. Thishelps guard against flyback voltage frying your MCU.

    To use Mosfets in an H-Bridge, you need P-Channel Mosfets on top because they can"source" power, and N-Channel Mosfets on the bottom because then can "sink" power. N-Channel Mosfets are much cheaper than P-Channel Mosfets, but N-Channel Mosfets used tosource power require about 7 volts more than the supply voltage, to turn on. As a result, some

    people manage to use N-Channel Mosfets, on top of the H- Bridge, by using cleaver circuitsto over come the breakdown voltage.

    It is important that the four quadrants of the H-Bridgecircuits be turned on and off pr operly.When there is a path between the positive and ground side of the H-Bridge, other than

    through the motor, a condition exists called "shoot through". This is basically a direct short ofthe power supply and can cause semiconductors to become ballistic, in circuits with largecurrents flowing. There are H-bridge chips available that are much easier, and safer, to usethan designing your own H-Bridge cir cuit.

    26

  • 7/29/2019 53189679 Project Report Final

    28/67

    4.5 Functions of individual Parts

    1. PC 817 Opto-coupler-

    I ts function is isolation of the voltage levels of the DC motor and the micro-controller.The micro-controller works on 5 volts but the DC motor works on 12 volts. As thesetwo are different voltage levels, there is a need of isolation and the four-legged PC

    817 device is used here.

    2. BC 557 Transistors-

    The function of BC 557 transistors is to perform the EX-OR operation in the module.This leads to the fact that the DC motor will work either on 10 or 01 logic levelscoming from the micro-controller to the input signal position in the H-Bridge module.So, the DC motor is saved from damage. This is because if 00 or 11 are supplied tothe motors, they will be shorted as explained i the theory about H-Bridges.

    3. TIP 112 and TIP 127-There are 8 transistors connected in the H-Bridge module other than BC 557. Ofthem, 4 are TIP 112 and 4 are TIP 127. The former are NPN transistors and the latterare PNP transistors. They make up in total 4 Darlington Pairs.A Darlington Pair is a circuit consisting of tr ansistors which is responsible for currentamplification. Eventually, this current is supplied to the DC motors to make them run.

    4. Diodes-

    There are 8 diodes used here. Their number is 1N4007 and of 1 amper e cur rent rating.They are used to prevent back e.m.f. This back e.m.f can cause damage to the DCmotor.

    27

  • 7/29/2019 53189679 Project Report Final

    29/67

    4.6 Assembly And Testing:

    1. The individual components were taken as written in the pr evious pages.

    2. Firstly, the octo-couplers were soldered o to the P.C.B.

    3. Next, in the spaces above them, the connector s for connections to the Micro- controller unitmodule were soldered. These were two five-pin connectors.

    4. Then came the turn of resistors and next the diodes. These were done before the transistorselse it would be difficult for the small legs to be soldered in a congested place.

    5. With the solder ing of transistors BC557, TIP 112 and TIP 127, this module was completeand ready to be used for the robot.

    28

  • 7/29/2019 53189679 Project Report Final

    30/67

    CHAPTER 5

    SENSOR

    Sensor is a device that when exposed to a physical phenomenon

    (temperature, displacement,force and others) produces a proportional output signal ( electrical,mechanical, magnetic andothers). The ter m transducer is often used synonymously withsensor s. Ideally, a sensor is adevice that response to a change in the physical phenomenon. Onother hand, a transducer is adevice that converts one form of ener gy into another for m of

    energy. Sensors are transducerwhen they sense one form of ener gy input and output in thedifferent form of energy. Forexample, a ther mocouple response to a temperature changes (thermal energy) and outputs aproportional change in electromotive force (electrical ener gy).This project uses IR sensors that function as an obstacle

    avoider when there are obstaclesdetected.

    29

  • 7/29/2019 53189679 Project Report Final

    31/67

    5.1 IR SENSOR

    Infra-red (IR) sensor use the concept of reflection of light to function. It consists of twodevices, which called as receiver (Rx) and transmitter (Tx). Transmitter transmits the IR

    packet to an object while receiver receives the packet sent after the light reflected from theobject.

    We used 556 IC for generating a baudrate as the receiver which isbeing used in this pr oject isa photo transistor not a photo diode . Photo diode has a featureto work on a frequency of38 khz or we can say that it only receives the signal of 38 khz.

    30

  • 7/29/2019 53189679 Project Report Final

    32/67

    5.2 Metal Sensor

    METAL SENSOR use the concept of reflection of magnetic pulsesto function. It consists of

    two devices, which called as r eceiver (Rx) and tr ansmitter(Tx). Tr ansmitter transmits themagnetic pulses to an object while receiver receives the magneticpulses sent after the pulsesreflected from the object. If the receiver receives the pulses thenbuzzer get activated. Heretransmitter and receiver both are solenoids of 6v and 12v . 6v istransmitter and 12 v receiver.

    31

  • 7/29/2019 53189679 Project Report Final

    33/67

    CHAPTER 6

    MICROCONTROLLER

    6.1 AT89S52 Microcontroller:

    6.1.1 Description:

    The AT89S52 is a low-power, high-performance CMOS 8-bitmicrocontroller with 8K bytesof in-system programmable Flash memor y. The device ismanufactured using Atmels high-density non-volatile memor y technology and is compatible withthe industry-standard 80C51instruction set and pin-out. The on-chip Flash allows the

    program memory to bereprogrammed in- system or by a conventional non-volatilememory programmer. Bycombining a versatile 8-bit CPU with in-system programmableFlash on a monolithic chip,the Atmel AT89S52 is a powerful microcontroller which providesa highly-flexible and cost-effective solution to many embedded control applications. TheAT89S52 provides thefollowing standard featur es: 8K bytes of Flash, 256 bytes ofRAM, 32 I/O lines, Watchdogtimer, two data pointers, thr ee 16-bit timer/counters, a six-vector two-level interruptarchitecture, a full duplex ser ial port, on-chip oscillator, and clockcircuitr y. I n addition, the

    AT89S52 is designed with static logic for operation down to zerofrequency and supports twosoftware selectable power saving modes. The Idle Mode stopsthe CPU while allowing theRAM, timer/counters, serial port, and interrupt system tocontinue functioning. The Power-down mode saves the RAM con- tents but freezes theoscillator, disabling all other chipfunctions until the next interrupt or hardware reset.32

  • 7/29/2019 53189679 Project Report Final

    34/67

    6.1.2 Pin Configuration:

    A

    T

    M

    E

    L89S5

    33

  • 7/29/2019 53189679 Project Report Final

    35/67

    6.1.3 Circuit Diagram Of AT89S52

    34

  • 7/29/2019 53189679 Project Report Final

    36/67

    6.1.4 Pin Descript ion

    1) VCC - Supplyvoltage.2) GND - Ground.

    3) Port 0 - Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, eachpin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be usedas high-impedance inputs. Port 0 can also be configur ed to be the multiplexed low-order address/data bus dur ing accesses to external program and data memory. In thismode, P0 has internal pull-ups. Port 0 also receives the code bytes during Flash

    pr ogramming and outputs the code bytes during pr ogram ver ification. External pull-ups are required during program verification.

    4) Port 1 - Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins,they ar e pulled high by the internal pull-ups and can be used as inputs. As inputs, Port1 pins that are externally being pulled low will source current (II L) because of theinter nal pull-ups. In addition, P1.0 and P1.1 can be configured to be the timer/counter2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX),r espectively, as shown in the following table. Port 1 also receives the low-orderaddress bytes during Flash programming and verification.

    5) Port 2 - Port 2 is an 8-bit bidir ectional I/O port with internal pull-

    ups. The Port 2 output buffer s can sink/source four TTL inputs. When 1s are writtento Port 2 pins, they are pulled high by the internal pull-ups and can be used as inputs.As inputs, Port 2 pins that are externally being pulled low will sour ce current (IIL)

    because of the internal pull-ups. Port 2 emits the high-order address byte duringfetches from external pr ogram memory and during accesses to external data memorythat uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses stronginter nal pull-ups when emitting 1s. During accesses to external data memory that use8- bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special FunctionRegister . Port 2 also receives the high-order address bits and some control signalsdur ing Flash programming and ver ification.

    6) Port 3 - This does not need any pull-up resistors since it already haspull-up resistors internally. Although port 3 is configured as an output port upon reset,this is not the way it is most commonly used.Port 3 has the additional function of providing signals.This can be seen fr om the nexttable.

    35

  • 7/29/2019 53189679 Project Report Final

    37/67

  • 7/29/2019 53189679 Project Report Final

    38/67

    11) XTAL1 - Input to the inver ting oscillator amplifier and input to the internal clock

    operating circuit.

    12) XTAL2 - Output from the inver ting oscillator amplifier.

    Function of other parts:

    1.7805 Voltage Regulator IC -As clear from its name, the function of voltage regulator 7805is , basically to regulate thevoltage. By this, we mean to ensure a constant supply at a

    level of 5 volts compared toground. This is essential as the Micro-controller works on voltagelevels 5V and ground.

    2. Capacitors (10 F) -The capacitor (10 F) connected at the left side is for reset of thecircuit and the one at theright side is to smoothen the output load.3. Electrolytic Capacitors (1000 F) and Diodes These form the br idge rectifier circuit for the micro-controllerunit module. This circuit isresponsible for fact that the robot will run on both ac and dc. Incase of dc, the rectifier circuitwill not come into account but in case of ac, the circuit will

    convert the ac into dc. This isessential as the micro-controller r uns on dc.

    4.10 k sip This 10 k sip is a register network. Its function is to giveactive- low on Port P0. So, whathappens is that all the 8 pins of P0 have 5 volts on them and soare disabled. Only when theyare made 0 do the pins become enabled.

    5. Crystal (11.0592 MHz) This is a Quartz crystal. Its function is to provide for thepins XTAL1 and XTAL2. Thecr ystal provides for the internal operating clock and alsois the input to the invertingoscillating amplifiers in the inter nal structure of the AT89S52

    micro-controller.

    37

  • 7/29/2019 53189679 Project Report Final

    39/67

    6.2 Assembly and Testing:-

    i) The P.C.B and the individual components were taken.ii) The micro-controller casing was fixed first. This is necessary, as if the micro-

    controller is directly soldered, its functioning will be hampered and it would bedifficult to solder the ver y small pieces of the micro-controller chip.

    iii) Then the 1000F Electrolytic Capacitor was soldered along with the diodes to makethe Bridge Rectifier circuit.

    iv) The IC 7805 voltage r egulator is then soldered on to the P.C.B.v) After that, the 10F capacitors are solder ed on to the P.C.B.vi) Then the crystal and other remaining components followed.vii) The Micro- controller unit module was prepared and ready to use.

    38

  • 7/29/2019 53189679 Project Report Final

    40/67

    CHAPTER 7

    PROGRAMMING AND FLOW CHART

    7.1 KEIL SOFTWARE

    The version of the C programming language used for the micr ocontroller environment is notvery different than standard C when working on mathematical operations, or organizing yourcode. The main difference is all about the limitations of the processor of the 89S52microcontroller as compared to modern computers.

    From the C program to the machine language

    The C source code is very high level language, meaning that it is far from being at the baselevel of the machine language that can be executed by a processor. This machine language is

    basically just zero's and one's and is wr itten in Hexadecimal format, that why they are called

    HEX files.

    There are several types ofHEX files; we are going to

    produce machine code in theINTEL HEX-80 format,since this is the output of theKEIL IDE that we are goingto use. Figure 2.1.A showsthat to convert a C programto machine language, it takesseveral steps depending onthe tool you ar e using,however, the main idea is to

    produce a HEX file at theend. This HEX file will bethen used by the 'burner' towrite every byte of data atthe appropriate place in theEEPROM of the 89S52.

    figure 2.1.A

    Variables and constants

    VariablesOne of the most basic concepts of programming is to handle variables. knowing the exacttype and size of a variable is a very important issue for microcontroller progr ammers,

    because the RAM is usually limited is size. There are two main design considerations to betaken in account when choosing the variables types: the occupied space in ram and the

    processing speed. Logically, a variable that occupies a big number of registers in RAM willbe more slowly processed than a small variable that fits on a single register.

    For you to chose the right variable type for each one of your applications, you will have torefer to the following table:

    Data Type Bit s Bytes Value Range

    39

  • 7/29/2019 53189679 Project Report Final

    41/67

    Bit 1 -- 0 to 1signed char 8 1 -128 to +127unsigned char 8 1 0 to 255signed int 16 2 -32768 to +32767unsigned int 16 2 0 to 65535signed long 32 4 -2147483648 to 2147483647unsigned long 32 4 0 to 4294967295

    float 32 4 1.175494E-38 to 3.402823E+38

    This table shows the number of bits and bytes occupied by eachtypes of var iables, notingthat each byte will fit into a register. You will notice that mostvariables can be either 'signed'or unsigned 'unsigned', and the major difference between the towtypes is the range, but bothwill occupy the same exact space in memory.

    The names of the variables shown in the table are the same that aregoing to be used in theprogram for variables declarations. Note that in C progr amminglanguage, any var iable have

    to be declared to be used. Declaring a variable, will attribute aspecific location in the RAMor FLASH memory to that variable. The size of that location willdepend on the type of thevariable that have been declared.

    To understand the difference between those types, consider thefollowing example sourcecode where we start by declaring three 'unsigned char' variables,and one 'signed char' andthen perform some simple operations:

    unsigned char a,b,c;signed char d;a = 100;

    b = 200;c = a - b;d = a - b;

    In that program the values of 'c' will be equal to '155'! and not '-100' as you though, becausethe variable 'c' is an unsigned type, and when a the value to bestored in a var iable is biggerthan the maximum value range of this variable, it over flows and rolls back to the other limit.Back to our example, the program is trying to store '-100' in 'c', butsince 'c' is unsigned, itsrange of values is from '0 to 255' so, trying to store a value belowzero, will cause the the

    40

  • 7/29/2019 53189679 Project Report Final

    42/67

    char display[10];

    this will create a group of 10 variables. Each one of them is accessible by its number,example:

    display[0] = 100;

    display[3] = 60;display[1] = display[0] - display[3] ;

    where 'display[1]' will be equal to '40'. Note that 'display' contains10 different variables,numbered from 0 to 9. In that previous example, according to thevariable declaration, ther e

    is not such var iable location as 'display[10]', and using it willcause an error in the compiler.

    Constants

    Sometimes, you want to store a very large amount of constantvalues, that wouldn't fit in theRAM or simply would take too much space. you can store thisDATA in the FLASH memoryreserved for the code, but it wont be editable, once the pr ogram isburned on your chip. Theadvantage of this technique is that it can be used to store a huge

    amount of var iables, notingthat the FLASH memor y of the 89S52 is 8K bytes, 32 timesbigger than the RAM memory. Itis, however, your responsibility to distribute this memory betweenyour program and yourDATA.

    To specify that a var iable is to be stored in the FLASH memory,we use exactly the samevariable types names but we add the prefix 'code' before it.Example:

    code unsigned char message[500];

    This line would cause this huge array to be stored in the FLASH

    memory. This can beinteresting for displaying messages on an LCD screen.

    To access the pins and the ports through programming, there are anumber of pre-definedvariables (defined in the header file, as you shall see later) thatdramatically simplifies thattask. There are 4 ports, Port 0 to Port 3, each one of them can beaccessed using the charvariables P0, P1, P2 and P3 respectively. In those char typesvariables, each one of the 8 bitsrepresents a pin on the port. Additionally, you can access a singlepin of a port using the bittype variables PX_0 to PX_7, where X takes a value between 0and 3, depending on the port

    being accessed. For example P1_3 is the pin number 3 of port 1.

    You can also define your own names, using the '#define' directive.Note that this is compilerdirective, meaning that the compiler will use this directive to readand understand the code,but it is not a statement or command that can be translated tomachine language. For example,you could define the following:

    #define LED1 P1_0

    With the definition above, the compiler will replace everyoccurrence of LED1 by P1_0. Thismakes your code much more easier to read, especially when the

    41

  • 7/29/2019 53189679 Project Report Final

    43/67

    Then, each time you write led on time, it will be replaced by 184. Note that this is not avariable and accordingly, you cannot write something like:

    led_on_time = 100; //That's wrong, you cannot change a constant's value in code.

    The utility of using defined constants, appears when you want to adjust some delays in your

    code, or some constant variables that are re-used many times within the code: With apredefined constant, you only change it's value once, and it's applied to the whole code. that'sfor sure apart from the fact that a word like led on time is much more comprehensive thansimply '184'!

    Along this tutorial you will see how port names, and special function registers are usedexactly as variables, to control input/output oper ations and other features of themicrocontroller like timers, counters and inter rupts.

    Mathematical & logic operations

    Now that you know how to declare variables, it is time to knowhow to handle them in yourprogram using mathematical and logic operations.

    Mathematical operations:The most basic concept about mathematical operations in programming languages, is the '='oper ator which is used to store the content of the expression at its right, into the variable at itsleft. For example the following code will store the value of 'b' into 'a' :

    a = b;

    And subsequently, the following expression in totally invalid:5 = b;

    Since 5 in a constant, trying to store the content of 'b' in it willcause an error.

    You can then perform all kind of mathematical operations, usingthe operators '+','-','*' and '/'.You can also use brackets '( )' when needed. Example:

    a =(5*b)+((a/b)*(a+b)) ;

    If you include 'math.h' header file, you will be able to use moreadvanced functions in yourequations like Sin, Cos and Tan trigonometric functions, absolutevalues and logarithmiccalculations like in the following example:

    a =(c*cos( b))+sin(b);

    To be able to successfully use those functions in your programs,you have to know the type ofvariables that those functions take as parameter and return as aresult. For example a Cosinefunction takes an angle in radians whose value is a float numberbetween -65535 and 65535

    and it will return a float value as a result. You can usually knowthose data types from the'math.h' file itself, for example, the cosine function, like all theothers is declared in the top ofthe math header file, and you can r ead the line:

    extern float cos (float val) ;

    42

  • 7/29/2019 53189679 Project Report Final

    44/67

    from this line you can deduce that the 'cos' function returns a float data type, and takes as aparameter a float too. (the parameter is always between brackets.) . Using the same technique,you can easily know how to deal with the rest of the functions of the math header file. thefollowing table shows a short description of those functions:

    Function Descriptionchar cabs (char val); Return an the absolute value of a char variable.int abs ( int val); Return an the absolute value of a int variable.long labs ( long val) ; Return an the absolute value of a long var iable.float fabs (float val); Return an the absolute value of a float variable.float sqrt (float val) ; Returns the square root of a float variable.float exp (float val) ; Returns the value of the Euler number 'e' to the power of valfloat log (float val); Returns the natural logarithm of valfloat log10 (float val); Returns the common logarithm of valfloat sin (float val);

    float cos (float val) ;float tan (float val);float asin (float val);float acos (float val);float atan (float val);float sinh (float val);float cosh (float val) ;float tanh ( float val);

    A set of standard trigonometr ic functions. They all takeangles measured in radians whose value have to be between -65535 and 65535.

    This function calculates the arc tan of the ratio y / x, using thesigns of both x and y to determine the quadrant of the angleand return a number ranging from -pi to pi.

    float atan2 (float y, float x);

    float ceil (float val); Calculates the smallest integer that is bigger than val.Example: ceil(4.3) = 5.

    float floor (float val) ; Calculates the largest integer that is smaller than val.Example: ceil(4.8) = 4.

    float fmod (float x, float y); Returns the remainder of x / y. For example: fmod(15.0,4.0)= 3.

    float pow (float x, float y); Returns x to the powery.Logical operations:You can also perform logic operations with variables, like AND, OR and NOT operations,using the following operators:Operator Description

    ! NOT (bit level) Example: P1_0 = !P1_0;~ NOT (byte level) Example: P1 = ~P1;

    & AND| OR

    Note that those logic operation are performed on the bit level of the registers. To understandthe effect of such operation on registers, it's easier to look at the bits of a variable (which iscomposed of one or more register). For example, a NOT operation will invert all the bit of aregister. Those logic operator s can be used in many ways to merge different bits of differentregisters together.

    For example, consider the variable 'P1', which is of type 'char', and hence stored in an 8-bit

    43

  • 7/29/2019 53189679 Project Report Final

    45/67

    register. Actually P1 is an SFR, whose 8 bits represents the 8 I/O pins of Port 1. It is requir edin that example to clear the 4 lower bits of that register without changing the state of the 4other which may be used by other equipment. This can be done using logical operatorsaccording to the following code:

    P1 = P1 & 0xF0; (Adding '0x' before a number indicates that it is a hexadecimal one)

    Here, the value of P1 is ANDed with the variable 0xF0, which in the binary base is'11110000'. Recalling the two following relations:

    1 AND X = X0 AND X = 0(where 'X' can be any binary value)

    You can deduce that the 4 higher bits of P1 will remain unchanged, while the 4 lower bitswill be cleared to 0.

    By the way, note that you could also perfor m the same operation using a decimal variable

    instead of a hexadecimal one, for example, the following code will have exactly the sameeffect than the pr evious one (because 240 = F0 in HEX):

    P1 = P1 & 240;

    A similar types of operations that can be per for med on a port, is to to set some of its bits to 1without affecting the others. For example, to set the first and last bit of P1, without affectingthe other, the following source code can be used:

    P1 = P1 | 0x81;

    Here, P1 is ORed with the value 0x81, which is '10000001' in binar y. Recalling the twofollowing relations:

    1 OR X = 10 OR X = X(where 'X' can be any binary value)

    You can deduce that the first and last pins of P1 will be turned on, without affecting the stateof the other pins of port 1. Those are just a few example of the manipulations that can bedone to register s using logical operators. Logic operators can also be used to define very

    specific conditions, as you shall see in the next section.

    The last types of logic operation studied in this tutorial is the shifting. It can be useful theshift the bit of a register the right or to the left in various situations. this can be done using thefollowing two operators:Operator Description>> Shift to the right

  • 7/29/2019 53189679 Project Report Final

    46/67

    You can clear ly notice that the content of P1 have been shifted 8 steps to the left.

    Condit ions and loops

    In most programs, it is required at a certain time, to differentiate between different situations,

    to make decision according to specific input, or to direct the flow of the code depending onsome criteria. All the above situation descr ibe an indispensable aspect of programming:'conditions'. In other words, this feature allows to execute a block of code only under certainconditions, and otherwise execute another code block or continue with the flow of the

    program.

    The most famous way to do that is to use the 'if' statement, according to the following syntax.

    if (expression) {...code to be executed...

    }

    It is important to see how the code is organized in this part. The 'expression' is the conditionthat shall be valid for the 'code block' to be executed. the code block is all delimited by thetwo brackets '{' and '}'. I n other words, all the code between those two brackets will beexecuted if and only if the expression is valid. The expression can be any combination ofmathematical and logical expressions, as you can see in the following example:

    if ( (P1 == 0) & (a

  • 7/29/2019 53189679 Project Report Final

    47/67

    ...}else if( expression_2) {...code block 2...}else if( expression_3) {

    ...code block 3...}else{...code block 4...}

    Here, There are four different code blocks, only one shall be executed if and only if thecorresponding condition is true. The last code block will only be executed if none of the

    previous expression is valid. Note that you can have as many 'else if' blocks as you need, each

    one with its corresponding condition, BUT you can only have one 'else' block, which iscompletely logical. However you can chose not to have and 'else' block at all if you want.

    There are some other alternatives to the 'if...else' code block, that can provide faster executionspeeds, but also have some limitations and restrictions like the 'Select...case' code block. Fornow, it is enough to understand the 'if...else' code block, whose performance is quite fair andhave a wide range of applications.

    Another ver y important tool in the programming languages is the loop. In C language like inmany others, loops are usually restr icted to certain number of loops like in the 'for ' code blockor restricted to a certain condition like the 'while' block.

    Let's start with the 'for' code block, which is a highly controllable and configurable loop.consider the following example source code:

    for(i=0;i

  • 7/29/2019 53189679 Project Report Final

    48/67

    conditions is satisfied, the code will keep looping. Finally, step is the increase or decrease ofthe counting variable, it can be any statement that changes its value, whether by an additionor subtraction.

    The second type of loop that we are going to study is the 'while' loop. the syntax of this one issimpler than the previous one, as you can observe in the following example source code, that

    is equivalent to the previous method:

    while( i < 10) {P0 = i;i = i +1;}

    Here there is only one parameter to be defined, which is the condition to keep this loop alive,which is 'i < 10' in our example. Then, it is the responsibility of the programmer to design thesoftware carefully to provide an exit for that loop, or to make it an infinite loop. Bothtechniques ar e commonly used in microcontroller programs, as you shall see later on alongthis tutorial.

    Functions

    Functions are way of organizing your code, reducing its size, and increasing its overallperformance, by grouping relatively small parts of code to be reused many times in the sameprogram. A new function can be created according to the following syntax:

    Function_name(parameter_1, Parameter_2, Parameter_3){...function body...return value (optional)

    ...}

    This is the general form of a function. The number of parameters of the function can be mor ethan the three parameters of the examples above, as it can be zer o, all depends on the typeand use of the function. The function's body is usually a sub program that implies the

    parameters to produce the required result. some functions will also generate an output, likethe cos() function, through the 'return' command, which will output the value next to it.Usually the 'return' command is used at the end of the function.

    A very common use of functions without return value is to create delays in a software,consider the following function:

    delay(unsigned int y){unsigned int i;for(i=0;i

  • 7/29/2019 53189679 Project Report Final

    49/67

    this can be called from anywhere in the program according to the following syntax:

    delay(30000);

    this line of code would cause the program to pause for approximately one second on a 12MHz clock on a 8051 microcontroller.

    A common example of a function with a return value, is a function that will calculate theangle in radian of a given angle in degrees, as all the trigonometr ic functions that are included

    by default take angles in radians. This function can be as the following:

    deg_to_rad(float deg){float rad;rad = (deg * 3.14) /180;retrun rad;

    }

    This function named 'deg_to_rad' will take as a parameter an angle in degrees and output an

    angle in radians. It can be called in your program according to this syntax:

    angle = deg_to_r ad(102,18);

    where angle should be already defined as a float, and where will be stored the value returnedby the function, which is the angle in radians equivalent to 102.18

    Another important note about functions in the 'main' function. Any C program must contain afunction named 'main' which is the place where the program's execution will star t. more

    precisely, for microcontrollers, it were the execution will start after a reset operation, or whena microcontroller circuit is turned ON. The 'main' f unction has no parameters, and is writtenlike this:

    main(){...code of the main functions...}

    Organization of a C program

    All C programs have this common organization scheme,sometimes it's followed, sometimesit's not, however, it is imperative for this category ofprogramming that this organizationscheme be followed in order to be able to develop yourapplications successfully. Anyapplication can be divided into the following parts, noting thatis should be written in this

    order:

    a. Headers Includes and constants definitionsIn this part, header files (.h) are included into your sourcecode. those headers files can besystem headers to declare the name of SFRs, to define newconstants, or to include

    mathematical functions like trigonometric functions, rootsquar e calculations or numbersapproximations. Header files can also contain your ownfunctions that would be shared byvarious programs.

    48

  • 7/29/2019 53189679 Project Report Final

    50/67

    b. Variables declarationsMore precisely, this part is dedicated to 'Global Var iables'declarations. Var iables declar ed inthis place can be used anywhere in the code. Usually in

    microcontroller programs, var iablesare declared as global var iables instead of local variables,unless your are running short ofRAM memory and want to save some space, so we use localvar iables, whose values will belost each time you switch from a function to another. Tosummarize, global variables aseasier to use and implement than local variables, but theyconsume more memory space.

    c. functions' bodyHere you group all your functions. Those functions can besimple ones that can be calledfrom another place in your program, as they can be calledfrom an 'inter rupt vector'. In otherwords, the sub-programs to be executed when an interruptoccurs is also written in this place.

    d. InitializationThe particular ity of this part is that it is executed only onetime when the microcontroller was

    just subjected to a 'RESET' or when power is just switchedON, then the processor continueexecuting the rest of the program but never executes this partagain. This particular ity makesit the perfect place in a program to initialize the values of someconstants, or to define themode of operation of the timers, counters, interrupts, andother features of the

    microcontroller.

    e. Infinite loopAn infinite loop in a microcontroller program is what is going to keep it alive, because aprocessor have to be allays running for the system to function, exactly like a heart have to bealways beating for a person to live. Usually this part is the cor e of any program, and its fromhere that all the other functions are called and executed.

    Simple C program for 89S52

    Here is a very simple but complete example program to blink a LED. Actually it is the source

    code of the example project that we are going to construct in the next part of the tutorial, butfor now it is important to concentrate on the programming to summar ize the notionsdiscussed above.

    #include #include

    delay(unsigned int y){unsigned int i;for(i=0;i

  • 7/29/2019 53189679 Project Report Final

    51/67

    which is simple a function to create a delay controlled via the parameter 'y'. Then comes themain function, with an infinite loop (the condition for that loop to remain will always besatisfied as it is '1'). Inside that loop, the pin number 0 of port 1 is constantly turned ON andOFF with a delay of approximately one second.

    As you will see in the next part, A simple circuit can be constructed and a LED can be

    connected to the pin P1_0 to see how software and hardware adjustments can affect thebehavior of you circuits.

    Using t he KEIL environment

    KEIL uVision is the name of a software dedicated to thedevelopment and testing of a familyof microcontroller s based on 8051 technology, like the 89S52which we are going to use

    along this tutorial. You can can download an evaluationversion of KEIL at their website:http://www.keil.com/c51/. Most versions share merely the sameinterface, this tutorial usesKEIL C51 uVision 3 with the C51 compiler v8.05a.

    To create a project, write and test the previous example source

    code, follow the followingsteps:

    Open Keil and start a new project:

    50

  • 7/29/2019 53189679 Project Report Final

    52/67

    You will pr ompted to chose a name for your new project, Create a separate folder where allthe files of your project will be stored, chose a name and click save. The following windowwill appear, where you will be asked to select a device for Target 'Target 1':

    51

  • 7/29/2019 53189679 Project Report Final

    53/67

    From the list at the left, seek for the brand name ATMEL, then under ATMEL, select

    AT89S52. You will notice that a brief descr iption of the deviceappears on the right. Leavethe two upper check boxes unchecked and click OK. The AT89S52

    will be called your'Target device', which is the final destination of your source code.You will be asked whetherto 'copy standard 8051 startup code' click No.

    click File, New, and something similar to the following window should appear. The boxnamed 'Text1' is where your code should be written later.

    52

  • 7/29/2019 53189679 Project Report Final

    54/67

    Now you have to click 'File, Save as' and chose a file name for your source code endingwith the letter '.c'. You can name is 'code.c' for example, and click save. Then you have toadd this file to your project work space at the left as shown in the following screen shot:

    53

  • 7/29/2019 53189679 Project Report Final

    55/67

    After right- clicking on 'source group 1', click on 'Add files to group...', then you will beprompted to browse the file to add to 'source group 1', chose thefile that you just saved,eventually 'code.c' and add it to the source group. You will notice

    that the file is added to theproject tree at the left.

    In some versions of this software you have to turn ON manually the option to generate HEX

    files. make sure it is turned ON, by right-clicking on target 1,Options for target 'target 1',then under the 'output' tab, by checking the box 'generate HEXfile'. This step is ver yimportant as the HEX file is the compiled output of your projectthat is going to betransferred to the microcontroller.

    You can then start to write the sour ce code in the window titled 'code.c' then before testingyour source code, you have to compile your source code, and correct eventual syntax errors.In KEIL IDE, this step is called 'rebuild all targets' and has this icon: .

    54

  • 7/29/2019 53189679 Project Report Final

    56/67

    You can use the output window to tr ack eventual syntax error s, but also to check theFLASH memory occupied by the program (code = 49) as well as the registers occupied in theRAM (data = 9). If after rebuilding the targets, the 'output window' shows that there is 0error, then you are ready to test the performance of your code. In keil, like in mostdevelopment environment, this step is called Debugging, and has this icon: . After clickingon the debug icon, you will notice that some part of the user interface will change, some new

    icons will appear, like the r un icon circled in the following figure:

    Figure: 2.8.f

    55

  • 7/29/2019 53189679 Project Report Final

    57/67

    You can click on the 'Run' icon and the execution of the program will start. In our example,you can see the behavior of the pin 0 or port one, but clicking on'peripherals, I/O ports, Port1'. You can always stop the execution of the program by clicking

    on the stop button ( ) andyou can simulate a reset by clicking on the 'r eset' button .

    You can also control the execution of the program using thefollowing icons:which allows you to follow the execution step by step. Then, whenyou're finished with thedebugging, you can always return to the programming inter face

    by clicking again on thedebug button ( ).

    There are many other features to discover in the KEIL IDE. Youwill easily discover them infirst couple hours of practice, and the more important of them willbe presented along the restof this tutorial.

    56

  • 7/29/2019 53189679 Project Report Final

    58/67

    7.2 ProjectProgramming

    57

  • 7/29/2019 53189679 Project Report Final

    59/67

    MOTOR CONTROL LOGIC

    CONTROL LOGIC

    TERMINALSMOTION P3.0 P3.1 P3.2 P3.3

    Forward 0 1 0 1

    Reverse 1 0 1 0Left 1 0 0 1

    Right 0 1 1 0Stop 1 1 1 1

    58

  • 7/29/2019 53189679 Project Report Final

    60/67

  • 7/29/2019 53189679 Project Report Final

    61/67

    1. The installation should be complete if all the instructions were followed cor rectly.

    1 How to burn the Microcontroller

    1. Double click on the icon for SpiPgm. And the following window will appear in front ofyou.

    2. Now select the device AT89S52.

    60

  • 7/29/2019 53189679 Project Report Final

    62/67

    3. Now click on Erase to erase the contents of microcontroller.

    4. Now click on Open File and select the desired program.

    61

  • 7/29/2019 53189679 Project Report Final

    63/67

    5. Now click on Program to burn the microcontroller.

    6. Your program should now run if all steps were followed correctly and your program isalso correct.

    62

  • 7/29/2019 53189679 Project Report Final

    64/67

    CHAPTER 8

    CAMERA INTERFACING

    In this project, wireless camera was applied to survey thesurrounding. The wireless camer a

    has tr ansmitter and receiver that able it to transmit image andsound data wirelessly.

    CAMERA RECEIVER

    USB VIDEO GRABBER

    Above figure show the USB video grabber that use to view image by using computer . Thisdevice has build in driver and Ulead VideoStudio SE DVD software that useful to view theimage and table below show the wireless camera specification.

    _ Image Pickup Device 1/3 1/4 Inch CMOS_ TV Syst em PAL/CCIR NTSC/EIA_ Scan Frequency PAL/CCIR: 50Hz NTSC/EIA:

    60Hz_ Definition 380 TV Lines_ Min Illumination 3LUX_ Output Power 50mW 200mW_ Transmitter Range 100M_ Power Supply DC +9~12V

    63

  • 7/29/2019 53189679 Project Report Final

    65/67

    CHAPTER 9

    FINAL ASSEMBLING AND TROUBLE SHOOTING

    1. The micro-controller unit module was fixed on the body using screws and nuts.

    2. The H-Bridge module was fixed on to the topof the body using screws and nuts.

    3. The motors extra edges were cut away and holes were drilled on its one arm to be attachedto body.

    4. Using screws and hexagonal nuts, the motors were attached to the body in properalignment.

    5. The sensor were attached at the front side and when any obstacle comes infront of it ,robot stops .

    6. Wheels were fixed on to the shafts of motors using glue and Caster was attached in thefront using its nut.

    8. The micro-controller AT89S52 was taken and program was burned in it using SPI -PGM37software.

    9. The Metal sensor is attached at the front side. The signal which receiver were gettingwas of low voltage, so to increase the voltage we use the integrator .

    10. During the fixing of motors, gears of one motor were damaged due to which the robotsmovement was being hampered. This motor had to be replaced.

    11. Also, the sensors position was difficult to adjust as it w as touching the ground so weplaced it on the wooden sheet.

    12. The robot was successfully assembled and made operational. The procedure took about10 weeks.

    64

  • 7/29/2019 53189679 Project Report Final

    66/67

    CHAPTER 10

    RESULT AND DISCUSSION

    The SPY Robot was successfully assembled and after burning the program in the

    AT89S52, all components were working properly and we could see live video onlaptop and movement of robot could be controlled by mobile. The result is

    based on the objective of the project. They are to bu ild the robot that able tosenseobstacle when the robot detect the obstacle in front of it and to build a robotthat able

    to stop moving when there is metal a detected.DISCUSSION

    This robot is intelligent spy robot that in this robot thereare many circuit attach to each other

    like motor driver, IR sensor, metal detector and PICmain board. All board have itsconnection to show that it related to each other forexample IR sensor use to detect object infront of it and after the object detected, it send signalto comparator to convert the signal todigital. Then the digital signal logic 1 at 3-5 Volts will

    receive by main board that consist PICto execute the signal. After the signal is executed, thesignal is send to motor driver wheremotor driver will receive the signal of DC motor directionand DC motor speed.DC motor is like execute device where when the sensorsense object , it will send to PIC andPIC send the signal to those motors to operate. Speedcontrol is most important part in

    programming to control motor because speed controlwill cause the robot to avoid co llisioninto the object because there are inertia when the robotmoving. The robot will not able to

    stop on time if the speed is high65

  • 7/29/2019 53189679 Project Report Final

    67/67

    CHAPTER 11

    FUTURE PROSPECTS

    1 . To reduce the size of unit we can use smd.

    2. Replacement of transmitter with low power transmitter & receiver with highly sensitivereceiver to reduce the power consumption

    3 . The range can be increased.

    Additional modules can be added to this application any time. It can be modified in future to

    add more features. Provisions have been made to upgrade the software.

    As all the resources used to develop this application were easily available, this applicationhas a cost benefit ratio of more than one. This makes this application of great use in future.

    REFRENCES

    1. 8051 book written by MAZIDI2. http://en.wikipedia.org/wiki/acuator3. http://en.wikipedia.org/wiki/Brushed_DC_electric_motor4. www.DatasheetCatalog.com5. MicroElectronika. C Compiler for Microchip PIC Microcontrollers .Micro C users

    manual.6. . http://www.surveyor.com/SRV_info.html. Last Updated -27 April 2009 15:15 GMT7. http://www.microdigitaled.com/8051/Software/keil_tutorial.pdf


Recommended