ultrasonic based distance measurement

98
ULTRASONIC BASED DISTANCE MEASUREMENT

Upload: deepkar-reddy

Post on 22-Oct-2014

1.108 views

Category:

Documents


11 download

TRANSCRIPT

Page 1: Ultrasonic Based Distance Measurement

ULTRASONIC BASED DISTANCE MEASUREMENT

Page 2: Ultrasonic Based Distance Measurement

TABLE OF CONTENTS

1. ABSTRACT

2. SCHEMATIC DIAGRAM

3. CIRCUIT DESCRIPTION

4. INTRODUCTION

4.1. EMBEDDED SYSTEMS

4.2. MICROCONTROLLER

4.3. SENSORS

4.4. LCD

4.5. LED

4.6. CVAVR

5. COMPONENT DESCRIPTION

5.1. ATMEGA8515

5.2. ULTRASONIC SENSOR (TS 601)

5.3. TRANSISTOR AS SWITCH

5.4. BUZZER

5.5. ISP PROGRAMMER

6. CODING

7. BIBILOGRAPHY

Page 3: Ultrasonic Based Distance Measurement

ABSTRACT

Ultrasonic sensors are commonly used for a wide variety of non-contact presence,

proximity, or distance measuring applications. These devices typically transmit a short

burst of ultrasonic sound toward a target, which reflects the sound back to the sensor. The

system then measures the time for the echo to return to the sensor and computes the

distance to the target using the speed of sound in the medium.

This project is used to measure the distance of the object. The ultrasonic waves

spread in the air and hit the nearest object and reflected. The reflected signal from the

object is received by the ultrasonic receiver. The received wave is given to the input of

the microcontroller. Now the microcontroller compares the time between the transmitted

signal and received signal and generates the corresponding pulse output which is equal to

the distance of the object.

This "ECHO" Ultrasonic Distance Sensor from Rhydolabz is an amazing

product that provides very short (2CM) to long-range (3M) detection and ranging. The

sensor provides precise, stable noncontact distance measurements from 2cm to 3 meters

with very high accuracy. Its compact size, higher range and easy usability make it a

handy sensor for distance measurement and mapping. The board can easily be interfaced

to microcontrollers where the triggering and measurement can be done using one I/O pin.

The sensor transmits an ultrasonic wave and produces an output pulse that corresponds to

the time required for the burst echo to return to the sensor. By measuring the echo pulse

width, the distance to target can easily be calculated.

Here we are using 40 KHz ultrasonic sensors. Microcontroller is Measured

the distance and that is displayed on the display 2x16 characters. The microcontroller will

generate measurements using 8bit timer port frequency 40 kHz, which passes through

inverters for amplifying the current and used to drive the ultrasonic transmitter that will

broadcast the ultrasonic waves at 40 kHz. Simultaneously with the activation of the

posting run 16bit timer that measures time by receiving the reflected signal. Sending a

signal spread environment. After hitting the barrier is part of it is reflected and returns

Page 4: Ultrasonic Based Distance Measurement

back to the sensor. The reflected signal is detected by the receiver, at this time

microcontroller acts as a input so it takes signal from receiver and it calculates the

distance when the signal is coming from object to receiver and that distance is displayed

on LCD 16*2 through microcontroller.

This technology can be used for measuring: wind speed and direction

(anemometer), fullness of a tank and speed through air or water. For measuring speed or

direction a device uses multiple detectors and calculates the speed from the relative

distances to particulates in the air or water. To measure the amount of liquid in a tank, the

sensor measures the distance to the surface of the fluid. Further applications include:

humidifiers, sonar, medical ultrasonography, burglar alarms and non-destructive testing.

BLOCK DIAGRAM:

LCD

ATMEGA8515

ULTRA SONICSENSOR

Page 5: Ultrasonic Based Distance Measurement

REQUIREMENTS:

HARDWARE REQUIREMENTS:

ATMEGA8515

LCD 16*2

ULTRASONIC SENSOR (TS601)

TRANSISTOR

BUZZER

LED

SOFTWARE REQUIREMENTS:

CVAVR-C COMPILER

EMBEDDED C PROGRAMMING

ISP PROGRAMMER

Page 6: Ultrasonic Based Distance Measurement

SCHEMATIC DIAGRAM

ATMEGA8 5 1 5 ISP

2 2 K

GND

V C C

F R O M I S P (4 )

P D 2 (I N T0 )

P B 68 . 0 0 M H z

D 6 (L C D )

POW ER SU PPL Y(5 VD C )

R8

R7

R6

R5

R4

R1

R2

R3

VCC

1 2 3 4 5 6 7 8 9

BC 109

0 . 1 u f / 3 5 VC

1 0 4 p f

1 K

GND

1 0 0 0 u f / 3 5 V

P A 1

XTA L 1

GND

S W 1

D 4 (L C D )

V C C

V C C

2

GND

ATMEGA8 5 1 5 C R YSTAL

B U Z Z E R

1

2

2 2 0 o h m

PC1

P A 7

(9V,1 AMP)

G N D

1 23 45 67 89 1 0

L C D

2 2 p f

XTA L 1

GND

R ESET

R E S E T

TS601(ULTRA SONIC SENSOR)

123

2 2 0 o h m s

- +

B R I D G E R E C TI F I E R

1

4

3

2

E N (L C D )

GND V C C

V C C

V C C

D 5 (L C D )F R O M I S P (2 )4 . 7 K

F R O M I S P (1 0 )

GND

P B 5

P A 4

S R E S E T

1 0 K P U L L U P

V C C

2 3 0 V , A . C

12

G N D

VCC

R1

R2

R3

R4

R7

R6

R5

R8

1 0 K P U L L U P987654321

TRANSFORMER

G N D

D 7 (L C D )

R E D L E D & B U Z Z E R

GND

S I G (TS (6 0 1 ))

XTA L 2

GND

P

V C C

TR I M P O T

5 K

P A 3

7805 REGUA LTOR1 3

V I N V O U T

V C C

-XTA L 2

V C C =5 V

P B 7

VCC

R1

R2

R3

R4

R7

R6

R5

R8

1 0 K P U L L U P

9 8 7 6 5 4 3 2 1

L E D

I

V C C

3 3 p f

GND

GNDVCCVEERSRWEND0

D3D2

D4D5D6D7

D1

LED+LED-

123456789

1 01 11 21 31 41 51 6

P A 6

F R O M I S P (6 )& R E S E T

R E D L E D

P A 5

R S (L C D )

S I G

+

A TMEGA 8515 L

9

1 8

1 9

2 93 03 1

3 2

1 01 11 21 31 41 51 61 7

4 03 93 83 73 63 53 43 3

2 82 72 62 52 42 32 22 1

12345678

2 0

R E S E T

XTA L 2

XTA L 1

P E 2 (O C 1 B )P E 1 (A L E )

P E 0 (I C P / I N T2 )

P A 7 / A D 7

(R XD ) P D 0(TD X) P D 1(I N T0 ) P D 2(I N T1 ) P D 3(XC K ) P D 4(O C 1 A ) P D 5(W R ) P D 6(R D ) P D 7

V C CP A 0 / A D 0P A 1 / A D 1P A 2 / A D 2P A 3 / A D 3P A 4 / A D 4P A 5 / A D 5P A 6 / A D 6

P C 7 (A 1 5 )P C 6 (A 1 4 )P C 5 (A 1 3 )P C 4 (A 1 2 )P C 3 (A 1 1 )P C 2 (A 1 0 )

P C 1 (A 9 )P C 0 (A 8 )

(O C 0 / T0 ) P B 0(T1 ) P B 1(A I N 0 ) P B 2(A I N 1 ) P B 3(S S ) P B 4(M O S I ) P B 5(M I S O ) P B 6(S C K ) P B 7

G N D

V C C

2 2 p f

Page 7: Ultrasonic Based Distance Measurement

CIRCUIT DESCRIPTION

DESIGNING:

Main intension of this project is to design an ULTRASONIC BASED

DISTANCE MEASUREMENT using microcontroller.

1) Designing the power supply for the entire circuitry.

2) Selection of microcontroller that suits our application.

3) Selection of LCD

4) Selection of sensor

Complete studies of all the above points are useful to develop this project.

POWER SUPPLY SECTION:

In-order to work with any components basic requirement is power supply.

In this section required voltage level is 5V DC.

Now the aim is to design the power supply section which converts 230V

AC in to 5V DC. Since 230V AC is too high to reduce it to directly 5V DC, therefore we

need a step-down transformer that reduces the line voltage to certain voltage that will

help us to convert it in to a 5V DC. Considering the efficiency factor of the bridge

rectifier, we came to a conclusion to choose a transformer, whose secondary voltage is 3

to 4 V higher than the required voltage i.e. 5V. For this application 0-9V transformers is

used, since it is easily available in the market.

The output of the transformer is 9V AC; it feed to rectifier that converts AC to

pulsating DC. As we all know that there are 3 kind of rectifiers that is

1) half wave

2) Full wave and

3) Bridge rectifier

Page 8: Ultrasonic Based Distance Measurement

Here we short listed to use Bridge rectifier, because half wave rectifier has

we less in efficiency. Even though the efficiency of full wave and bridge rectifier are the

same, since there is no requirement for any negative voltage for our application, we gone

with bridge rectifier.

Since the output voltage of the rectifier is pulsating DC, in order to

convert it into pure DC we use a high value (1000UF/1500UF) of capacitor in parallel

that acts as a filter. The most easy way to regulate this voltage is by using a 7805 voltage

regulator, whose output voltage is constant 5V DC irrespective of any fluctuation in line

voltage.

SELECTION OF MICROCONTROLLER:

As we know that there so many types of micro controller families that are

available in the market.

Those are

1) 8051 Family

2) AVR microcontroller Family

3) PIC microcontroller Family

4) ARM Family

To implement this application 8051 is some what difficult. So, that is the

reason we are selecting AVR controller to fulfill our requirement.

Here we are selecting ATMEGA8515 controller. If user want to implement any

application using ATMEGA8515 some basic connections are required.

Those are:

1) power supply section

2) pull-up resistors for PORTS

3) Reset circuit

4) Crystal circuit

5) ISP circuit (for program dumping)

SELECTION OF LCD:

A liquid crystal display (LCD) is an electronically-modulated optical

device shaped into a thin, flat panel made up of any number of color or monochrome

Page 9: Ultrasonic Based Distance Measurement

pixels filled with liquid crystals and arrayed in front of a light source (backlight) or

reflector. Here LCD is used for only debugging purpose. Ultrasonic sensor values are

displayed n the LCD.

SELECTION OF SENSOR:

A sensor is a device that measures a physical quantity and converts it into

a signal which can be read by an observer or by an instrument. Here in this project I

selected TS 601 ultrasonic sensor used to measure the distance.

CIRCUIT OPERATION:

This project is used to measure the distance of the object. The ultrasonic waves

spread in the air and hit the nearest object and reflected. The reflected signal from the

object is received by the ultrasonic receiver. The received wave is given to the input of

the microcontroller. Now the microcontroller compares the time between the transmitted

signal and received signal and generates the corresponding pulse output which is equal to

the distance of the object.

This "ECHO" Ultrasonic Distance Sensor from Rhydolabz is an amazing

product that provides very short (2CM) to long-range (3M) detection and ranging. The

sensor provides precise, stable noncontact distance measurements from 2cm to 3 meters

with very high accuracy. Its compact size, higher range and easy usability make it a

handy sensor for distance measurement and mapping. The board can easily be interfaced

to microcontrollers where the triggering and measurement can be done using one I/O pin.

The sensor transmits an ultrasonic wave and produces an output pulse that corresponds to

the time required for the burst echo to return to the sensor. By measuring the echo pulse

width, the distance to target can easily be calculated.

Here we are using 40 KHz ultrasonic sensors. Microcontroller is Measured

the distance and that is displayed on the display 2x16 characters. The microcontroller will

generate measurements using 8bit timer port frequency 40 kHz, which passes through

inverters for amplifying the current and used to drive the ultrasonic transmitter that will

Page 10: Ultrasonic Based Distance Measurement

broadcast the ultrasonic waves at 40 kHz. Simultaneously with the activation of the

posting run 16bit timer that measures time by receiving the reflected signal. Sending a

signal spread environment. After hitting the barrier is part of it is reflected and returns

back to the sensor. The reflected signal is detected by the receiver, at this time

microcontroller acts as a input so it takes signal from receiver and it calculates the

distance when the signal is coming from object to receiver and that distance is displayed

on LCD 16*2 through microcontroller.

Page 11: Ultrasonic Based Distance Measurement

EMBEDDED SYSTEMS

Embedded systems are electronic devices that incorporate microprocessors

with in their implementations. The main purposes of the microprocessors are to simplify

the system design and provide flexibility. Having a microprocessor in the device helps in

removing the bugs, making modifications, or adding new features are only matter of

rewriting the software that controls the device. Or in other words embedded computer

systems are electronic systems that include a microcomputer to perform a specific

dedicated application. The computer is hidden inside these products. Embedded systems

are ubiquitous. Every week millions of tiny computer chips come pouring out of factories

finding their way into our everyday products.

Embedded systems are self-contained programs that are embedded within

a piece of hardware. Whereas a regular computer has many different applications and

software that can be applied to various tasks, embedded systems are usually set to a

specific task that cannot be altered without physically manipulating the circuitry. Another

way to think of an embedded system is as a computer system that is created with optimal

efficiency, thereby allowing it to complete specific functions as quickly as possible.

Embedded systems designers usually have a significant grasp of hardware

technologies. They use specific programming languages and software to develop

embedded systems and manipulate the equipment. When searching online, companies

offer embedded systems development kits and other embedded systems tools for use by

engineers and businesses.

Embedded systems technologies are usually fairly expensive due to the

necessary development time and built in efficiencies, but they are also highly valued in

specific industries. Smaller businesses may wish to hire a consultant to determine what

sort of embedded systems will add value to their organization.

Page 12: Ultrasonic Based Distance Measurement

CHARACTERISTICS:

Two major areas of differences are cost and power consumption. Since

many embedded systems are produced in tens of thousands to millions of units range,

reducing cost is a major concern. Embedded systems often use a (relatively) slow

processor and small memory size to minimize costs.

The slowness is not just clock speed. The whole architecture of the

computer is often intentionally simplified to lower costs. For example, embedded systems

often use peripherals controlled by synchronous serial interfaces, which are ten to

hundreds of times slower than comparable peripherals used in PCs. Programs on an

embedded system often run with real-time constraints with limited hardware resources:

often there is no disk drive, operating system, keyboard or screen. A flash drive may

replace rotating media, and a small keypad and LCD screen may be used instead of a

PC's keyboard and screen.

Firmware is the name for software that is embedded in hardware devices,

e.g. in one or more ROM/Flash memory IC chips. Embedded systems are routinely

expected to maintain 100% reliability while running continuously for long periods,

sometimes measured in years. Firmware is usually developed and tested too much

harsher requirements than is general-purpose software, which can usually be easily

restarted if a problem occurs.

PLATFORM:

There are many different CPU architectures used in embedded designs.

This in contrast to the desktop computer market which is limited to just a few competing

architectures mainly the Intel/AMD x86 and the Apple/Motorola/IBM Power PC’s which

are used in the Apple Macintosh. One common configuration for embedded systems is

the system on a chip, an application-specific integrated circuit, for which the CPU was

purchased as intellectual property to add to the IC's design.

Page 13: Ultrasonic Based Distance Measurement

TOOLS:

Like a typical computer programmer, embedded system designers use

compilers, assemblers and debuggers to develop an embedded system. Those software

tools can come from several sources:

Software companies that specialize in the embedded market Ported from

the GNU software development tools. Sometimes, development tools for a personal

computer can be used if the embedded processor is a close relative to a common PC

processor. Embedded system designers also use a few software tools rarely used by

typical computer programmers. Some designers keep a utility program to turn data files

into code, so that they can include any kind of data in a program. Most designers also

have utility programs to add a checksum or CRC to a program, so it can check its

program data before executing it.

OPERATING SYSTEM:

They often have no operating system, or a specialized embedded operating

system (often a real-time operating system), or the programmer is assigned to port one of

these to the new system.

DEBUGGING:

Debugging is usually performed with an in-circuit emulator, or some type

of debugger that can interrupt the micro controller’s internal microcode. The microcode

interrupt lets the debugger operate in hardware in which only the CPU works. The CPU-

based debugger can be used to test and debug the electronics of the computer from the

viewpoint of the CPU.

Developers should insist on debugging which shows the high-level

language, with breakpoints and single stepping, because these features are widely

available. Also, developers should write and use simple logging facilities to debug

sequences of real-time events. PC or mainframe programmers first encountering this sort

of programming often become confused about design priorities and acceptable methods.

Mentoring, code-reviews and ego less programming are recommended.

Page 14: Ultrasonic Based Distance Measurement

DESIGN OF EMBEDDED SYSTEMS:

The electronics usually uses either a microprocessor or a microcontroller.

Some large or old systems use general-purpose mainframes computers or minicomputers.

START-UP:

All embedded systems have start-up code. Usually it disables interrupts,

sets up the electronics, tests the computer (RAM, CPU and software), and then starts the

application code. Many embedded systems recover from short-term power failures by

restarting (without recent self-tests). Restart times under a tenth of a second are common.

Many designers have found one of more hardware plus software-

controlled LED’s useful to indicate errors during development (and in some instances,

after product release, to produce troubleshooting diagnostics). A common scheme is to

have the electronics turn off the LED(s) at reset, whereupon the software turns it on at the

first opportunity, to prove that the hardware and start-up software have performed their

job so far. After that, the software blinks the LED(s) or sets up light patterns during

normal operation, to indicate program execution progress and/or errors. This serves to

reassure most technicians/engineers and some users.

THE CONTROL LOOP:

In this design, the software has a loop. The loop calls subroutines. Each

subroutine manages a part of the hardware or software. Interrupts generally set flags, or

update counters that are read by the rest of the software. A simple API disables and

enables interrupts. Done right, it handles nested calls in nested subroutines, and restores

the preceding interrupt state in the outermost enable. This is one of the simplest methods

of creating an exocrine.

Typically, there's some sort of subroutine in the loop to manage a list of

software timers, using a periodic real time interrupt. When a timer expires, an associated

subroutine is run, or flag is set. Any expected hardware event should be backed-up with a

software timer. Hardware events fail about once in a trillion times.

Page 15: Ultrasonic Based Distance Measurement

State machines may be implemented with a function-pointer per state-

machine (in C++, C or assembly, anyway). A change of state stores a different function

into the pointer. The function pointer is executed every time the loop runs.

Many designers recommend reading each IO device once per loop, and

storing the result so the logic acts on consistent values. Many designers prefer to design

their state machines to check only one or two things per state. Usually this is a hardware

event, and a software timer. Designers recommend that hierarchical state machines

should run the lower-level state machines before the higher, so the higher run with

accurate information.

Complex functions like internal combustion controls are often handled

with multi-dimensional tables. Instead of complex calculations, the code looks up the

values. The software can interpolate between entries, to keep the tables small and cheap.

One major disadvantage of this system is that it does not guarantee a time

to respond to any particular hardware event. Careful coding can easily assure that nothing

disables interrupts for long. Thus interrupt code can run at very precise timings. Another

major weakness of this system is that it can become complex to add new features.

Algorithms that take a long time to run must be carefully broken down so only a little

piece gets done each time through the main loop.

This system's strength is its simplicity, and on small pieces of software the

loop is usually so fast that nobody cares that it is not predictable. Another advantage is

that this system guarantees that the software will run. There is no mysterious operating

system to blame for bad behavior.

USER INTERFACES:

Interface designers at PARC, Apple Computer, Boeing and HP minimize

the number of types of user actions. For example, use two buttons (the absolute

minimum) to control a menu system (just to be clear, one button should be "next menu

entry" the other button should be "select this menu entry"). A touch-screen or screen-edge

buttons also minimize the types of user actions.

Page 16: Ultrasonic Based Distance Measurement

Another basic trick is to minimize and simplify the type of output. Designs

should consider using a status light for each interface plug, or failure condition, to tell

what failed. A cheap variation is to have two light bars with a printed matrix of errors that

they select- the user can glue on the labels for the language that she speaks.

For example, Boeing's standard test interface is a button and some lights.

When you press the button, all the lights turn on. When you release the button, the lights

with failures stay on. The labels are in Basic English.

Designers use colors. Red defines the users can get hurt- think of blood.

Yellow defines something might be wrong. Green defines everything's OK.

Another essential trick is to make any modes absolutely clear on the user's

display. If an interface has modes, they must be reversible in an obvious way. Most

designers prefer the display to respond to the user. The display should change

immediately after a user action. If the machine is going to do anything, it should start

within 7 seconds, or give progress reports.

One of the most successful general-purpose screen-based interfaces is the

two menu buttons and a line of text in the user's native language. It's used in pagers,

medium-priced printers, network switches, and other medium-priced situations that

require complex behavior from users. When there's text, there are languages. The default

language should be the one most widely understood.

Page 17: Ultrasonic Based Distance Measurement

MICROCONTROLLERS

Microcontrollers as the name suggests are small controllers. They are like

single chip computers that are often embedded into other systems to function as

processing/controlling unit. For example the remote control you are using probably has

microcontrollers inside that do decoding and other controlling functions. They are also

used in automobiles, washing machines, microwave ovens, toys ... etc, where automation

is needed.

Micro-controllers are useful to the extent that they communicate with

other devices, such as sensors, motors, switches, keypads, displays, memory and even

other micro-controllers. Many interface methods have been developed over the years to

solve the complex problem of balancing circuit design criteria such as features, cost, size,

weight, power consumption, reliability, availability, manufacturability. Many

microcontroller designs typically mix multiple interfacing methods. In a very simplistic

form, a micro-controller system can be viewed as a system that reads from (monitors)

inputs, performs processing and writes to (controls) outputs.

Embedded system means the processor is embedded into the required

application. An embedded product uses a microprocessor or microcontroller to do one

task only. In an embedded system, there is only one application software that is typically

burned into ROM. Example: printer, keyboard, video game player

Microprocessor - A single chip that contains the CPU or most of the computer

Microcontroller - A single chip used to control other device

Microcontroller differs from a microprocessor in many ways. First and the

most important is its functionality. In order for a microprocessor to be used, other

components such as memory, or components for receiving and sending data must be

added to it. In short that means that microprocessor is the very heart of the computer. On

the other hand, microcontroller is designed to be all of that in one. No other external

Page 18: Ultrasonic Based Distance Measurement

components are needed for its application because all necessary peripherals are already

built into it. Thus, we save the time and space needed to construct devices.

MICROPROCESSOR VS MICROCONTROLLER:

Microprocessor:

CPU is stand-alone, RAM, ROM, I/O, timer are separate

Designer can decide on the amount of ROM, RAM and I/O ports.

expensive

versatility general-purpose

Microcontroller:

CPU, RAM, ROM, I/O and timer are all on a single chip

fix amount of on-chip ROM, RAM, I/O ports

for applications in which cost, power and space are critical

single-purpose

Page 19: Ultrasonic Based Distance Measurement

SENSORS

A sensor is a device that measures a physical quantity and converts it

into a signal which can be read by an observer or by an instrument. They are used for

various purposes including measurement or information transfer.

An electronic sensor is any device that uses electricity to sense a change in

physical quantity, and then through a voltage change, send a signal to a device that

captures this information. Some sensors measure properties directly, other sensors

measure properties indirectly, using conversions or calculations to determine results.

Sensors are generally categorized by the type of phenomenon that they measure, rather

than the functionality of the sensor itself.

There are many different things to measure -- heat, light, humidity, sound,

level, weight etc. each of these requires a different sensors. There are so many kinds of

sensors.

MECHANICAL SENSORS:

Mechanical sensors measure a property through mechanical means,

although the measurement itself may be collected electronically. An example of a

mechanical sensor is a strain gauge. The strain gauge measures the physical deformation

of a component by experiencing the same strain as the component, yet the change in

resistance of the strain gauge is measured electrically. Other types of mechanical sensors

include:

Pressure sensors

Accelerometers

Potentiometers

Gas and fluid flow meters

Humidity sensors

Page 20: Ultrasonic Based Distance Measurement

Ultrasonic sensors

ELECTRICAL:

Electrical sensors measure electric and magnetic properties. An example

of an electrical sensor is an ohmmeter, which is used to measure electrical resistance

between two points in a circuit. An ohmmeter sends a fixed voltage through one probe,

and measures the returning voltage through a second probe. The drop in voltage is

proportional to the resistance, as dictated by Ohm's Law. Other electrical sensors include:

Voltmeter/Ammeter

Metal detector

RADAR

Magnetometer

THERMAL:

Although all thermal sensors measure changes in temperature, there are a

variety of types of thermal sensors, each with specific uses, temperature ranges, and

accuracies. Some types of thermal sensors include:

Thermometers

Thermocouples

Thermistors

Bi-metal thermometers

OPTICAL:

Optical sensors detect the presence of light waves. This could include light

in the visible spectrum, or outside the visible spectrum, in the case of infrared sensors.

Some types of optical sensors include:

Photo detectors

Infrared sensors

Page 21: Ultrasonic Based Distance Measurement

Fiber optic sensors

Interferometers

OTHER TYPES OF SENSORS:

There are many other types of sensors:

Radiation sensors, including Geiger counters and dosimeters

Motion sensors, including radar guns ,Infrared detectors and speedometers

Acoustic, including sonar and seismometers

Gyroscopes

Microphones

Video cameras

Hall Effect probes (magnetic field)

Remote control devices

Photocells

Sensors may be simple physical measurement systems, or complex

electronic devices requiring sophisticated data acquisition systems. No matter the type of

sensor, input type, or output type, every sensor has inherent characteristics that allow the

user to select the right sensor for the task at hand.

SENSOR CHARACTERISTICS:

Some sensor characteristics include:

Input Range

Output Range

Accuracy

Repeatability

Resolution

Page 22: Ultrasonic Based Distance Measurement

INPUT RANGE:

Input range is the maximum measurable range that the sensor can

accurately measure. For example, a compression load cell may have an input range of 0 -

5000 pounds. The load cell cannot accurately measure "negative", or tensile loads, or

compressive loads greater than 5000 pounds. Generally, quantities outside of the input

range can be measured, but characteristics such as accuracy and repeatability may be

compromised when the input is outside of the specified range.

OUTPUT RANGE:

Output range generally refers to electronic sensors, and is the range of

electrical output signal that the sensor returns. However, the output range could be a

physical displacement, such as in a spring scale, or rotation, such as in a clock-style

analog thermometer. The output range is related to the input range by the conversion

algorithm specific to the sensor type, and the algorithm may include factors based on the

calibration of the specific sensor.

ACCURACY:

Accuracy actually refers to the amount of error, or inaccuracy that may be

present in a sensor. Accuracy can be stated as a unit of measurement, such as +/- 5

pounds, or as a percentage, such as 95%. In most cases, increased accuracy results in an

increased cost for a sensor.

REPEATABILITY:

Repeatability, as the name implies, refers to how often a sensor under the

same input conditions will return the same value. If a sensor is designed to be used over

and over again, it is important that the output value is accurate over every measurement

cycle for the life of the sensor. Repeatability is determined by calibration testing of the

sensor using known inputs.

Page 23: Ultrasonic Based Distance Measurement

RESOLUTION:

Resolution is the smallest unit of measurement that the sensor can

accurately measure. Some transducers return output signals in discrete steps, and

therefore the resolution is easily defined. Resolution can be stated as a unit of

measurement or as a percentage. For electronic sensors, resolution is also dictated by the

resolution of the signal conditioning hardware or software.

These qualities are common to all sensors, no matter what characteristic is

being measured. All of these traits must be considered when selecting the right sensor for

the specific needs of a test.

APPLICATION OF SENSORS:

Sensors Applications covers all major fields of applications

Commercial sensors like Temperature sensors, Pressure sensors, Micro

sensors, Microsystems and integrated electronic sensors etc. More and more utilization of

microcontrollers in different areas also increase the use of sophisticated, low cost sensors.

In Household applications sensors are used in modern washing machines,

dish washers, dryers, freezers as well as in cooking, domestic heating, air conditioning or

small appliances results in reduction of electricity, water or detergent consumption, less

noise emission, increased efficiency and higher user comfort.

In Medical Applications like Glucose Biosensors, Coagulation Rate

Biosensors, Cholesterol Biosensors and Others in laboratories etc. Remote sensors

include film photography, Infrared, charge-coupled devices, and radiometers.

The Remote Military applications include strategic systems for early

warning of intercontinental ballistic missile launches, methods for the detection of

atmospheric contaminants, such as poison gas, under field conditions, aids for the

Page 24: Ultrasonic Based Distance Measurement

precision delivery of weaponry (including passive, active, and laser designator guidance

techniques), and sensor systems for reconnaissance and surveillance.

Page 25: Ultrasonic Based Distance Measurement

LIQUID CRYSTAL DISPLAY

A liquid crystal display (LCD) is a thin, flat panel used for electronically

displaying information such as text, images, and moving pictures. Its uses include

monitors for computers, televisions, instrument panels, and other devices ranging from

aircraft cockpit displays, to every-day consumer devices such as video players, gaming

devices, clocks, watches, calculators, and telephones. Among its major features are its

lightweight construction, its portability, and its ability to be produced in much larger

screen sizes than are practical for the construction of cathode ray tube (CRT) display

technology. Its low electrical power consumption enables it to be used in battery-powered

electronic equipment. It is an electronically-modulated optical device made up of any

number of pixels filled with liquid crystals and arrayed in front of a light source

(backlight) or reflector to produce images in color or monochrome. The earliest discovery

leading to the development of LCD technology, the discovery of liquid crystals, dates

from 1888. By 2008, worldwide sales of televisions with LCD screens had surpassed the

sale of CRT units.

PIN DESCRIPTION:

Page 26: Ultrasonic Based Distance Measurement

PIN DESCRIPTION:

PIN SYMBOL I/O DESCRIPTION

1 VSS -- Ground

2 VCC -- +5V power supply

3 VEE -- Power supply to control contrast

4 RS I RS=0 to select command register

RS=1 to select data register

5 R/W I R/W=0 for write

R/W=1 for read

6 EN I/O Enable

7 DB0 I/O The 8-bit data bus

8 DB1 I/O The 8-bit data bus

9 DB2 I/O The 8-bit data bus

10 DB3 I/O The 8-bit data bus

11 DB4 I/O The 8-bit data bus

12 DB5 I/O The 8-bit data bus

13 DB6 I/O The 8-bit data bus

14 DB7 I/O The 8-bit data bus

VCC, VSS and VEE:

While VCC and VSS provide +5V and ground respectively, VEE is used for

controlling LCD contrast.

RS (REGISTER SELECT):

There are two important registers inside the LCD. When RS is low (0), the

data is to be treated as a command or special instruction (such as clear screen, position

cursor, etc.). When RS is high (1), the data that is sent is a text data which should be

displayed on the screen. For example, to display the letter "T" on the screen you would

set RS high.

RW (READ/WRITE):

Page 27: Ultrasonic Based Distance Measurement

The RW line is the "Read/Write" control line. When RW is low (0), the

information on the data bus is being written to the LCD. When RW is high (1), the

program is effectively querying (or reading) the LCD. Only one instruction ("Get LCD

status") is a read command. All others are write commands, so RW will almost be low.

EN (ENABLE):

The EN line is called "Enable". This control line is used to tell the LCD

that you are sending it data. To send data to the LCD, your program should first set this

line high (1) and then set the other two control lines and/or put data on the data bus.

When the other lines are completely ready, bring EN low (0) again. The 1-0 transition

tells the 44780 to take the data currently found on the other control lines and on the data

bus and to treat it as a command.

D0-D7 (DATA LINES):

The 8-bit data pins, D0-D7 are used to send information to the LCD or

read the content of the LCD’s internal registers.

To display letters and numbers, we send ASCII codes for the letters A-Z,

a-z and numbers 0-9 to these pins while making RS=1.

There are also instruction command codes that can be sent to the LCD to

clear the display or force the cursor to the home position or blink the cursor.

We also use RS=0 to check the busy flag bit to see if the LCD is ready to

receive the information. The busy flag is D7 and can be read when R/W = 1 and RS=0, as

follows: if R/W = 1, RS = 0. When D7=1 (busy flag = 1), the LCD is busy taking care of

internal operations and will not accept any new information. When D7 = 0, the LCD is

ready to receive new information.

Note: it is recommended to check the flag before writing any data to LCD.

LCD COMMAND CODES:

Page 28: Ultrasonic Based Distance Measurement

CODE (HEX) COMMAND TO LCD INSTRUCTION REGISTER0X01 CLEAR DISPLAY SCREEN0X02 RETURN HOME0X04 DECREMENT CURSOR(SHIFT CURSOR TO LEFT)0X06 INCREMENT CURSOR(SHIFT CURSOR TO RIGHT)0X05 SHIFT DISPLAY RIGHT0X07 SHIFT DISPLAY LEFT0X08 DISPLAY OFF,CURSOR OFF0X0A DISPLAY OFF,CURSOR ON0X0C DISPLAY ON,CURSOR OFF0X0E DISPLAY ON CURSOR BLINKING0X0F DISPLAY ON CURSOR BLINKING0X10 SHIFT CURSOR POSITION TO LEFT0X14 SHIFT CURSOR POSITION TO RIGHT0X18 SHIFT THE ENTIRE DISPLAY TO THE LEFT0X1C SHIFT THE ENTIRE DISPLAY TO THE RIGHT0X80 FORCE CURSOR TO BEGINNING OF 1ST LINE0XC0 FORCE CURSOR TO BEGINNING OF 2ND LINE0X380X300X280X20

8-BIT INTERFACE, 2 LINES, 5*7 PIXELS 8-BIT INTERFACE, 1 LINE, 5*7 PIXELS4-BIT INTERFACE, 2 LINES, 5*7 PIXELS4-BIT INTERFACE, 1 LINE, 5*7 PIXELS

CURSOR ADDRESSES FOR LCD’S:

16x2 LCD 80 81 82 83 84 85 86 through 8F C0 C1 C2 C3 C4 C5 C6 through CF20x1 LCD 80 81 82 83 through 9320x2 LCD 80 81 82 83 through 93 C0 C1 C2 C3 through D320x4 LCD 80 81 82 83 through 93 C0 C1 C2 C3 through D3 94 95 96 97 through A7 D4 D5 D6 D7 through E740x2 LCD 80 81 82 83 through A7 C0 C1 C2 C3 through E7NOTE: All data is in HEX.

ADVANTAGES:

Page 29: Ultrasonic Based Distance Measurement

LCD interfacing with 8051 is a real-world application. In recent years the LCD is

finding widespread use replacing LED’s (seven segment LED’s or other multi segment

LED’s).

This is due to following reasons:

The declining prices of LCD’s.

The ability to display numbers, characters and graphics. This is in contrast to

LED’s, which are limited to numbers and a few characters. An intelligent LCD

displays two lines, 20 characters per line, which is interfaced to the 8051.

Incorporation of a refreshing controller into the LCD, thereby relieving the CPU

to keep displaying the data.

Ease of programming for characters and graphics.

LIGHT EMITTING DIODE

Page 30: Ultrasonic Based Distance Measurement

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

incoherent narrow spectrum light when electrically biased in the forward direction of the

pn-junction, as in the common LED circuit. This effect is a form of electroluminescence.

Like a normal diode, the LED consists of a chip of semi-conducting

material impregnated, or doped, with impurities to create a p-n junction. As in other

diodes, current flows easily from the p-side, or anode, to the n-side, or cathode, but not in

the reverse direction. Charge-carriers—electrons and holes—flow into the junction from

electrodes with different voltages. When an electron meets a hole, it falls into a lower

energy level, and releases energy in the form of a photon.

Page 31: Ultrasonic Based Distance Measurement

The wavelength of the light emitted, and therefore its color, depends on

the band gap energy of the materials forming the p-n junction. In silicon or germanium

diodes, the electrons and holes recombine by a non-radiative transition which produces

no optical emission, because these are indirect band gap materials. The materials used for

the LED have a direct band gap with energies corresponding to near-infrared, visible or

near-ultraviolet light.

LED development began with infrared and red devices made with gallium

arsenide. Advances in materials science have made possible the production of devices

with ever-shorter wavelengths, producing light in a variety of colors.

LEDs are usually built on an n-type substrate, with an electrode attached

to the p-type layer deposited on its surface. P-type substrates, while less common, occur

as well. Many commercial LEDs, especially GaN/InGaN, also use sapphire substrate.

Most materials used for LED production have very high refractive indices.

This means that much light will be reflected back in to the material at the material/air

surface interface. Therefore Light extraction in LEDs is an important aspect of LED

production, subject to much research and development.

Solid state devices such as LEDs are subject to very limited wear and tear

if operated at low currents and at low temperatures. Many of the LEDs produced in the

Page 32: Ultrasonic Based Distance Measurement

1970s and 1980s are still in service today. Typical lifetimes quoted are 25,000 to 100,000

hours but heat and current settings can extend or shorten this time significantly.

Conventional LEDs are made from a variety of inorganic semiconductor

materials; the following table shows the available colors with wavelength range and

voltage drop.

Color Wavelength (nm) Voltage (V)

Infrared λ > 760 ΔV < 1.9

Red 610 < λ < 760 1.63 < ΔV < 2.03

Orange 590 < λ < 610 2.03 < ΔV < 2.10

Yellow 570 < λ < 590 2.10 < ΔV < 2.18

Green 500 < λ < 570 1.9 < ΔV < 4.0

Blue 450 < λ < 500 2.48 < ΔV < 3.7

Violet 400 < λ < 450 2.76 < ΔV < 4.0

Purple multiple types 2.48 < ΔV < 3.7

Ultraviolet λ < 400 3.1 < ΔV < 4.4

White Broad spectrum ΔV = 3.5

Page 33: Ultrasonic Based Distance Measurement

ADVANTAGES OF LEDS:

LED’s have many advantages over other technologies like lasers. As compared to

laser diodes or IR sources

LED’s are conventional incandescent lamps. For one thing, they don't have a

filament that will burn out, so they last much longer. Additionally, their small

plastic bulb makes them a lot more durable. They also fit more easily into modern

electronic circuits.

The main advantage is efficiency. In conventional incandescent bulbs, the light-

production process involves generating a lot of heat (the filament must be

warmed). Unless you're using the lamp as a heater, because a huge portion of the

available electricity isn't going toward producing visible light.

LED’s generate very little heat. A much higher percentage of the electrical power

is going directly for generating light, which cuts down the electricity demands

considerably.

LED’s offer advantages such as low cost and long service life. Moreover LED’s

have very low power consumption and are easy to maintain.

DISADVANTAGES OF LEDS:

Page 34: Ultrasonic Based Distance Measurement

LED’s performance largely depends on the ambient temperature of the operating

environment.

LED’s must be supplied with the correct current.

LED’s do not approximate a "point source" of light, so cannot be used in

applications needing a highly collimated beam.

But the disadvantages are quite negligible as the negative properties of LED’s do not

apply and the advantages far exceed the limitations.

Page 35: Ultrasonic Based Distance Measurement

CODE-VISION AVR

Assembly code is used for one or more of three reasons: speed,

compactness or because some functions are easier to do in assembler than in a higher

level language. It is well known that using a high level language always results in the

faster program development but there are times when, for the reasons stated above, one

wants to use assembly language.

The Code Vision AVR C Compiler, like other compilers meant for

microcontroller development, has an easy interface to assembly language. Assembler

code may be imbedded anywhere in a C program.

FEATURES:

Installing and Configuring Code Vision AVR to work with the Atmel STK500

starter kit and AVR Studio debugger.

Creating a New Project using the Code Wizard AVR Automatic Program

Generator

Editing and Compiling the C code

Loading the executable code into the target microcontroller on the STK500 starter

kit.

INTRODUCTION:

Page 36: Ultrasonic Based Distance Measurement

This is an introduction to the user through the preparation of an example C

program using the Code Vision AVR C compiler. The example, which is the subject of

this application note, is a simple program for the Atmel AT90S8515 microcontroller on

the STK500 starter kit.

PREPARATION:

Install the Code Vision AVR C Compiler by executing the file setup.exe.

It is assumed that the program was installed in the default directory: C:\cvavr. Install the

Atmel AVR Studio debugger by executing the file setup.exe. It is assumed that AVR

Studio was installed in the default directory: C:\Program Files\Atmel\AVR Studio. Setup

the starter kit (STK500) according to the instructions in the STK500 User Guide. Make

sure the power is off and insert the AT90S8515 chip into the appropriate socket marked

SCKT3000D3. Set the XTAL1 jumper. Also set the OSCSEL jumper between pins 1 and

2. Connect one 10 pin ribbon cable between the PORTB and LEDS headers. This will

allow displaying the state of AT90S8515’s PORTB outputs. Connect one 6 pin ribbon

cable between the ISP6PIN and SPROG3 headers. This will allow Code Vision AVR to

automatically program the AVR chip after a successful compilation. In order to use this

feature, one supplementary setting must be done: Open the Code Vision AVR IDE and

select the Settings | Programmer menu option. Make sure to select the Atmel STK500

AVR Chip Programmer Type and the corresponding Communication Port which is used

with the STK500 starter kit. Then press the STK500.EXE Directory button in order to

specify the location of the stk500.exe command line utility supplied with AVR Studio.

Select the c:\Program Files\Atmel\AVR Studio\STK500 directory and press the OK

button. Then press once again the OK button in order to save the Programmer Settings. In

order to be able to invoke the AVR Studio debugger/simulator from within the Code

Vision AVR IDE one final setting must be done. Select the Settings | Debugger menu

option.

Page 37: Ultrasonic Based Distance Measurement

SHORT REFERENCE:

PREPARATIONS:

1. Install the Code Vision AVR C compiler

2. Install the Atmel AVR Studio debugger

3. Install the Atmel STK500 starter kit

4. Configure the STK500 programmer support in the Code Vision AVR IDE by selecting:

Settings->Programmer-> AVR Chip Programmer Type: STK500-> Specify

STK500.EXE Directory: C:\Program Files\Atmel\AVR Studio\STK500->

Communication Port

5. Configure the AVR Studio support in the Code Vision AVR IDE by selecting:

Settings->Debugger-> Enter: C:\Program Files\Atmel\AVR Studio.

GETTING STARTED:

1. Create a new project by selecting: File->New->Select Project

2. Specify that the Code Wizard AVR will be used for producing the C source and project

files: Use the Code Wizard? ->Yes

3. In the Code Wizard AVR window specify the chip type and clock frequency: Chip-

>Chip: AT90S8515->Clock: 3.86MHz

4. Configure the I/O ports: Ports->Port B- >Data Direction: all Outputs->Output Value:

all 1’s

5. Configure Timer 1: Timers->Timer1- >Clock Value: 3.594 kHz->Interrupt on: Timer1

Overflow->Val: 0xF8FB

Page 38: Ultrasonic Based Distance Measurement

6. Generate the C source, C project and Code Wizard AVR project files by selecting: File

| Generate, Save and Exit-> Create new directory: C:\cvavr\led-> Save: led .c ->Save:

led.prj->Save: led.cwp

7. Edit the C source code

8. View or Modify the Project Configuration by selecting Project->Configure-> After

Make->Program the Chip

9. Compile the program by selecting: Project->Make

10. Automatically program the AT90S8515 chip on the STK500 starter kit: Apply power-

>Information->Program.

ATMEGA8515

FEATURES:

High-performance, Low-power AVR® 8-bit Microcontroller

RISC Architecture

–130 Powerful Instructions – Most Single Clock Cycle Execution

– 32 x 8 General Purpose Working Registers

– Fully Static Operation

– Up to 16 MIPS Throughput at 16 MHz

– On-chip 2-cycle Multiplier

Nonvolatile Program and Data Memories

– 8K Bytes of In-System Self-programmable Flash

Endurance: 10,000 Write/Erase Cycles

– Optional Boot Code Section with Independent Lock bits

In-System Programming by On-chip Boot Program

True Read-While-Write Operation

– 512 Bytes EEPROM

Endurance: 100,000 Write/Erase Cycles

– 512 Bytes Internal SRAM

– Up to 64K Bytes Optional External Memory Space

– Programming Lock for Software Security

Peripheral Features

Page 39: Ultrasonic Based Distance Measurement

– One 8-bit Timer/Counter with Separate Prescaler and Compare Mode

– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and

Capture Mode

– Three PWM Channels

– Programmable Serial USART

– Master/Slave SPI Serial Interface

– Programmable Watchdog Timer with Separate On-chip Oscillator

–On-chip Analog Comparator

Special Microcontroller Features

– Power-on Reset and Programmable Brown-out Detection

– Internal Calibrated RC Oscillator

– External and Internal Interrupt Sources

– Three Sleep Modes: Idle, Power-down and Standby

I/O and Packages

– 35 Programmable I/O Lines

– 40-pin PDIP, 44-lead TQFP, 44-lead PLCC, and 44-pad QFN/MLF

Operating Voltages

– 2.7 - 5.5V for ATmega8515L

– 4.5 - 5.5V for ATmega8515

Speed Grades

–0 - 8 MHz for ATmega8515L

–0 - 16 MHz for ATmega8515

Pin Configurations

Page 40: Ultrasonic Based Distance Measurement

OVERVIEW:

The ATmega8515 is a low-power CMOS 8-bit microcontroller based on

the AVR enhanced RISC architecture. By executing powerful instructions in a single

clock cycle, the ATmega8515 achieves throughputs approaching 1 MIPS per MHz

allowing the system designer to optimize power consumption versus processing speed.

Page 41: Ultrasonic Based Distance Measurement

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

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

(ALU), allowing two independent registers to be accessed in one single instruction

executed in one clock cycle. The resulting architecture is more code efficient while

achieving throughputs up to ten times faster than conventional CISC microcontrollers.

Page 42: Ultrasonic Based Distance Measurement

The ATmega8515 provides the following features: 8K bytes of In-System

Programmable Flash with Read-While-Write capabilities, 512 bytes EEPROM, 512 bytes

SRAM, an External memory interface, 35 general purpose I/O lines, 32 general purpose

working registers, two flexible Timer/Counters with compare modes, Internal and

External interrupts, a Serial Programmable USART, a programmable Watchdog Timer

with internal Oscillator, a SPI serial port, and three software selectable power saving

modes. The Idle mode stops the CPU while allowing the SRAM, Timer/Counters, SPI

port, and Interrupt system to continue functioning. The Power-down mode saves the

Register contents but freezes the Oscillator, disabling all other chip functions until the

next interrupt or hardware reset. In Standby mode, the crystal/resonator Oscillator is

running while the rest of the device is sleeping. This allows very fast start-up combined

with low-power consumption.

The device is manufactured using Atmel’s high density nonvolatile

memory technology. The On-chip ISP Flash allows the Program memory to be

reprogrammed In-System through an SPI serial interface, by a conventional nonvolatile

memory programmer, or by an On-chip Boot program running on the AVR core. The

boot program can use any interface to download the application program in the

Application Flash memory. Software in the Boot Flash section will continue to run while

the Application Flash section is updated, providing true Read-While-Write operation. By

combining an 8-bit RISC CPU with In-System Self-programmable Flash on a monolithic

chip, the Atmel ATmega8515 is a powerful microcontroller that provides a highly

flexible and cost effective solution to many embedded control applications.

The ATmega8515 is supported with a full suite of program and system

development tools including: C Compilers, Macro assemblers, Program

debugger/simulators, In-circuit Emulators, and Evaluation kits.

Typical values contained in this datasheet are based on simulations and

characterization of other AVR microcontrollers manufactured on the same process

technology. Min and Max values will be available after the device is characterized.

PIN DESCRIPTIONS:

Page 43: Ultrasonic Based Distance Measurement

VCC:

Digital supply voltage

GND:

Ground

Port A (PA7...PA0):

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

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

with both high sink and source capability. When pins PA0 to PA7 are used as inputs and

are externally pulled low, they will source current if the internal pull-up resistors are

activated. The PortA pins are tri-stated when a reset condition becomes active, even if the

clock is not running.

Port B (PB7...PB0):

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

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

with both high sink and source capability. As inputs, Port B pins that are externally

pulled low will source current if the pull-up resistors are activated. The Port B pins are

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

Port C (PC7...PC0):

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

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

with both high sink and source capability. As inputs, Port C pins that are externally

pulled low will source current if the pull-up resistors are activated. The Port C pins are

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

Port D (PD7...PD0):

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

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

with both high sink and source capability. As inputs, Port D pins that are externally

Page 44: Ultrasonic Based Distance Measurement

pulled low will source current if the pull-up resistors are activated. The Port D pins are

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

Port E (PE2...PE0):

Port E is a 3-bit bi-directional I/O port with internal pull-up resistors

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

with both high sink and source capability. As inputs, Port E pins that are externally pulled

low will source current if the pull-up resistors are activated. The Port E pins are tri-stated

when a reset condition becomes active, even if the clock is not running.

RESET Bar:

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

length will generate a reset, even if the clock is not running. The minimum pulse length is

given in Table 18 on page 46. Shorter pulses are not guaranteed to generate a reset.

XTAL1:

Input to the inverting Oscillator amplifier and input to the internal clock

operating circuit.

XTAL2:

Output from the inverting Oscillator amplifier

TS 601

INTRODUCTION OF TS601:

NT-TS601 Using a non-contact ultrasonic measurement techniques as a module,

about 2cm less and more than 3.3m

Page 45: Ultrasonic Based Distance Measurement

Accurately measure the distance of objects and can be.

TS601 of a single I / O pin to use the connection because the micro-controller and

the robot easily,

Industry and can be used to measure the distance.

FEATURES:

Distance measurement range of about 2 cm ~ 3.3 m

Measurement tolerance: ± 2 cm

Ongoing response time: 20 ms minimum per

In a narrow range of ultrasound can measure the precise distance.

One I / O pin interface by the way, bi-directional TTL pulse

5V TTL can be connected to the microcontroller.

Page 46: Ultrasonic Based Distance Measurement

Input trigger:

Positive TTL pulse / typical l5 μs

Output pulse:

Positive TTL pulse / min up to 110 μs ~ 19.0 ms

PIN CONNECTIONS OF SENSOR:

TS601 with a male 3-header pin is configured.

GND - ground

Vcc - +5 VDC

SIG - signal I / O pin

Regular 2.54 mm (100 mil) to the pin spacing you can easily connect to the board.

MCU I / O pin, and between NT-TS601 SIG pin 1kΩ ~ 10 kΩ resistor is recommended to

be enclosed.

SENSOR SPECIFICATIONS:

Measurement Principle: Ultrasonic Detection

Application: Distance Measuring

Input Power: +5 VDC

Input current: 15 mA

Sensor frequency: 40 kHz

Operating Temperature: 0 ~ 70

Weight: 13g

Size: 25 mm (H) x 50 mm (W) x 17.5 mm (D)

image: 3-pin SIP (single in-line package)

Page 47: Ultrasonic Based Distance Measurement

SENSOR WORKING:

The minimum distance measured 2cm. First, the output pin of the MCU pins SIG

of the TS601 Input trigger pulse (t1) will send you. TS601 Input trigger pulse of

the SIG pin receiving TS601 in TX pin of the ultrasonic sensor Burst pulse is

generated to 40 kHz.

Output echo pulse until the Echo postpones (t2) and wait. Burst pulse is reflected

in the body until it is checked Output echo pulse. MCU Output echo pulse width

of the input received may be represented by measuring the distance. In order to

measure again after waiting a minimum of 200 μs or send Input trigger pulse.

Page 48: Ultrasonic Based Distance Measurement

Input trigger pulse t1 - 5 μs

Output

Echo postpone t2 500 - 520 μs

Output echo pulse MIN. t3 110 - 140 μs

Output echo pulse MAX. t4 1.90 - 19.0 ms

Burst pulse cycle t5 - 25 μs

CONSIDERATIONS FOR USING THE SENSOR:

In the case of NT-TS601 down the street will not be measured.

If at least closer than 2 cm (an arbitrary value, recognition)

If you have far more than the maximum 3.3 m (3.3m recognized)

a small angle of ultrasonic sensors on the surface is reflected toward the reflection

does not a very small object that is not reflective of the ultrasound

TS601 is located on the bottom of the case

Page 49: Ultrasonic Based Distance Measurement

OBJECT OF THE MATERIAL:

Sound absorbing materials and objects such as cotton is erratic enough to find the

wave are not reflected.

Outside or big the error of distance measurement in the natural environment can

be high.

Atmospheric temperature and Velocity is affected by the temperature of the

atmosphere.

Temperature of the atmosphere, if you know T expression

Sonic velocity V = (331.5 + 0.60714 T) [m / s]

Of the sensor's operating range of 0 to 70 error represents approximately 11-12%.

Ambient temperature

Speed of sound varies by the distance to the high precision measurement is

needed if the temperature compensation.

THE APPLICATION OF THE PRODUCT:

The formula for the distance between objects

Distance to object (D) [m] = velocity (V) [m / s] x hours (t) [s]

= (331.5 + 0.60714 T) x (t / 2)

Output echo pulse went the distance and coming back by time, so Output echo pulse of

the actual distance is half of the time. Above, the distance between objects using the

expression can be obtained. Port D of the signal measured using the 3 pin has an external

interrupt. Reference temperature 25 degrees when the temperature of the environment,

based on specific work will be requested to change the temperature value.

Page 50: Ultrasonic Based Distance Measurement

TRANSISTOR AS A SWITCH

The transistor is the fundamental building block of modern electronic devices,

and its presence is ubiquitous in modern electronic systems.

Because a transistor's collector current is proportionally limited by its base

current, it can be used as a sort of current-controlled switch. A relatively small flow of

electrons sent through the base of the transistor has the ability to exert control over a

much larger flow of electrons through the collector.

When used as an AC signal amplifier, the transistors Base biasing voltage is

applied so that it operates within its "Active" region and the linear part of the output

characteristics curves are used. However, both the NPN & PNP type bipolar transistors

can be made to operate as an "ON/OFF" type solid state switch for controlling high

power devices such as motors, solenoids or lamps. If the circuit uses the Transistor as a

Switch, then the biasing is arranged to operate in the output characteristics curves seen

previously in the areas known as the "Saturation" and "Cut-off" regions as shown

below.

TRANSISTOR CURVES:

Page 51: Ultrasonic Based Distance Measurement

The shaded area at the bottom represents the "Cut-off" region. Here the operating

conditions of the transistor are zero input base current (Ib), zero output collector current

(Ic) and maximum collector voltage (Vce) which results in a large depletion layer and no

current flows through the device. The transistor is switched "Fully-OFF". The lighter blue

area to the left represents the "Saturation" region. Here the transistor will be biased so

that the maximum amount of base current is applied, resulting in maximum collector

current flow and minimum collector emitter voltage which results in the depletion layer

being as small as possible and maximum current flows through the device. The transistor

is switched "Fully-ON". Then we can summarize this as:

Cut-off Region: Both junctions are Reverse-biased, Base current is zero or very

small resulting in zero Collector current flowing, the device is switched fully

"OFF".

Saturation Region: Both junctions are Forward-biased, Base current is high

enough to give a Collector-Emitter voltage of 0v resulting in maximum

Collector current flowing, the device is switched fully "ON".

TRANSISTOR SWITCHING CIRCUIT:

Page 52: Ultrasonic Based Distance Measurement

An NPN Transistor as a switch being used to operate a relay is given above. With

inductive loads such as relays or solenoids a flywheel diode is placed across the load to

dissipate the back EMF generated by the inductive load when the transistor switches

"OFF" and so protect the transistor from damage. If the load is of a very high current or

voltage nature, such as motors, heaters etc, then the load current can be controlled via a

suitable relay as shown.

The circuit resembles that of the Common Emitter circuit we looked at in the

previous tutorials. The difference this time is that to operate the transistor as a switch the

transistor needs to be turned either fully "OFF" (Cut-off) or fully "ON" (Saturated). An

ideal transistor switch would have an infinite resistance when turned "OFF" resulting in

zero current flow and zero resistance when turned "ON", resulting in maximum current

flow. In practice when turned "OFF", small leakage currents flow through the transistor

and when fully "ON" the device has a low resistance value causing a small saturation

voltage (Vce) across it. In both the Cut-off and Saturation regions the power dissipated

by the transistor is at its minimum.

To make the Base current flow, the Base input terminal must be made more

positive than the Emitter by increasing it above the 0.7 volts needed for a silicon device.

By varying the Base-Emitter voltage Vbe, the Base current is altered and which in turn

controls the amount of Collector current flowing through the transistor as previously

discussed. When maximum Collector current flows the transistor is said to be saturated.

The value of the Base resistor determines how much input voltage is required and

corresponding Base current to switch the transistor fully "ON".

Transistor switches are used for a wide variety of applications such as interfacing

large current or high voltage devices like motors, relays or lamps to low voltage digital

logic IC's or gates like AND Gates or OR Gates.

Page 53: Ultrasonic Based Distance Measurement

BUZZER

Sound is simply a wave of varying air pressure. These pressure waves

cause a thin membrane in the ear to vibrate and the brain interprets these vibrations as

sound. A decibel (dB) scale is used to describe the sound pressure level (SPL) or

loudness of a sound.

In general, man's audible frequency range is about 20 Hz to 20 kHz.

Frequency ranges of 2 kHz to 4 kHz are most easily heard. For this reason, most

piezoelectric sound components are used in this frequency range, and the resonant

frequency (f0) is generally selected in the same range too.

Piezoelectric sound components are used in many ways such as home

appliances, OA equipment, audio equipment telephones, etc. And they are applied

widely, for example, in alarms, speakers, telephone ringers, receivers, transmitters, beep

sounds, etc.

BUZZER:

Page 54: Ultrasonic Based Distance Measurement

The sound source of a piezoelectric sound component is the piezoelectric

diaphragm. The piezoelectric diaphragm (bender plate) consists of a piezoelectric

ceramic plate, with electrodes on both sides, attached to a metal plate (brass, stainless

steel etc) with conductive adhesive. Figure below shows the construction diagram of a

piezoelectric diaphragm.

The sound is created from the movement of the metal plate. Applying a

D.C. voltage between electrodes of the piezoelectric diaphragm causes mechanical

distortion due to the piezoelectric effect. The distortion of the piezoelectric ceramic plate

expands in the radial direction causing the metal plate to bend shown in Figure below.

Extended

Reversing the polarity of the D.C. voltage cause the ceramic plate to

shrink, bending the metal plate in the opposite direction, shown in Figure below. When

Page 55: Ultrasonic Based Distance Measurement

an A.C. voltage is applied across the electrodes, the diaphragm alternates bending in the

two directions. The repeated bending motion produces sound waves in the air.

Shrunk

AC Voltage Applied

There are two ways to drive piezoelectric sound components: External-

Drive and Self-Drive.

EXTERNAL DRIVE:

This drive method is typically used with edge mounted devices and uses

an external oscillating circuit to produce sound. In this way the device can act as a

speaker and produce frequencies over a specific bandwidth. This type of drive method is

used when multiple tones are desired. Externally driven devices have found extensive use

in watches, calculators, game machines, as well as appliances like microwave ovens,

washing machines, and TVs.

Page 56: Ultrasonic Based Distance Measurement

SELF DRIVE:

This method is used with node mounted devices. The diaphragm has a

feedback tab on one of the electrodes that is used in closed loop Hartley types of

oscillation circuits. When the circuit is closed to the resonant frequency, the conditions

for oscillation are met and the diaphragm produces a single high-pressure tone. This type

of drive procedure will produce only one tone but will have the highest SPL possible

from the buzzer.

DESIGN CONSIDERATIONS:

Driving Waveform:

The piezo elements may be driven with sinusoidal, pulsed, or square waves. A

sine wave will cause the device to operate at a frequency lower than the

resonant frequency with a lower SPL. This is due to the loss of energy through

the lag time between peak deflections. A square wave will produce higher

sound levels because of the near instantaneous rise and fall time. Clipping of

sinusoidal waveforms can result in frequency instability and pulse and square

Page 57: Ultrasonic Based Distance Measurement

waves will cause an increase in harmonic levels. A capacitor in parallel with

the diaphragm can reduce the harmonics.

DC Precautions:

Subjecting the ceramic elements to direct current can cause them to

depolarize and stop working. For this reason, it is best to drive the

buzzers with an A.C. signal that has a zero D.C. bias. Blocking

capacitors are recommended to prevent a bias.

High Voltage Precautions:

Voltages higher than those recommended can cause permanent damage to the

ceramic even if applied for short durations. Significantly higher sound

pressure levels will not be achieved by higher voltages before permanent

damage is caused.

Shock:

Mechanical impact on piezoelectric devices can generate high voltages that

can seriously damage drive circuitry, therefore, diode protection is

recommended.

SPL Control:

It is not recommended to place a resistor in series with the power source since

this may cause abnormal oscillation. If a resistor is essential in order to adjust

the sound pressure then place a capacitor (about 1μF) in parallel with the

buzzer.

Page 58: Ultrasonic Based Distance Measurement

ISP PROGRAMMER

In-System Programming (abbreviated ISP) is the ability of some

programmable logic devices, microcontrollers, and other programmable electronic chips

to be programmed while installed in a complete system, rather than requiring the chip to

be programmed prior to installing it into the system. Otherwise, In-system programming

means that the program and/or data memory can be modified without disassembling the

embedded system to physically replace memory.

The primary advantage of this feature is that it allows manufacturers of

electronic devices to integrate programming and testing into a single production phase,

rather than requiring a separate programming stage prior to assembling the system. This

may allow manufacturers to program the chips in their own system's production line

instead of buying preprogrammed chips from a manufacturer or distributor, making it

feasible to apply code or design changes in the middle of a production run.

ISP (In System Programming) will provide a simple and affordable home

made solution to program and debug your microcontroller based project.

Normally, the flash memory of an ATMEL microcontroller is

programmed using a parallel interface, which consists of sending the data byte by byte

(using 8 independent lines for the data, and another bunch of lines for the address, the

control word and clock input).

Many members of the Maxim 8051-based microcontroller family support

in-system programming via a commonly available RS-232 serial interface. The serial

interface consists of pins SCK, MOSI (input) and MISO (output) and the RST pin, which

is normally used to reset the device.

ISP is performed using only 4 lines, and literally, data is transferred

through 2 lines only, as in a I2C interface, where data is shifted in bit by bit though

MOSI line, with a clock cycle between each bit and the next (on the SCK line). MISO

Page 59: Ultrasonic Based Distance Measurement

line is used for reading and for code verification; it is only used to output the code from

the FLASH memory of the microcontroller.

The RST pin is also used to enable the 3 pins (MOSI, MISO and SCK) to

be used for ISP simply by setting RST to HIGH (5V), otherwise if RST is low (0V),

program start running and those three pins, are used normally as P1.5, P1.6 and P1.7.

After RST is set high, the Programming Enable instruction needs to be executed first

before other operations can be executed. Before a reprogramming sequence can occur, a

Chip Erase operation is required. The Chip Erase operation turns the content of every

memory location in the Code array into FFH.

Either an external system clock can be supplied at pin XTAL1 or a crystal

needs to be connected across pins XTAL1 and XTAL2. The maximum serial clock

(SCK) frequency should be less than 1/16 of the crystal frequency. With a 33 MHz

oscillator clock, the maximum SCK frequency is 2 MHz.

Page 60: Ultrasonic Based Distance Measurement

GND

I4A

GND

O4BGND

1 23 45 67 89 1 0

C O N N E C TO R D B 2 5

1 32 51 22 41 12 31 02 292 182 071 961 851 741 631 521 41

GND

I4B

GA

100K

GB

GND

I2B

0.1UF/35V

O1AI1A

7 4 H C 2 4 4

2 01 91 81 71 61 51 41 31 21 1

123456789

1 0

O2A

V C C

I1BO1B

O4A

I2A

VCC

O2B

03AI3A

I3BO3B

In the above figure we can see the ISP programmer connections using 74ls244

DB-25 Male pin description:

Pin no Name Direction Pin Description

12

GNDTXD

Shield GroundTransmit Data

3 RXD Receive Data

4 RTS Request to Send

5 CTS Clear to Send

6 DSR Data Set Ready

7 GND System Ground

8 CD Carrier Detect

9 --- Reserved

Page 61: Ultrasonic Based Distance Measurement

10 --- Reserved

11 STF Select Transmit Channel

12 S.CD Secondary Carrier Detect13 S.CTS Secondary Clear to Send

14 S.TXD Secondary Transmit Data

15 TCK Transmission Signal Element Timing

16 S.RXD Secondary Receive Data

17 RCK Receiver Signal Element Timing

18 LL Local Loop Control

19 S.RTS Secondary Request to Send

20 DTR Data terminal Ready

21 RL Remote Loop Control

22 RI Ring Indicator

23 DSR Data Signal Rate Selector

24 XCK Transmit Signal Element Timing

25 TI Test Indicator

74LS244:

The 74LS244 is used to work between PRINT ports to the chips

AT89S52. We cannot observe 74LS244 on the PCB which is AT89S52 located. It hid in

the joint between PC and 6 transmission lines. The 74LS244 pin configuration, logic

diagram, connection and function table is on the below.

Page 62: Ultrasonic Based Distance Measurement

EXAMPLE: CONNECTING THE PROGRAMMER TO AN AT89S52

Page 63: Ultrasonic Based Distance Measurement

AT89S8252 microcontroller features an SPI port, through which on-chip

Flash memory and EEPROM may be programmed. To program the microcontroller, RST

is held high while commands, addresses and data are applied to the SPI port.

ATMEL ISP FLASH PROGRAMMER:

This is the software that will take the HEX file generated by whatever

compiler you are using, and send it - with respect to the very specific ISP transfer

protocol - to the microcontroller.

This programmer was designed in view of to be flexible, economical and

easy to built, the programmer hardware uses the standard TTL series parts and no special

components are used. The programmer is interfaced with the PC parallel port and there is

Page 64: Ultrasonic Based Distance Measurement

no special requirement for the PC parallel port, so the older computers can also be used

with this programmer.

SUPPORTED DEVICES:

The programmer software presently supports the following devices

 

AT89C51 AT89S51 AT89C1051 UD87C51 AT89C52 AT89S52

AT89C2051 D87C52 AT89C55 AT89S53 AT89C4051 AT89C55WD

AT89S8252 AT89C51RC

Note:  For 20 pin devices a simple interface adapter is required.

The ISP-3v0.zip file contains the main program and the I/O port driver for

Windows 2000 & XP. Place all files in the same folder, for win-95/98 use the "ISP-

Pgm3v0.exe"File, for win-2000 & XP use the "ISP-XP.bat" file. The main screen view of

the program is shown in fig below.

Following are the main features of this software:

Page 65: Ultrasonic Based Distance Measurement

Read and write the Intel Hex file

Read signature, lock and fuse bits

Clear and Fill memory buffer

Verify with memory buffer

Reload current Hex file

Display buffer checksum

Program selected lock bits & fuses

Auto detection of hardware

The memory buffer contains both the code data and the EEPROM data for

the devices which have EEPROM memory. The EEPROM memory address in buffer is

started after the code memory, so it is necessary the hex file should contains the

EEPROM start address after the end of code memory last address.

i.e., for 90S2313 the start address for EEPROM memory is 0 x 800.

The software does not provide the erase command because this function is

performed automatically during device programming. If you are required to erase the

controller, first use the clear buffer command then program the controller, this will erase

the controller and also set the device→ to default setting.

ISP PROGRAMMER PICTURE:

CODING

Page 66: Ultrasonic Based Distance Measurement

/** COMPILER DIRECTIVES **/

#include<mega8515.h>

#include<delay.h>

/**LCD PIN DEFINITIONS**/

#define lcd PORTA

#define rs PORTA.1

#define en PORTA.3

#define SIG PIND.2 //its only for i/P we ll give PIN

#define SIG1 PORTD.2 //for O/P we ll give PORT

#define buzzer PORTC.1

/**LCD FUNCTIONS DECLARATIONS**/

void init();

void lcdcmd(unsigned char);

void lcddata(unsigned char);

void str(char flash *);

void lcdint(unsigned int);

/** VARIABLE DECLARATIONS **/

float dist;

bit flag=0;

unsigned char counter;

// External Interrupt 0 service routine

interrupt [EXT_INT0] void ext_int0_isr(void)

{

flag=1;

}

Page 67: Ultrasonic Based Distance Measurement

// Timer 1 overflow interrupt service routine

interrupt [TIM1_OVF] void timer1_ovf_isr(void)

{

counter++;

}

/** MAIN FUNCTION **/

void main(void)

{

unsigned long int cnt,i;

float result;

PORTA=0x00; //initially we put on 0

DDRA=0XFF; //for O/P DDR put into high

DDRB.1=0; // initial value for timer1

DDRD.2=0; // initial value for interrupt

DDRC=0xFF;

PORTC.1 = 0;

init(); //LCD INITILIZATION FUNCTION CALLING

lcdcmd(0x80); //IST LINE DISPLAY

str("ULTRASONIC BASED"); //DISPLAY STRING

lcdcmd(0xC0); //2ND LINE DISPLAY

str("DISTANCE MEASURE"); //DISPLAY STRING

delay_ms(1000);

while(1)

{

buzzer = 0;

Page 68: Ultrasonic Based Distance Measurement

TIMSK=0x80;

GICR|=0x40; //INT0: On

MCUCR=0x03; //INT0 Mode: Rising Edge

EMCUCR=0x00;

//INT1: Off

GIFR=0x40; //INT2: Off

// Global enable interrupts

#asm("sei")

DDRD.2=1; //SIG1 acts as a O/P when DDRD=1

SIG1=0; //SIG1 low

delay_us(250); //give delay 500us

delay_us(250);

SIG1=1; //SIG1 high

delay_us(5); //give delay 5us

SIG1=0; //SIG1 low

delay_us(195); //ll wait upto 200us after SIG goes to high for that give delay

195

DDRD.2=0; //Again we are going to change D2 pin as a i/p for we have to

give distance to uc

TCNT1=0; //count intialization as a zero

cnt=0;

counter=0;

while(!SIG); //we have to wait up to sig=1 after it comes out of loop

TCCR1B=1;

Page 69: Ultrasonic Based Distance Measurement

while(SIG); // when SIG=1 it enters into loop

TCCR1B=0x00;

cnt = TCNT1 + (counter)*65536;

result=(((float)cnt*0.125)/20000.0);

dist=(349.7142*result);

lcdcmd(0x01);

lcdcmd(0x80);

str("OBJECT DISTANCE:");

lcdcmd(0XC0);

lcdint(dist);

str(".");

lcdint((dist-(int)dist)*10);

str(" cm");

if(dist>150)

{

for(i=0;i<3;i++)

{

buzzer = 1;

delay_ms(300);

buzzer = 0;

delay_ms(300);

}

}

delay_ms(1000);

}

}

/** INTEGER LCD FUNCTION **/

Page 70: Ultrasonic Based Distance Measurement

void lcdint(unsigned int x)

{

unsigned int i=0,a[5],c=0;

if(x!=0)

{

while(x>0)

{

a[i++]=x%10;

x=x/10;

c++;

}

for(;c>0;--c)

{

lcddata(a[c-1]+0x30);

}

}

else

lcddata('0');

}

/**LCD INITILIZATION FUNCTION DEFINITION**/

void init()

{

lcdcmd(0x28);

lcdcmd(0x28); //4BIT-MODE

lcdcmd(0x0C); //DISPLAY ON CURSOR OFF

lcdcmd(0x06); //SHIFT CURSOR TO RIGHT

lcdcmd(0x01); //CLEAR THE SCREEN

}

Page 71: Ultrasonic Based Distance Measurement

/**LCD COMMAND FUNCTION**/

void lcdcmd(unsigned char var)

{

lcd = ((var & 0xF0) | 0x08); //RS=0,RW=0

lcd = 0;

lcd = ((var << 4) | 0x08); //RS=0,RW=0

lcd = 0;

delay_ms(1);

}

/**LCD DATA FUNCTION**/

void lcddata(unsigned char var)

{

lcd = ((var & 0xF0) | 0x0a); //RS=1,RW=0

lcd = 0;

lcd = ((var << 4) | 0x0a); //RS=1,RW=0

lcd = 0;

delay_ms(1);

}

/**LCD STRING FUNCTION**/

void str(char flash *p)

{

while(*p)

lcddata(*p++);

}

Page 72: Ultrasonic Based Distance Measurement

BIBLIOGRAPHY

TEXT BOOKS REFERED:

1. “The 8051 Microcontroller and Embedded Systems” by Muhammad Ali Mazidi

and Janice Gillispie Mazidi, Pearson Education.

2. 8051 Microcontroller Architecture, programming and application by KENNETH

JAYALA

3. ATMEL 89s52 Data sheets

4. Hand book for Digital IC’s from Analogic Devices

WEBSITES VIEWED:

www.atmel.com

www.beyondlogic.org

www.dallassemiconductors.com

www.maxim-ic.com

www.alldatasheets.com

www.howstuffworks.com

www.digi.com

Page 73: Ultrasonic Based Distance Measurement

www.wikipedia.com