Você está na página 1de 169

INDEX

TOPICS

Certificates

Acknowledgement........

CHAPTER 1: INTRODUCTION

1.1 Introduction of the project


1.2 Project overview...
1.3 Thesis

CHAPTER 2: EMBEDDED SYSTEMS

2.1 Introduction to embedded systems


2.2 Need of embedded systems...
2.3 Explanation of embedded systems...
2.4 Applications of embedded systems

CHAPTER 3: HARDWARE DESCRIPTION

3.1 Introduction with block diagram


3.2 Microcontroller.
3.3 Regulated power supply...
3.4 LED
3.5 RS232 cable
3.6 Zigbee module...
3.7 Metal Detection sensor.
1

3.8 Buzzer...............................
3.10 Relays
3.11 DC motors
3.12 DC motor driver..

CHAPTER 4: SOFTWARE DESCRIPTION

4.1 Express PCB


4.2 PIC C Compiler.
4.3 Proteus software

4.4 Procedural steps for compilation, simulation and dumping..


CHAPTER 5: PROJECT DESCRIPTION

CHAPTER 6: ADVANTAGES, DISADVANTAGES AND APPLICATIONS

CHAPTER 7: RESULTS, CONCLUSION, FUTURE PROSPECTS

REFERENCES

CHAPTER 1: INTRODUCTION
1.1 Introduction:
The advent of new high-speed technology and the growing computer
Capacity provided realistic opportunity for new robot controls and realization of new methods of
control theory. This technical improvement together with the need for high performance robots
created faster, more accurate and more intelligent robots using new robots control devices, new drives
and advanced control algorithms. This project describes a new economical solution of robot control
systems. The presented robot control system can be used for different sophisticated robot applications.
The project aims in designing a Bomb Detecting and diffusion wireless controlled War field
Robot through PC which is capable of detecting human beings and land mines in its path and which is
wirelessly controlled through PC using Zigbee technology. It is a very low cost robot used to monitor
the Warfield. The robot can be moved in all the directions using the PC wirelessly. The robot system is
also used for bomb detection and diffusion using robotic arm.
Zigbee is a PAN technology based on the IEEE 802.15.4 standard. Unlike Bluetooth or
wireless USB devices, Zigbee devices have the ability to form a mesh network between nodes.
Meshing is a type of daisy chaining from one device to another. This technique allows the short range
of an individual node to be expanded and multiplied, covering a much larger area.
The controlling device of the whole system is a Microcontroller. Whenever the user presses a
button in the PC, the data related to that button is sent through Zigbee module interfaced to PC. This
data will be received by the Zigbee module in the robot system and feds this to Microcontroller which
judges the relevant task to the information received and acts accordingly. Whenever, land mines are
detected, it alerts through buzzer alarm system and also using diffuses using robotic arm. The
Microcontrollers used in the project are programmed using Embedded C language.

This project utilizes two DC Motors respectively. The DC motor generates torque directly
from DC power supplied to the motor by using internal commutation, stationary permanent
3

magnets, and rotating electrical magnets. It works on the principle of Lorentz force, which
states that any current carrying conductor placed within an external magnetic field experiences
a torque or force known as Lorentz force. Advantages of a brushed DC motor include low initial
cost, high reliability, and simple control of motor speed. Disadvantages are high maintenance
and low life-span for high intensity uses.
Maintenance involves regularly replacing the brushes and springs which carry the
electric current, as well as cleaning or replacing the commutator. These components are
necessary for transferring electrical power from outside the motor to the spinning wire windings
of the rotor inside the motor.
The driver used for DC Motors is L293D. The Device is a monolithic integrated high
voltage, high current four channel driver designed to accept standard DTL or TTL logic levels and
drive inductive loads (such as relays solenoids, DC and stepping motors) and switching power
transistors. This project makes use of a micro controller, which is programmed, with the help of
embedded C instructions. This Microcontroller is capable of communicating with input and output
modules. The controller is interfaced with dc motors, which are fixed to the Robot to control the
direction of the Robot.

1.2 Project Overview:


An embedded system is a combination of software and hardware to perform a
dedicated task. Some of the main devices used in embedded products are Microprocessors and
Microcontrollers.
Microprocessors are commonly referred to as general purpose processors as they
simply accept the inputs, process it and give the output. In contrast, a microcontroller not only accepts
the data as inputs but also manipulates it, interfaces the data with various devices, controls the data
and thus finally gives the result.
The project Bomb Detecting and diffusion wireless controlled War field Robot
through PC using 16F72 Microcontroller is an exclusive project that can move the robot according to
the instructions given by Computer and also alerts through buzzer when any metal is being detected
by it. It also alerts when any human beings are near by using PIR sensor.

1.3 Thesis Overview:


The thesis explains the implementation of Bomb Detecting and diffusion
wireless controlled War field Robot through PC using 16F72 microcontroller. The organization of the
thesis is explained here with:

Chapter 1 Presents introduction to the overall thesis and the overview of the project. In the project
overview a brief introduction of metal detection, PIR sensors, DC motors with driver, buzzer, and
using of robot and its applications are discussed.
Chapter 2

Presents the topic embedded systems. It explains the about what is embedded systems,

need for embedded systems, explanation of it along with its applications.


Chapter 3

Presents the hardware description. It deals with the block diagram of the project and

explains the purpose of each block. In the same chapter the explanation of microcontrollers, power
supplies, metal detection sensors, DC motors with driver, buzzer, relay and Zigbee modules are
considered.
Chapter 4

Presents the software description. It explains the implementation of the project using PIC

C Compiler software.
Chapter 5 Presents the project description along with metal detection, Zigbee module, buzzer, relay,
DC motors with driver interfacing to microcontroller.
Chapter 6

Presents the advantages, disadvantages and applications of the project.

Chapter 7 Presents the results, conclusion and future scope of the project.

CHAPTER 2: EMBEDDED SYSTEMS


2.1 Embedded Systems:
An embedded system is a computer system designed to perform one or a few dedicated
functions often with real-time computing constraints. It is embedded as part of a complete device
often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a
personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs.
Embedded systems control many devices in common use today.
Embedded systems are controlled by one or more main processing cores that are
typically either microcontrollers or digital signal processors (DSP). The key characteristic, however, is
being dedicated to handle a particular task, which may require very powerful processors. For example,
air traffic control systems may usefully be viewed as embedded, even though they involve mainframe
computers and dedicated regional and national networks between airports and radar sites. (Each radar
probably includes one or more embedded systems of its own.)
Since the embedded system is dedicated to specific tasks, design engineers can
optimize it to reduce the size and cost of the product and increase the reliability and performance.
Some embedded systems are mass-produced, benefiting from economies of scale.
Physically embedded systems range from portable devices such as digital watches and
MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems
controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to
very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.
In general, "embedded system" is not a strictly definable term, as most systems have
some element of extensibility or programmability. For example, handheld computers share some
elements with embedded systems such as the operating systems and microprocessors which power
them, but they allow different applications to be loaded and peripherals to be connected. Moreover,
even systems which don't expose programmability as a primary feature generally need to support
software updates. On a continuum from "general purpose" to "embedded", large application systems
will have subcomponents at most points even if the system as a whole is "designed to perform one or
6

a few dedicated functions", and is thus appropriate to call "embedded". A modern example of
embedded system is shown in fig: 2.1.

Fig 2.1:A modern example of embedded system


Labeled parts include microprocessor (4), RAM (6), flash memory (7).Embedded
systems programming is not like normal PC programming. In many ways, programming for an
embedded system is like programming PC 15 years ago. The hardware for the system is usually
chosen to make the device as cheap as possible. Spending an extra dollar a unit in order to make
things easier to program can cost millions. Hiring a programmer for an extra month is cheap in
comparison. This means the programmer must make do with slow processors and low memory, while
at the same time battling a need for efficiency not seen in most PC applications. Below is a list of
issues specific to the embedded field.
2.1.1 History:
In the earliest years of computers in the 193040s, computers were sometimes
dedicated to a single task, but were far too large and expensive for most kinds of tasks performed by
embedded computers of today. Over time however, the concept of programmable controllers evolved
from traditional electromechanical sequencers, via solid state devices, to the use of computer
technology.

One of the first recognizably modern embedded systems was the Apollo Guidance
Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. At the project's
inception, the Apollo guidance computer was considered the riskiest item in the Apollo project as it
employed the then newly developed monolithic integrated circuits to reduce the size and weight. An
early mass-produced embedded system was the Autonetics D-17 guidance computer for
the Minuteman missile, released in 1961. It was built from transistor logic and had a hard disk for
main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a
new computer that was the first high-volume use of integrated circuits.
2.1.2 Tools:
Embedded development makes up a small fraction of total programming. There's also a
large number of embedded architectures, unlike the PC world where 1 instruction set rules, and the
UNIX world where there's only 3 or 4 major ones. This means that the tools are more expensive. It
also means that they're lowering featured, and less developed. On a major embedded project, at some
point you will almost always find a compiler bug of some sort.
Debugging tools are another issue. Since you can't always run general programs on
your embedded processor, you can't always run a debugger on it. This makes fixing your program
difficult. Special hardware such as JTAG ports can overcome this issue in part. However, if you stop
on a breakpoint when your system is controlling real world hardware (such as a motor), permanent
equipment damage can occur. As a result, people doing embedded programming quickly become
masters at using serial IO channels and error message style debugging.
2.1.3 Resources:
To save costs, embedded systems frequently have the cheapest processors that can do
the job. This means your programs need to be written as efficiently as possible. When dealing with
large data sets, issues like memory cache misses that never matter in PC programming can hurt you.
Luckily, this won't happen too often- use reasonably efficient algorithms to start, and optimize only
when necessary. Of course, normal profilers won't work well, due to the same reason debuggers don't
work well.
Memory is also an issue. For the same cost savings reasons, embedded systems usually
have the least memory they can get away with. That means their algorithms must be memory efficient
(unlike in PC programs, you will frequently sacrifice processor time for memory, rather than the
8

reverse). It also means you can't afford to leak memory. Embedded applications generally use
deterministic memory techniques and avoid the default "new" and "malloc" functions, so that leaks
can be found and eliminated more easily. Other resources programmers expect may not even exist.
For example, most embedded processors do not have hardware FPUs (Floating-Point Processing
Unit). These resources either need to be emulated in software, or avoided altogether.
2.1.4 Real Time Issues:
Embedded systems frequently control hardware, and must be able to respond to them
in real time. Failure to do so could cause inaccuracy in measurements, or even damage hardware such
as motors. This is made even more difficult by the lack of resources available. Almost all embedded
systems need to be able to prioritize some tasks over others, and to be able to put off/skip low priority
tasks such as UI in favor of high priority tasks like hardware control.
2.2 Need For Embedded Systems:
The uses of embedded systems are virtually limitless, because every day new products
are introduced to the market that utilizes embedded computers in novel ways. In recent years,
hardware such as microprocessors, microcontrollers, and FPGA chips have become much cheaper. So
when implementing a new form of control, it's wiser to just buy the generic chip and write your own
custom software for it. Producing a custom-made chip to handle a particular task or set of tasks costs
far more time and money. Many embedded computers even come with extensive libraries, so that
"writing your own software" becomes a very trivial task indeed. From an implementation viewpoint,
there is a major difference between a computer and an embedded system. Embedded systems are often
required to provide Real-Time response. The main elements that make embedded systems unique are
its reliability and ease in debugging.
2.2.1 Debugging:
Embedded debugging may be performed at different levels, depending on the facilities
available. From simplest to most sophisticate they can be roughly grouped into the following areas:

Interactive resident debugging, using the simple shell provided by the embedded operating
system (e.g. Forth and Basic)

External debugging using logging or serial port output to trace operation using either a
monitor in flash or using a debug server like the Remedy Debugger which even works for
heterogeneous multi core systems.

An in-circuit debugger (ICD), a hardware device that connects to the microprocessor via a
JTAG or Nexus interface. This allows the operation of the microprocessor to be controlled
externally, but is typically restricted to specific debugging capabilities in the processor.

An in-circuit emulator replaces the microprocessor with a simulated equivalent, providing full
control over all aspects of the microprocessor.

A complete emulator provides a simulation of all aspects of the hardware, allowing all of it to
be controlled and modified and allowing debugging on a normal PC.

Unless restricted to external debugging, the programmer can typically load and run software
through the tools, view the code running in the processor, and start or stop its operation. The
view of the code may be as assembly code or source-code.
Because an embedded system is often composed of a wide variety of elements, the

debugging strategy may vary. For instance, debugging a software(and microprocessor) centric
embedded system is different from debugging an embedded system where most of the processing is
performed by peripherals (DSP, FPGA, co-processor). An increasing number of embedded systems
today use more than one single processor core. A common problem with multi-core development is
the proper synchronization of software execution. In such a case, the embedded system design may
wish to check the data traffic on the busses between the processor cores, which requires very lowlevel debugging, at signal/bus level, with a logic analyzer, for instance.
2.2.2 Reliability:
Embedded systems often reside in machines that are expected to run continuously for
years without errors and in some cases recover by them if an error occurs. Therefore the software is
usually developed and tested more carefully than that for personal computers, and unreliable
mechanical moving parts such as disk drives, switches or buttons are avoided.
Specific reliability issues may include:

The system cannot safely be shut down for repair, or it is too inaccessible to repair. Examples
include space systems, undersea cables, navigational beacons, bore-hole systems, and
automobiles.
10

The system must be kept running for safety reasons. "Limp modes" are less tolerable. Often
backup s are selected by an operator. Examples include aircraft navigation, reactor control
systems, safety-critical chemical factory controls, train signals, engines on single-engine
aircraft.

The system will lose large amounts of money when shut down: Telephone switches, factory
controls, bridge and elevator controls, funds transfer and market making, automated sales and
service.
A variety of techniques are used, sometimes in combination, to recover from errors

both software bugs such as memory leaks, and also soft errors in the hardware:

Watchdog timer that resets the computer unless the software periodically notifies the watchdog

Subsystems with redundant spares that can be switched over to

software "limp modes" that provide partial function

Designing with a Trusted Computing Base (TCB) architecture[6] ensures a highly secure &
reliable system environment

An Embedded Hypervisor is able to provide secure encapsulation for any subsystem


component, so that a compromised software component cannot interfere with other
subsystems, or privileged-level system software. This encapsulation keeps faults from
propagating from one subsystem to another, improving reliability. This may also allow a
subsystem to be automatically shut down and restarted on fault detection.

Immunity Aware Programming

2.3 Explanation of Embedded Systems:


2.3.1 Software Architecture:
There are several different types of software architecture in common use.

Simple Control Loop:

In this design, the software simply has a loop. The loop calls subroutines, each of which
manages a part of the hardware or software.

Interrupt Controlled System:


11

Some embedded systems are predominantly interrupt controlled. This means that tasks
performed by the system are triggered by different kinds of events. An interrupt could be generated
for example by a timer in a predefined frequency, or by a serial port controller receiving a byte. These
kinds of systems are used if event handlers need low latency and the event handlers are short and
simple.
Usually these kinds of systems run a simple task in a main loop also, but this task is not
very sensitive to unexpected delays. Sometimes the interrupt handler will add longer tasks to a queue
structure. Later, after the interrupt handler has finished, these tasks are executed by the main loop.
This method brings the system close to a multitasking kernel with discrete processes.

Cooperative Multitasking:

A non-preemptive multitasking system is very similar to the simple control loop


scheme, except that the loop is hidden in an API. The programmer defines a series of tasks, and each
task gets its own environment to run in. When a task is idle, it calls an idle routine, usually called
pause, wait, yield, nop (stands for no operation), etc.The advantages and disadvantages are
very similar to the control loop, except that adding new software is easier, by simply writing a new
task, or adding to the queue-interpreter.

Primitive Multitasking:

In this type of system, a low-level piece of code switches between tasks or threads
based on a timer (connected to an interrupt). This is the level at which the system is generally
considered to have an "operating system" kernel. Depending on how much functionality is required, it
introduces more or less of the complexities of managing multiple tasks running conceptually in
parallel.
As any code can potentially damage the data of another task (except in larger systems
using an MMU) programs must be carefully designed and tested, and access to shared data must be
controlled by some synchronization strategy, such as message queues, semaphores or a non-blocking
synchronization scheme.
Because of these complexities, it is common for organizations to buy a real-time
operating system, allowing the application programmers to concentrate on device functionality rather
than operating system services, at least for large systems; smaller systems often cannot afford the
12

overhead associated with a generic real time system, due to limitations regarding memory size,
performance, and/or battery life.

Microkernels And Exokernels:


A microkernel is a logical step up from a real-time OS. The usual arrangement is that

the operating system kernel allocates memory and switches the CPU to different threads of execution.
User mode processes implement major functions such as file systems, network interfaces, etc.
In general, microkernels succeed when the task switching and intertask communication
is fast, and fail when they are slow. Exokernels communicate efficiently by normal subroutine calls.
The hardware and all the software in the system are available to, and extensible by application
programmers. Based on performance, functionality, requirement the embedded systems are divided
into three categories:
2.3.2 Stand Alone Embedded System:
These systems takes the input in the form of electrical signals from transducers or
commands from human beings such as pressing of a button etc.., process them and produces desired
output. This entire process of taking input, processing it and giving output is done in standalone mode.
Such embedded systems comes under stand alone embedded systems
Eg: microwave oven, air conditioner etc..
2.3.3 Real-time embedded systems:
Embedded systems which are used to perform a specific task or operation in a specific
time period those systems are called as real-time embedded systems. There are two types of real-time
embedded systems.

Hard Real-time embedded systems:


These embedded systems follow an absolute dead line time period i.e.., if the tasking is

not done in a particular time period then there is a cause of damage to the entire equipment.
Eg: consider a system in which we have to open a valve within 30 milliseconds. If this valve is
not opened in 30 ms this may cause damage to the entire equipment. So in such cases we use
embedded systems for doing automatic operations.
13

Soft Real Time embedded systems:

Eg: Consider a TV remote control system, if the remote control takes a few milliseconds delay it will
not cause damage either to the TV or to the remote control. These systems which will not cause damage when
they are not operated at considerable time period those systems comes under soft real-time embedded systems.

2.3.4 Network communication embedded systems:


A wide range network interfacing communication is provided by using embedded
systems.
Eg:

Consider a web camera that is connected to the computer with internet can be used to
spread communication like sending pictures, images, videos etc.., to another computer
with internet connection throughout anywhere in the world.

Consider a web camera that is connected at the door lock.


Whenever a person comes near the door, it captures the image of a person and sends to

the desktop of your computer which is connected to internet. This gives an alerting message with
image on to the desktop of your computer, and then you can open the door lock just by clicking the
mouse. Fig: 2.2 show the network communications in embedded systems.

Fig 2.2: Network communication embedded systems

14

2.3.5 Different types of processing units:


The central processing unit (c.p.u) can be any one of the following microprocessor,
microcontroller, digital signal processing.

Among these Microcontroller is of low cost processor and one of the main advantage of
microcontrollers is, the components such as memory, serial communication interfaces, analog
to digital converters etc.., all these are built on a single chip. The numbers of external
components that are connected to it are very less according to the application.

Microprocessors are more powerful than microcontrollers. They are used in major applications
with a number of tasking requirements. But the microprocessor requires many external
components like memory, serial communication, hard disk, input output ports etc.., so the
power consumption is also very high when compared to microcontrollers.

Digital signal processing is used mainly for the applications that particularly involved with
processing of signals

2.4 APPLICATIONS OF EMBEDDED SYSTEMS:


2.4.1 Consumer applications:
At home we use a number of embedded systems which include microwave oven,
remote control, vcd players, dvd players, camera etc.

Fig2.3: Automatic coffee makes equipment

15

2.4.2 Office automation:


We use systems like fax machine, modem, printer etc

Fig2.4: Fax machine

Fig2.5: Printing machine

2.4.3. Industrial automation:


Today a lot of industries are using embedded systems for process control. In industries
we design the embedded systems to perform a specific operation like monitoring temperature,
pressure, humidity ,voltage, current etc.., and basing on these monitored levels we do control other
devices, we can send information to a centralized monitoring station.

Fig2.6: Robot
In critical industries where human presence is avoided there we can use robots which
are programmed to do a specific operation.
16

2.4.5 Computer networking:


Embedded systems are used as bridges routers etc..

Fig2.7: Computer networking


2.4.6 Tele communications:
Cell phones, web cameras etc.

Fig2.8: Cell Phone

Fig2.9: Web camera

CHAPTER 3: HARDWARE DESCRIPTION


17

3.1 Introduction:
In this chapter the block diagram of the project and design aspect of independent
modules are considered. Block diagram is shown in fig: 3.1:

FIG 3.1(i): Block diagram of Bomb Detecting and diffusion wireless controlled War field Robot
through PC

18

FIG 3.1(ii): Block diagram of Bomb Detecting and diffusion wireless controlled War field
Robot through PC
The main blocks of this project are:

Micro controller (16F72)

. Reset button

Crystal oscillator
19

Regulated power supply (RPS)

Led indicator

RS232 cable

Zigbee module

Metal detection sensor

Buzzer

Relay

DC Motors

DC motors drivers

3.2 Micro controller:


MICROCONTROLLER
A Microcontroller is a programmable digital processor with necessary peripherals.
Both microcontrollers and microprocessors are complex sequential digital circuits meant
to carry out job according to the program / instructions. Sometimes analog input/output
interface makes a part of microcontroller circuit of mixed mode (both analog and digital
nature).
1. A smaller computer
2. On-chip RAM, ROM, I/O ports...
Example: Motorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X
General-purpose microprocessor
1. CPU for Computers
2. No RAM, ROM, I/O on CPU chip itself
3. Example: Intels x86, Motorolas 680x0
20

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.

expansive

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

Choosing a MC

Speed

Packaging(Ex. DIP,QFP Quad Flat Package)

Power Consumption

Amount of RAM,ROM

I/O Pins

Final Cost of The product

How easy it is Upgraded

Memory types

In a microcontroller, two types of memory are found. They are, program memory and data memory
respectively. Program memory is also known as 'control store' and 'firm ware'. It is non-volatile i.e, the

21

memory content is not lost when the power goes off. Non-volatile memory is also called Read Only
Memory (ROM). There are various types of ROM.
1. Mask ROM: Some microcontrollers with ROM are programmed while they are still
in the factory. This ROM is called Mask ROM. Since the microcontrollers with Mask
ROM are used for specific application, there is no need to reprogram them. Some
times, this type of manufacturing reduces the cost for bulk production.
2.

Reprogrammable

program

memory

(or)

Erasable

PROM

(EPROM):

Microcontrollers with EPROM were introduced in late 1970's. These devices are
electrically programmable but are erased with UV radiation. The construction of a
EPROM memory cell is somewhat like a MOSFET but with a control and float
semiconductor as shown in the figure.

In the unprogrammed state, the 'float' does not have any charge and the MOSFET is
in the OFF state. To program the cell, the 'control' above the 'float' is raised to a high
enough potential such that a charge leaks to the float through SiO 2 insulating layer.
Hence a channel is formed between 'Source' and 'Drain' in the silicon substrate and
the MOSFET becomes 'ON'. The charge in the 'float' remains for a long time (typically
over 30 years). The charge can be removed by exposing the float to UV radiation. For
UV erasable version, the packaging is done in a ceramic enclosure with a glass
window.
22

Usually, these versions of micro controllers are expensive


3. OTP EPROM: One time programmable (OTP) EPROM based microcontrollers do
not have any glass window for UV erasing. These can be programmed only once.
This type of packaging results in microcontroller that have the cost 10% of the
microcontrollers with UV erase facility (i.e., 1/10th cost).
4. EEPROM: (Electrically Erasable Programmable ROM): This is similar to EPROM but
the float charge can be removed electrically.
5. FLASH (EEPROM Memory): FLASH memory was introduced by INTEL in late
1980's.
This memory is similar to EEPROM but the cells in a FLASH memory are bussed so
that they can be erased in a few clock cycles. Hence the reprogramming is faster.
Different Data memory types:
1. Random access memory (RAM)
2. Read only memory (ROM)
Random access memory (RAM): data will disappear after power down.

Static RAM (SRAM): each bit is a flip-flop, fast but expensive.

Dynamic RAM (DRAM): each bit is a small capacitor, and is needed to be


recharged regularly, slower but cheap. To be used as primary memory in a
computer.

Data memory can be classified into the following categories


23

Bits

Registers

Variable RAM

Program counter stack

Microcontroller can have ability to perform manipulation of individual bits in certain registers (bit
manipulation). This is a unique feature of a microcontroller, not available in a microprocessor.
Eight bits make a byte. Memory bytes are known as file registers.
Registers are some special RAM locations that can be accessed by the processor very
easily.
Static RAM (SRAM) memory cell:

This consists of two CMOS inverters connected back to front, so as to form a latch. Processor stacks
store/save the data in a simple way during program execution. Processor stack is a part of RAM area
where the data is saved in a Last in First out (LIFO) fashion just like a stack of paper on a table. Data
is stored by executing a 'push' instruction and data is read out using a 'pop' instruction

24

SRAM memory cell equivalent

Internal Structure of a Microcontroller

25

At times, a microcontroller can have external memory also (if there is no internal
memory or extra memory interface is required). Early microcontrollers were
manufactured using bipolar or NMOS technologies. Most modern microcontrollers are
manufactured with CMOS technology, which leads to reduction in size and power
loss. Current drawn by the IC is also reduced considerably from 10mA to a few micro
Amperes in sleep mode (for a microcontroller running typically at a clock speed of
20MHz).

Harvard vs. Princeton Architecture


Many years ago, in the late 1940's, the US Government asked Harvard and
Princeton universities to come up with a computer architecture to be used in
26

computing distances of Naval artillery shell for defense applications. Princeton


suggested computer architecture with a single memory interface. It is also known as
Von Neumann architecture after the name of the chief scientist of the project in
Princeton University John Von Neumann (1903 - 1957 Born in Budapest, Hungary).
Harvard suggested a computer with two different memory interfaces, one for the
data / variables and the other for program / instructions. Although Princeton
architecture was accepted for simplicity and ease of implementation, Harvard
architecture became popular later, due to the parallelism of instruction execution
Princeton Architecture (Single memory interface):
Program memory and data memory are interfaced to CPU through common buses

An instruction "Read a data byte from memory and store it in the accumulator" is executed as follows:
Cycle 1 - Read Instruction
Cycle 2 - Read Data out of RAM and put into Accumulator
It will take more time to execute instructions

27

Harvard Architecture

(Separate Program and Data Memory interfaces)

Hence each instruction is effectively executed in one instruction cycle, except for the
ones that modify the content of the program counter. For example, the "jump" (or
call) instructions takes 2 cycles. Thus, due to parallelism, Harvard architecture
executes more instructions in a given time compared to Princeton Architecture
PIC Microcontrollers:
PIC stands for Peripheral Interface Controller given by Microchip Technology to
identify its single-chip microcontrollers. These devices have been very successful in
8-bit microcontrollers. The main reason is that Microchip Technology has continuously
upgraded

the

device

architecture

and

added

needed

peripherals

to

the

microcontroller to suit customers' requirements. The development tools such as


assembler and simulator are freely available on the internet at www.microchip.com .
Low - end PIC Architectures:
Microchip

PIC

microcontrollers

are

available

in

various

types.

When

PIC

microcontroller MCU was first available from General Instruments in early 1980's, the
microcontroller consisted of a simple processor executing 12-bit wide instructions
28

with basic I/O functions. These devices are known as low-end architectures. They
have limited program memory and are meant for applications requiring simple
interface functions and small program & data memories. Some of the low-end device
numbers are
12C5XX
16C5X
16C505
Mid range PIC Architectures
Mid range PIC architectures are built by upgrading low-end architectures with more
number of peripherals, more number of registers and more data/program memory.
Some of the mid-range devices are
16C6X
16C7X
16F87X
Program memory type is indicated by an alphabet.
C = EPROM
F = Flash
RC = Mask ROM
Popularity of the PIC microcontrollers is due to the following factors.
1. Speed: Harvard Architecture, RISC architecture, 1 instruction cycle = 4 clock
cycles.
2. Instruction set simplicity: The instruction set consists of just 35 instructions (as
opposed to 111 instructions for 8051).
3. Power-on-reset and brown-out reset. Brown-out-reset means when the power
supply goes below a specified voltage (say 4V), it causes PIC to reset; hence
malfunction is avoided.
A watch dog timer (user programmable) resets the processor if the software/program
ever malfunctions and deviates from its normal operation.
29

4. PIC microcontroller has four optional clock sources.

Low power crystal

Mid range crystal

High range crystal

RC oscillator (low cost).

5. Programmable timers and on-chip ADC.


6. Up to 12 independent interrupt sources.
7. Powerful output pin control (25 mA (max.) current sourcing capability per pin.)
8. EPROM/OTP/ROM/Flash memory option.
9. I/O port expansion capability.
Free assembler and simulator support from Microchip at www.microchip.com
CPU Architecture:
The CPU uses Harvard architecture with separate Program and Variable (data)
memory

interface.

This

facilitates

instruction

data/accessing of variables simultaneously.


Architecture of PIC microcontroller

PIC Microcontroller Clock

30

fetch

and

the

operation

on

Most of the PIC microcontrollers can operate up to 20MHz. One instructions cycle
(machine cycle) consists of four clock cycles
Relation between instruction cycles and clock cycles for PIC microcontrollers

Instructions that do not require modification of program counter content get


executed in one instruction cycle.

Microcontrollers versus Microprocessors


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 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.
Memory unit
Memory

is

part

of

the

microcontroller

whose

function

is

to

store

data.

The easiest way to explain it is to describe it as one big closet with lots of drawers. If we suppose that
we marked the drawers in such a way that they can not be confused, any of their contents will then be
easily accessible. It is enough to know the designation of the drawer and so its contents will be known
to us for sure.

31

Memory components are exactly like that. For a certain input we get the contents of a certain
addressed memory location and that's all. Two new concepts are brought to us: addressing and
memory location. Memory consists of all memory locations, and addressing is nothing but selecting
one of them. This means that we need to select the desired memory location on one hand, and on the
other hand we need to wait for the contents of that location. Besides reading from a memory location,
memory must also provide for writing onto it. This is done by supplying an additional line called
control line. We will designate this line as R/W (read/write). Control line is used in the following way:
if r/w=1, reading is done, and if opposite is true then writing is done on the memory location.
Memory is the first element, and we need a few operation of our microcontroller.
Central Processing Unit
Let add 3 more memory locations to a specific block that will have a built in capability to multiply,
divide, subtract, and move its contents from one memory location onto another. The part we just
added in is called "central processing unit" (CPU). Its memory locations are called registers.

32

Registers are therefore memory locations whose role is to help with performing various mathematical
operations or any other operations with data wherever data can be found. Look at the current situation.
We have two independent entities (memory and CPU) which are interconnected, and thus any
exchange of data is hindered, as well as its functionality. If, for example, we wish to add the contents
of two memory locations and return the result again back to memory, we would need a connection
between memory and CPU. Simply stated, we must have some "way" through data goes from one
block to another.
Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires
there are two types of buses: address and data bus. The first one consists of as many lines as the
amount of memory we wish to address and the other one is as wide as data, in our case 8 bits or the
connection line. First one serves to transmit address from CPU memory, and the second to connect all
blocks inside the microcontroller.

33

As far as functionality, the situation has improved, but a new problem has also appeared: we have a
unit that's capable of working by itself, but which does not have any contact with the outside world, or
with us! In order to remove this deficiency, let's add a block which contains several memory locations
whose one end is connected to the data bus, and the other has connection with the output lines on the
microcontroller which can be seen as pins on the electronic component.
Input-output unit
Those locations we've just added are called "ports". There are several types of ports : input, output or
bidirectional ports. When working with ports, first of all it is necessary to choose which port we need
to work with, and then to send data to, or take it from the port.

When working with it the port acts like a memory location. Something is simply being written into or
read from it, and it could be noticed on the pins of the microcontroller.
34

Serial communication
Beside stated above we've added to the already existing unit the possibility of communication with an
outside world. However, this way of communicating has its drawbacks. One of the basic drawbacks is
the number of lines which need to be used in order to transfer data. What if it is being transferred to a
distance of several kilometers? The number of lines times number of kilometers doesn't promise the
economy of the project. It leaves us having to reduce the number of lines in such a way that we don't
lessen its functionality. Suppose we are working with three lines only, and that one line is used for
sending data, other for receiving, and the third one is used as a reference line for both the input and
the output side. In order for this to work, we need to set the rules of exchange of data. These rules are
called protocol. Protocol is therefore defined in advance so there wouldn't be any misunderstanding
between the sides that are communicating with each other. For example, if one man is speaking in
French, and the other in English, it is highly unlikely that they will quickly and effectively understand
each other. Let's suppose we have the following protocol. The logical unit "1" is set up on the
transmitting line until transfer begins. Once the transfer starts, we lower the transmission line to
logical "0" for a period of time (which we will designate as T), so the receiving side will know that it
is receiving data, and so it will activate its mechanism for reception. Let's go back now to the
transmission side and start putting logic zeros and ones onto the transmitter line in the order from a bit
of the lowest value to a bit of the highest value. Let each bit stay on line for a time period which is
equal to T, and in the end, or after the 8th bit, let us bring the logical unit "1" back on the line which
will mark the end of the transmission of one data. The protocol we've just described is called in
professional literature NRZ (Non-Return to Zero).

As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at
the same time. So called full-duplex mode block which enables this way of communication is called a
serial communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series
35

of bits what defines the term serial communication comes from. After the reception of data we need to
read it from the receiving location and store it in memory as opposed to sending where the process is
reversed. Data goes from memory through the bus to the sending location, and then to the receiving
unit according to the protocol.
Timer unit
Since we have the serial communication explained, we can receive, send and process data.

However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer
block which is significant to us because it can give us information about time, duration, protocol etc.
The basic unit of the timer is a free-run counter which is in fact a register whose numeric value
increments by one in even intervals, so that by taking its value during periods T1 and T2 and on the
basis of their difference we can determine how much time has elapsed. This is a very important part of
the microcontroller whose understanding requires most of our time.
Watchdog
One more thing is requiring our attention is a flawless functioning of the microcontroller
during its run-time. Suppose that as a result of some interference (which often does occur in industry)
our microcontroller stops executing the program, or worse, it starts working incorrectly.

Of course, when this happens with a computer, we simply reset it and it will keep working. However,
there is no reset button we can push on the microcontroller and thus solve our problem. To overcome
this obstacle, we need to introduce one more block called watchdog. This block is in fact another freerun counter where our program needs to write a zero in every time it executes correctly.
36

In case that program gets "stuck", zero will not be written in, and counter alone will reset the
microcontroller upon achieving its maximum value this will result in executing the program again,
and correctly this time around. That is an important element of every program to be reliable without
man's supervision.
Analog to Digital Converter
As the peripheral signals usually are substantially different from the ones that microcontroller can
understand (zero and one), they have to be converted into a pattern which can be comprehended by a
microcontroller. This task is performed by a block for analog to digital conversion or by an ADC. This
block is responsible for converting an information about some analog value to a binary number and
for follow it through to a CPU block so that CPU block can further process it.

Finally, the microcontroller is now completed, and all we need to do now is to assemble it into an
electronic component where it will access inner blocks through the outside pins. The picture below
shows what a microcontroller looks like inside.

Physical configuration of the interior of a microcontroller


Thin lines which lead from the center towards the sides of the microcontroller represent wires
connecting inner blocks with the pins on the housing of the microcontroller so called bonding lines.
Chart on the following page represents the center section of a microcontroller.
37

Microcontroller outline with its basic elements and internal connections


For a real application, a microcontroller alone is not enough. Beside a microcontroller, we
need a program that would be executed, and a few more elements which make up a interface logic
towards the elements of regulation (which will be discussed in later chapters).
The program adds the contents of two memory locations, and views their sum on port A. The
first line of the program stands for moving the contents of memory location "A" into one of the
registers of central processing unit. As we need the other data as well, we will also move it into the
other register of the central processing unit. The next instruction instructs the central processing unit
to add the contents of those two registers and send a result to port A, so that sum of that addition
would be visible to the outside world. For a more complex problem, program that works on its
38

solution

will

be

bigger.

Programming can be done in several languages such as Assembler, C and Basic which are most
commonly used languages. Assembler belongs to lower level languages that are programmed slowly,
but take up the least amount of space in memory and gives the best results where the speed of
program execution is concerned. As it is the most commonly used language in programming
microcontrollers it will be discussed in a later chapter. Programs in C language are easier to be
written, easier to be understood, but are slower in executing from assembler programs. Basic is the
easiest one to learn, and its instructions are nearest a man's way of reasoning, but like C programming
language it is also slower than assembler. In any case, before you make up your mind about one of
these languages you need to consider carefully the demands for execution speed, for the size of
memory and for the amount of time available for its assembly.

After the program is written, we would install the microcontroller into a device and run
it. In order to do this we need to add a few more external components necessary for its work. First we
must give life to a microcontroller by connecting it to a power supply (power needed for operation of
all electronic instruments) and oscillator whose role is similar to the role that heart plays in a human
body. Based on its clocks microcontroller executes instructions of a program. As it receives supply
microcontroller will perform a small check up on itself, look up the beginning of the program and
start executing it. How the device will work depends on many parameters, the most important of
which is the skillfulness of the developer of hardware, and on programmer's expertise in getting the
maximum out of the device with his program.
Introduction
PIC16F belongs to a class of 8-bit microcontrollers of RISC architecture.
Its

general

structure

is

shown

on

the

following

map

representing

basic

blocks.

Program memory (FLASH)It is used for storing a written program. Since memory made in FLASH technology can be
programmed and cleared more than once, it makes this microcontroller suitable for device
development.
EEPROM

data

memory

that

needs

to

be

saved

when

there

is

no

supply.

It is usually used for storing important data that must not be lost if power supply suddenly stops. For
39

instance, one such data is an assigned temperature in temperature regulators. If during a loss of power
supply this data was lost, we would have to make the adjustment once again upon return of supply.
Thus

our

device

looses

on

self-reliance.

RAM- Data memory used by a program during its execution. In RAM are stored all inter-results or
temporary data during run-time.
PORTA and PORTB are physical connections between the microcontroller and the outside world.
Port A has five, and port B has eight pins.
FREE-RUN TIMER is an 8-bit register inside a microcontroller that works independently of the
program. On every fourth clock of the oscillator it increments its value until it reaches the maximum
(255), and then it starts counting over again from zero. As we know the exact timing between each
two increments of the timer contents, timer can be used for measuring time which is very useful with
some devices.
CENTRAL PROCESSING UNIT has a role of connective element between other blocks in the
microcontroller. It coordinates the work of other blocks and executes the user program.

40

Applications
PIC16F perfectly fits many uses, from automotive industries and controlling home appliances to
industrial instruments, remote sensors, electrical door locks and safety devices. It is also ideal for
smart cards as well as for battery supplied devices because of its low consumption.
EEPROM memory makes it easier to apply microcontrollers to devices where permanent storage of
various parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc.). Low
cost, low consumption, easy handling and flexibility make PIC16F applicable even in areas where
microcontrollers had not previously been considered (example: timer functions, interface replacement
in larger systems, coprocessor applications, etc.).
In System Programmability of this chip (along with using only two pins in data transfer) makes
possible the flexibility of a product, after assembling and testing have been completed. This capability
can be used to create assembly-line production, to store calibration data available only after final
testing, or it can be used to improve programs on finished products.
Clock / instruction cycle
Clock is microcontroller's main starter, and is obtained from an external component called an
"oscillator". If we want to compare a microcontroller with a time clock, our "clock" would then be a
ticking sound we hear from the time clock. In that case, oscillator could be compared to a spring that
is wound so time clock can run. Also, force used to wind the time clock can be compared to an
electrical

supply.

Clock from the oscillator enters a microcontroller via OSC1 pin where internal circuit of a
microcontroller divides the clock into four even clocks Q1, Q2, Q3, and Q4 which do not overlap.
41

These four clocks make up one instruction cycle (also called machine cycle) during which one
instruction is executed.
Execution of instruction starts by calling an instruction that is next in string. Instruction is called from
program memory on every Q1 and is written in instruction register on Q4. Decoding and execution of
instruction are done between the next Q1 and Q4 cycles. On the following diagram we can see the
relationship between instruction cycle and clock of the oscillator (OSC1) as well as that of internal
clocks Q1-Q4. Program counter (PC) holds information about the address of the next instruction.

Pipelining
Instruction cycle consists of cycles Q1, Q2, Q3 and Q4. Cycles of calling and executing instructions
are connected in such a way that in order to make a call, one instruction cycle is needed, and one more
is needed for decoding and execution. However, due to pipelining, each instruction is effectively
executed in one cycle. If instruction causes a change on program counter, and PC doesn't point to the
following but to some other address (which can be the case with jumps or with calling subprograms),
two cycles are needed for executing an instruction. This is so because instruction must be processed
again, but this time from the right address. Cycle of calling begins with Q1 clock, by writing into
instruction register (IR). Decoding and executing begins with Q2, Q3 and Q4 clocks.

42

TCY0 reads in instruction MOVLW 55h (it doesn't matter to us what instruction was executed,
because
TCY1

there
executes

TCY2

executes

is

no

instruction
MOVWF

rectangle
MOVLW

55h

PORTB

pictured
and
and

reads
reads

on

the

bottom).

in

MOVWF

PORTB.

in

CALL

SUB_1.

TCY3 executes a call of a subprogram CALL SUB_1, and reads in instruction BSF PORTA, BIT3. As
this instruction is not the one we need, or is not the first instruction of a subprogram SUB_1 whose
execution is next in order, instruction must be read in again. This is a good example of an instruction
needing

more

than

one

cycle.

TCY4 instruction cycle is totally used up for reading in the first instruction from a subprogram at
address SUB_1.
TCY5 executes the first instruction from a subprogram SUB_1 and reads in the next one.
Pin description
Clock generator - oscillator
Oscillator circuit is used for providing a microcontroller with a clock. Clock is needed so that
microcontroller could execute a program or program instructions.
Types of oscillators
PIC16Fcan work with four different configurations of an oscillator

43

Since configurations with crystal oscillator and resistor-capacitor (RC) are the ones that are used most
frequently, these are the only ones we will mention here. Microcontroller type with a crystal oscillator
has in its designation XT, and a microcontroller with resistor-capacitor pair has a designation RC.
This is important because you need to mention the type of oscillator when buying a microcontroller.
XT Oscillator
Crystal oscillator is kept in metal
housing with two pins where you
have written down the frequency at
which crystal oscillates. One ceramic
capacitor of 30pF whose other end is
connected to the ground needs to be
connected with each pin.

Oscillator and capacitors can be packed in


joint case with three pins. Such element is
called ceramic resonator and is represented
in charts like the one below.
Center pins of the element is the ground,
while end pins are connected with OSC1
and OSC2 pins on the microcontroller.
When designing a device, the rule is to
place

an

oscillator

nearer

microcontroller, so as to avoid any


interference

on

lines

on

which

microcontroller is receiving a clock.


RC Oscillator
In applications where great time precision is not necessary, RC oscillator offers additional
savings during purchase. Resonant frequency of RC oscillator depends on supply voltage rate,
resistance R, capacity C and working temperature. It should be mentioned here that resonant
frequency is also influenced by normal variations in process parameters, by tolerance of external R
and C components, etc.
44

Above diagram shows how RC oscillator is connected with PIC16F84. With value of resistor R being
below 2.2k, oscillator can become unstable, or it can even stop the oscillation. With very high value of
R (ex.1M) oscillator becomes very sensitive to noise and humidity. It is recommended that value of
resistor R should be between 3 and 100k. Even though oscillator will work without an external
capacitor (C=0pF), capacitor above 20pF should still be used for noise and stability. No matter which
oscillator is being used, in order to get a clock that microcontroller works up on, a clock of the
oscillator must be divided by 4. Oscillator clock divided by 4 can also be obtained on
OSC2/CLKOUT pin, and can be used for testing or synchronizing other logical circuits.

Following a supply, oscillator starts oscillating. Oscillation at first has an unstable period and
amplitude, but after some period of time it becomes stabilized.

45

To prevent such inaccurate clock from influencing microcontroller's performance, we need to keep the
microcontroller in reset state during stabilization of oscillator's clock. Diagram above shows a typical
shape of a signal which microcontroller gets from the quartz oscillator.
Reset
Reset is used for putting the microcontroller into a 'known' condition. That practically means that
microcontroller can behave rather inaccurately under certain undesirable conditions. In order to
continue its proper functioning it has to be reset, meaning all registers would be placed in a starting
position. Reset is not only used when microcontroller doesn't behave the way we want it to, but can
also be used when trying out a device as an interrupt in program execution, or to get a microcontroller
ready when loading a program.
In order to prevent from bringing a logical zero
to MCLR pin accidentally (line above it means
that reset is activated by a logical zero), MCLR
has to be connected via resistor to the positive
supply pole. Resistor should be between 5 and
10K. This kind of resistor whose function is to
keep a certain line on a logical one as a
preventive, is called a pull up.

Microcontroller PIC16F84 knows several sources of resets:


a) Reset during power on, POR (Power-On Reset)
b) Reset during regular work by bringing logical zero to MCLR microcontroller's pin.
c) Reset during SLEEP regime
d) Reset at watchdog timer (WDT) overflow
e) Reset during at WDT overflow during SLEEP work regime.
The most important reset sources are a) and b). The first one occurs each time a power supply is
brought to the microcontroller and serves to bring all registers to a starting position initial state.
The second one is a product of purposeful bringing in of a logical zero to MCLR pin during normal
operation of the microcontroller. This second one is often used in program development.
46

During a reset, RAM memory locations are not being reset. They are unknown during a power up and
are not changed at any reset. Unlike these, SFR registers are reset to a starting position initial state.
One of the most important effects of a reset is setting a program counter (PC) to zero (0000h) , which
enables

the

program

to

start

executing

from

the

first

written

instruction.

Reset at supply voltage drop below the permissible (Brown-out Reset). Impulse for resetting during
voltage voltage-up is generated by microcontroller itself when it detects an increase in supply Vdd (in
a range from 1.2V to 1.8V). That impulse lasts 72ms which is enough time for an oscillator to get
stabilized. These 72ms are provided by an internal PWRT timer which has its own RC oscillator.
Microcontroller is in a reset mode as long as PWRT is active. However, as device is working, problem
arises when supply doesn't drop to zero but falls below the limit that guarantees microcontroller's
proper functioning. This is a likely case in practice, especially in industrial environment where
disturbances and instability of supply are an everyday occurrence. To solve this problem we need to
make sure that microcontroller is in a reset state each time supply falls below the approved limit.
If, according to electrical specification, internal reset circuit of a microcontroller can not satisfy the
needs, special electronic components can be used which are capable of generating the desired reset
signal. Beside this function, they can also function in watching over supply voltage. If voltage drops
below specified level, a logical zero would appear on MCLR pin which holds the microcontroller in
reset state until voltage is not within limits that guarantee accurate performance.
Memory organization
PIC16F84 has two separate memory blocks, one for data and the other for program. EEPROM
memory with GPR and SFR registers in RAM memory make up the data block, while FLASH
memory makes up the program block.
SFR registers
Registers which take up first 12 locations in banks 0 and 1 are registers of specialized function
assigned with certain blocks of the microcontroller. These are called Special Function Registers.

Introduction:
The PIC16F72 CMOS FLASH-based 8-bit microcontroller is upward compatible
with PIC16C72/72A and PIC16F872devices. It features 200 ns instruction execution,
47

self programming, an ICD, 2 Comparators, 5 channels of 8-bit Analog-to-Digital


(A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port that can
be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave
Port.
High-Performance RISC CPU
High performance RISC CPU
Only 35 single word instructions to learn
All single cycle instructions except for program branches which are two-cycle
Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle
2K x 14 words of Program Memory
128 x 8 bytes of Data Memory (RAM)
Pin out compatible to the PIC16C72/72A and PIC16F872
Interrupt capability
Eight level deep hardware stack
Direct, Indirect and Relative Addressing modes

Peripheral Features
Timer0: 8-bit timer/counter with 8-bit prescaler
Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP via
external crystal/clock
Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
Capture, Compare, PWM(CCP) module
48

- Capture is 16-bit, max resolution is 12.5 ns


- Compare is 16-bit, max resolution is 200 ns
- PWM max resolution is 10-bit
8-bit, 5-channel Analog-to-Digital converter
Synchronous Serial Port (SSP) with SPI (Master mode) and I2C (Slave)
Heat sink/Source Current: 25 mA
Brown-out detection circuitry for Brown-out Reset (BOR)

CMOS Technology:
Low power, high speed CMOS FLASH technology
Fully static design
Wide operating voltage range: 2.0V to 5.5V
Industrial temperature range
Low power consumption:
- < 0.6 mA typical @ 3V, 4 MHz
- 20 A typical @ 3V, 32 kHz

- < 1 A typical standby current


Following are the major blocks of PIC Microcontroller.
Program

memory

(FLASH)

is

used

for

storing

written

program.

Since memory made in FLASH technology can be programmed and cleared more than
once,

it

makes

this

microcontroller

suitable

for

device

development.

EEPROM - data memory that needs to be saved when there is no supply.


49

It is usually used for storing important data that must not be lost if power supply
suddenly stops. For instance, one such data is an assigned temperature in temperature
regulators. If during a loss of power supply this data was lost, we would have to make
the adjustment once again upon return of supply. Thus our device looses on selfreliance.
RAM- Data memory used by a program during its execution
In RAM are stored all inter-results or temporary data during run-time.
PORTS are physical connections between the microcontroller and the outside world.
PIC16F72 has 22 I/O.

FREE-RUN TIMER is an 8-bit register inside a microcontroller that works


independently of the program. On every fourth clock of the oscillator it increments its
value until it reaches the maximum (255), and then it starts counting over again from
zero. As we know the exact timing between each two increments of the timer contents,
timer can be used for measuring time which is very useful with some devices.
Crystal oscillator:
The crystal oscillator speed that can be connected to the PIC microcontroller
range from DC to 20Mhz. Using the CCS C compiler normally 20Mhz oscillator will
be used and the price is very cheap. The 20 MHz crystal oscillator should be connected
with about 22pF capacitor. Please refer to my circuit schematic.
There are 5 input/output ports on PIC microcontroller namely port A, port B, port
C, port D and port E. Each port has different function. Most of them can be used as I/O
port.
50

Clock / instruction cycle


Clock is microcontroller's main starter, and is obtained from an external component
called an "oscillator". If we want to compare a microcontroller with a time clock, our
"clock" would then be a ticking sound we hear from the time clock. In that case,
oscillator could be compared to a spring that is wound so time clock can run. Also,
force used to wind the time clock can be compared to an electrical supply.
Clock from the oscillator enters a microcontroller via OSC1 pin where internal circuit
of a microcontroller divides the clock into four even clocks Q1, Q2, Q3, and Q4 which
do not overlap. These four clocks make up one instruction cycle (also called machine
cycle) during which one instruction is executed.
Execution of instruction starts by calling an instruction that is next in string. Instruction
is called from program memory on every Q1 and is written in instruction register on
Q4. Decoding and execution of instruction are done between the next Q1 and Q4
cycles. On the following diagram we can see the relationship between instruction cycle
and clock of the oscillator (OSC1) as well as that of internal clocks Q1-Q4. Program
counter (PC) holds information about the address of the next instruction.

Pipelining
Instruction

cycle

consists of cycles Q1,


Q2, Q3 and Q4. Cycles
of calling and executing
instructions

are

connected in such a way that in order to make a call, one instruction cycle is needed,
51

and one more is needed for decoding and execution. However, due to pipelining, each
instruction is effectively executed in one cycle. If instruction causes a change on
program counter, and PC doesn't point to the following but to some other address
(which can be the case with jumps or with calling subprograms), two cycles are needed
for executing an instruction. This is so because instruction must be processed again, but
this time from the right address. Cycle of calling begins with Q1 clock, by writing into
instruction register (IR). Decoding and executing begins with Q2, Q3 and Q4 clocks.

Pin description
PIC16F72 has a total of 28 pins. It is most frequently found in a DIP28 type of case but
can also be found in SMD case which is smaller from a DIP. DIP is an abbreviation for
Dual In Package. SMD is an abbreviation for Surface Mount Devices suggesting that
holes for pins to go through when mounting aren't necessary in soldering this type of a
component.

52

Pins on PIC16F72 microcontroller have the following meaning:


There are 28 pins on PIC16F72. Most of them can be used as an IO pin. Others are
already for specific functions. These are the pin functions.
1. MCLR to reset the PIC
2. RA0 port A pin 0
3. RA1 port A pin 1
4. RA2 port A pin 2
5. RA3 port A pin 3
6. RA4 port A pin 4
7. RA5 port A pin 5
8. VSS ground
9. OSC1 connect to oscillator
10. OSC2 connect to oscillator
11. RC0 port C pin 0 VDD power supply
53

12. RC1 port C pin 1


13. RC2 port C pin 2
14. RC3 port C pin 3
15. RC4 - port C pin 4
16. RC5 - port C pin 5
17. RC6 - port C pin 6
18. RC7 - port C pin 7
19. VSS - ground
20. VDD power supply
21. RB0 - port B pin 0
22. RB1 - port B pin 1
23. RB2 - port B pin 2
24. RB3 - port B pin 3
25. RB4 - port B pin 4
26. RB5 - port B pin 5
27. RB6 - port B pin 6
28. RB7 - port B pin 7
By utilizing all of this pin so many application can be done such as:
1. LCD connect to Port B pin.
2. LED connect to any pin declared as output.
3. Relay and Motor - connect to any pin declared as output.
4. External EEPROM connect to I2C interface pin RC3 and RC4 (SCL and SDA)
5. LDR, Potentiometer and sensor connect to analogue input pin such as RA0.
6. GSM modem dial up modem connect to RC6 and RC7 the serial communication
interface using RS232 protocol.
For more detail function for each specific pin please refer to the device datasheet from
Microchip.
54

Ports
Term "port" refers to a group of pins on a microcontroller which can be accessed simultaneously, or
on which we can set the desired combination of zeros and ones, or read from them an existing status.
Physically, port is a register inside a microcontroller which is connected by wires to the pins of a
microcontroller. Ports represent physical connection of Central Processing Unit with an outside world.
Microcontroller uses them in order to monitor or control other components or devices. Due to
functionality, some pins have twofold roles like PA4/TOCKI for instance, which is in the same time
the fourth bit of port A and an external input for free-run counter. Selection of one of these two pin
functions is done in one of the configuration registers. An illustration of this is the fifth bit T0CS in
OPTION register. By selecting one of the functions the other one is disabled.
All port pins can be designated as input or output, according to the needs of a device that's being
developed. In order to define a pin as input or output pin, the right combination of zeros and ones
must be written in TRIS register. If the appropriate bit of TRIS register contains logical "1", then that
pin is an input pin, and if the opposite is true, it's an output pin. Every port has its proper TRIS
register. Thus, port A has TRISA, and port B has TRISB. Pin direction can be changed during the
course of work which is particularly fitting for one-line communication where data flow constantly
changes direction. PORTA and PORTB state registers are located in bank 0, while TRISA and TRISB
pin

direction

registers

are

located

in

bank

1.

PORTB and TRISB


PORTB have adjoined 8 pins. The appropriate register for data direction is TRISB. Setting a bit in
TRISB register defines the corresponding port pin as input, and resetting a bit in TRISB register
defines the corresponding port pin as output.

55

Each PORTB pin has a weak internal pull-up resistor (resistor which defines a line to logic one) which
can be activated by resetting the seventh bit RBPU in OPTION register. These 'pull-up' resistors are
automatically being turned off when port pin is configured as an output. When a microcontroller is
started, pull-ups are disabled.
Four pins PORTB, RB7:RB4 can cause an interrupt which occurs when their status changes from
logical one into logical zero and opposite. Only pins configured as input can cause this interrupt to
occur (if any RB7:RB4 pin is configured as an output, an interrupt won't be generated at the change of
status.) This interrupt option along with internal pull-up resistors makes it easier to solve common
problems we find in practice like for instance that of matrix keyboard. If rows on the keyboard are
connected to these pins, each push on a key will then cause an interrupt. A microcontroller will
determine which key is at hand while processing an interrupt It is not recommended to refer to port B
at the same time that interrupt is being processed.
PORTA and TRISA

56

PORTA have 5 adjoining pins. The corresponding register for data direction is TRISA at address 85h.
Like with port B, setting a bit in TRISA register defines also the corresponding port pin as input, and
clearing a bit in TRISA register defines the corresponding port pin as output.
It is important to note that PORTA pin RA4 can be input only. On that pin is also situated an external
input for timer TMR0. Whether RA4 will be a standard input or an input for a counter depends on
T0CS bit (TMR0 Clock Source Select bit). This pin enables the timer TMR0 to increment either from
internal oscillator or via external impulses on RA4/T0CKI pin.
Example shows how pins 0, 1, 2, 3, and 4 are designated input, and pins 5, 6, and 7 outputs. After this,
it is possible to read the pins RA2, RA3, RA4, and to set logical zero or one to pins RA0 and RA1.

Memory organization
PIC16F72 has two separate memory blocks, one for data and the other for program. EEPROM
memory with GPR and SFR registers in RAM memory make up the data block, while FLASH
57

memory

makes

up

the

program

block.

Program memory
Program memory has been carried out in FLASH technology which makes it possible to program a
microcontroller many times before it's installed into a device, and even after its installment if eventual
changes in program or process parameters should occur. The size of program memory is 1024
locations with 14 bits width where locations zero and four are reserved for reset and interrupt vector.
Data memory
Data memory consists of EEPROM and RAM memories. EEPROM memory consists of 256 eight bit
locations whose contents are not lost during loosing of power supply. EEPROM is not directly
addressable, but is accessed indirectly through EEADR and EEDATA registers. As EEPROM memory
usually serves for storing important parameters (for example, of a given temperature in temperature
regulators) , there is a strict procedure for writing in EEPROM which must be followed in order to
avoid accidental writing. RAM memory for data occupies space on a memory map from location
0x0C to 0x4F which comes to 68 locations. Locations of RAM memory are also called GPR registers
which is an abbreviation for General Purpose Registers. GPR registers can be accessed regardless of
which bank is selected at the moment.

Applications
PIC16F72 perfectly fits many uses, from automotive industries and controlling home
appliances to industrial instruments, remote sensors, electrical door locks and safety
devices. It is also ideal for smart cards as well as for battery supplied devices because
of its low consumption.
EEPROM memory makes it easier to apply microcontrollers to devices where
permanent storage of various parameters is needed (codes for transmitters, motor
speed, receiver frequencies, etc.). Low cost, low consumption, easy handling and
flexibility make PIC16F72 applicable even in areas where microcontrollers had not
previously been considered (example: timer functions, interface replacement in larger
systems, coprocessor applications, etc.).
58

In System Programmability of this chip (along with using only two pins in data
transfer) makes possible the flexibility of a product, after assembling and testing have
been completed. This capability can be used to create assembly-line production, to
store calibration data available only after final testing, or it can be used to improve
programs on finished products.
3.3 REGULATED POWER SUPPLY:
3.3.1 Introduction:
Power supply is a supply of electrical power. A device or system that supplies electrical
or other types of energy to an output load or group of loads is called a power supply unit or PSU. The
term is most commonly applied to electrical energy supplies, less often to mechanical ones, and rarely
to others.
A power supply may include a power distribution system as well as primary or
secondary sources of energy such as

Conversion of one form of electrical power to another desired form and voltage, typically
involving converting AC line voltage to a well-regulated lower-voltage DC for electronic devices.
Low voltage, low power DC power supply units are commonly integrated with the devices they
supply, such as computers and household electronics.

Batteries.

Chemical fuel cells and other forms of energy storage systems.

Solar power.

Generators or alternators.
3.3.2 Block Diagram:

59

Fig 3.3.2 Regulated Power Supply


The basic circuit diagram of a regulated power supply (DC O/P) with led connected as
load is shown in fig: 3.3.3.

Fig 3.3.3 Circuit diagram of Regulated Power Supply with Led connection
The components mainly used in above figure are
60

230V AC MAINS

TRANSFORMER

BRIDGE RECTIFIER(DIODES)

CAPACITOR

VOLTAGE REGULATOR(IC 7805)

RESISTOR

LED(LIGHT EMITTING DIODE)


The detailed explanation of each and every component mentioned above is as follows:

Transformation: The process of transforming energy from one device to another is called
transformation. For transforming energy we use transformers.
Transformers:
A transformer is a device that transfers electrical energy from one circuit to another
through inductively coupled conductors without changing its frequency. A varying current in the first
or primary winding creates a varying magnetic flux in the transformer's core, and thus a
varying magnetic field through the secondary winding. This varying magnetic field induces a
varying electromotive force (EMF) or "voltage" in the secondary winding. This effect is called mutual
induction.
If a load is connected to the secondary, an electric current will flow in the secondary
winding and electrical energy will be transferred from the primary circuit through the transformer to
the load. This field is made up from lines of force and has the same shape as a bar magnet.
If the current is increased, the lines of force move outwards from the coil. If the current
is reduced, the lines of force move inwards.
If another coil is placed adjacent to the first coil then, as the field moves out or in, the
moving lines of force will "cut" the turns of the second coil. As it does this, a voltage is induced in the
second coil. With the 50 Hz AC mains supply, this will happen 50 times a second. This is called
MUTUAL INDUCTION and forms the basis of the transformer.

61

The input coil is called the PRIMARY WINDING; the output coil is the
SECONDARY WINDING. Fig: 3.3.4 shows step-down transformer.

Fig 3.3.4: Step-Down Transformer


The voltage induced in the secondary is determined by the TURNS RATIO.

For example, if the secondary has half the primary turns; the secondary will have half
the primary voltage.
Another example is if the primary has 5000 turns and the secondary has 500 turns, then
the turns ratio is 10:1.
If the primary voltage is 240 volts then the secondary voltage will be x 10 smaller = 24
volts. Assuming a perfect transformer, the power provided by the primary must equal the power taken
by a load on the secondary. If a 24-watt lamp is connected across a 24 volt secondary, then the
primary must supply 24 watts.
To aid magnetic coupling between primary and secondary, the coils are wound on a
metal CORE. Since the primary would induce power, called EDDY CURRENTS, into this core, the
core is LAMINATED. This means that it is made up from metal sheets insulated from each other.
Transformers to work at higher frequencies have an iron dust core or no core at all.
Note that the transformer only works on AC, which has a constantly changing current
and moving field. DC has a steady current and therefore a steady field and there would be no
induction.
62

Some transformers have an electrostatic screen between primary and secondary. This is
to prevent some types of interference being fed from the equipment down into the mains supply, or in
the other direction. Transformers are sometimes used for IMPEDANCE MATCHING.
We can use the transformers as step up or step down.
Step Up transformer:
In case of step up transformer, primary windings are every less compared to secondary
winding. Because of having more turns secondary winding accepts more energy, and it releases more
voltage at the output side.
Step down transformer:
Incase of step down transformer, Primary winding induces more flux than the
secondary winding, and secondary winding is having less number of turns because of that it accepts
less number of flux, and releases less amount of voltage.

Battery power supply:


A battery is a type of linear power supply that offers benefits that traditional lineoperated power supplies lack: mobility, portability and reliability. A battery consists of multiple
electrochemical cells connected to provide the voltage desired. Fig: 3.3.5 shows Hi-Watt 9V battery

63

Fig 3.3.5: Hi-Watt 9V Battery


The most commonly used dry-cell battery is the carbon-zinc dry cell battery. Dry-cell
batteries are made by stacking a carbon plate, a layer of electrolyte paste, and a zinc plate alternately
until the desired total voltage is achieved. The most common dry-cell batteries have one of the
following voltages: 1.5, 3, 6, 9, 22.5, 45, and 90. During the discharge of a carbon-zinc battery, the
zinc metal is converted to a zinc salt in the electrolyte, and magnesium dioxide is reduced at the
carbon electrode. These actions establish a voltage of approximately 1.5 V.
The lead-acid storage battery may be used. This battery is rechargeable; it consists of
lead and lead/dioxide electrodes which are immersed in sulfuric acid. When fully charged, this type of
battery has a 2.06-2.14 V potential (A 12 volt car battery uses 6 cells in series). During discharge, the
lead is converted to lead sulfate and the sulfuric acid is converted to water. When the battery is
charging, the lead sulfate is converted back to lead and lead dioxide A nickel-cadmium battery has
become more popular in recent years. This battery cell is completely sealed and rechargeable. The
electrolyte is not involved in the electrode reaction, making the voltage constant over the span of the
batteries long service life. During the charging process, nickel oxide is oxidized to its higher oxidation
state and cadmium oxide is reduced. The nickel-cadmium batteries have many benefits. They can be
stored both charged and uncharged. They have a long service life, high current availabilities, constant
voltage, and the ability to be recharged. Fig: 3.3.6 shows pencil battery of 1.5V.

Fig 3.3.6: Pencil Battery of 1.5V


Rectification:
The process of converting an alternating current to a pulsating direct current is called
as rectification. For rectification purpose we use rectifiers.

64

Rectifiers:
A rectifier is an electrical device that converts alternating current (AC) to direct current
(DC), a process known as rectification. Rectifiers have many uses including as components of power
supplies and as detectors of radio signals. Rectifiers may be made of solid-state diodes, vacuum tube
diodes, mercury arc valves, and other components.
A device that it can perform the opposite function (converting DC to AC) is known as
an inverter.
When only one diode is used to rectify AC (by blocking the negative or positive
portion of the waveform), the difference between the term diode and the term rectifier is merely one
of usage, i.e., the term rectifier describes a diode that is being used to convert AC to DC. Almost all
rectifiers comprise a number of diodes in a specific arrangement for more efficiently converting AC to
DC than is possible with only one diode. Before the development of silicon semiconductor rectifiers,
vacuum tube diodes and copper (I) oxide or selenium rectifier stacks were used.
Bridge full wave rectifier:
The Bridge rectifier circuit is shown in fig: 3.3.7, which converts an ac voltage to dc
voltage using both half cycles of the input ac voltage. The Bridge rectifier circuit is shown in the
figure. The circuit has four diodes connected to form a bridge. The ac input voltage is applied to the
diagonally opposite ends of the bridge. The load resistance is connected between the other two ends of
the bridge.
For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas
diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series with the load
resistance RL and hence the load current flows through RL.
For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct
whereas, D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load
resistance RL and hence the current flows through RL in the same direction as in the previous half
cycle. Thus a bi-directional wave is converted into a unidirectional wave.
Input

Output
65

Fig 3.3.7: Bridge rectifier: a full-wave rectifier using 4 diodes


DB107:
Now -a -days Bridge rectifier is available in IC with a number of DB107. In our project
we are using an IC in place of bridge rectifier. The picture of DB 107 is shown in fig: 3.3.8.
Features:

Good for automation insertion

Surge overload rating - 30 amperes peak

Ideal for printed circuit board

Reliable low cost construction utilizing molded

Glass passivated device

Polarity symbols molded on body

Mounting position: Any

Weight: 1.0 gram

66

Fig 3.3.8: DB107


Filtration:
The process of converting a pulsating direct current to a pure direct current using filters
is called as filtration.
Filters:
Electronic filters are electronic circuits, which perform signal-processing functions,
specifically to remove unwanted frequency components from the signal, to enhance wanted ones.
Introduction to Capacitors:
The Capacitor or sometimes referred to as a Condenser is a passive device, and one
which stores energy in the form of an electrostatic field which produces a potential (static voltage)
across its plates. In its basic form a capacitor consists of two parallel conductive plates that are not
connected but are electrically separated either by air or by an insulating material called the Dielectric.
When a voltage is applied to these plates, a current flows charging up the plates with electrons giving
one plate a positive charge and the other plate an equal and opposite negative charge this flow of
electrons to the plates is known as the Charging Current and continues to flow until the voltage across
the plates (and hence the capacitor) is equal to the applied voltage Vcc. At this point the capacitor is
said to be fully charged and this is illustrated below. The construction of capacitor and an electrolytic
capacitor are shown in figures 3.3.9 and 3.3.10 respectively.

67

Fig 3.3.9:Construction Of a Capacitor

Fig 3.3.10:Electrolytic Capaticor

Units of Capacitance:
Microfarad (F) 1F = 1/1,000,000 = 0.000001 = 10-6 F
Nanofarad (nF) 1nF = 1/1,000,000,000 = 0.000000001 = 10-9 F
Pico farad (pF) 1pF = 1/1,000,000,000,000 = 0.000000000001 = 10-12 F
Operation of Capacitor:
Think of water flowing through a pipe. If we imagine a capacitor as being a storage
tank with an inlet and an outlet pipe, it is possible to show approximately how an electronic capacitor
works.
First, let's consider the case of a "coupling capacitor" where the capacitor is used to
connect a signal from one part of a circuit to another but without allowing any direct current to flow.

If the current flow is alternating between zero and a maximum,


our "storage tank" capacitor will allow the current waves to pass
through.
68

However, if there is a steady current, only the initial short burst


will flow until the "floating ball valve" closes and stops further
flow.

So a coupling capacitor allows "alternating current" to pass through because the ball
valve doesn't get a chance to close as the waves go up and down. However, a steady current quickly
fills the tank so that all flow stops.
A capacitor will pass alternating current but (apart from an initial surge) it will not pass
d.c.

Where a capacitor is used to decouple a circuit, the effect is to


"smooth out ripples". Any ripples, waves or pulses of current are
passed to ground while d.c. Flows smoothly.

Regulation:
The process of converting a varying voltage to a constant regulated voltage is called as
regulation. For the process of regulation we use voltage regulators.

Voltage Regulator:
A voltage regulator (also called a regulator) with only three terminals appears to be a
simple device, but it is in fact a very complex integrated circuit. It converts a varying input voltage
into a constant regulated output voltage. Voltage Regulators are available in a variety of outputs like
69

5V, 6V, 9V, 12V and 15V. The LM78XX series of voltage regulators are designed for positive input.
For applications requiring negative input, the LM79XX series is used. Using a pair of voltagedivider resistors can increase the output voltage of a regulator circuit.
It is not possible to obtain a voltage lower than the stated rating. You cannot use a 12V
regulator to make a 5V power supply. Voltage regulators are very robust. These can withstand overcurrent draw due to short circuits and also over-heating. In both cases, the regulator will cut off before
any damage occurs. The only way to destroy a regulator is to apply reverse voltage to its input.
Reverse polarity destroys the regulator almost instantly. Fig: 3.3.11 shows voltage regulator.

Fig 3.3.11: Voltage Regulator


Resistors:
A resistor is a two-terminal electronic component that produces a voltage across its terminals
that is proportional to the electric current passing through it in accordance with Ohm's law:
V = IR

Resistors are elements of electrical networks and electronic circuits and are ubiquitous in most
electronic equipment. Practical resistors can be made of various compounds and films, as well as
resistance wire (wire made of a high-resistivity alloy, such as nickel/chrome).
The primary characteristics of a resistor are the resistance, the tolerance, maximum working
voltage and the power rating. Other characteristics include temperature coefficient, noise, and
inductance. Less well-known is critical resistance, the value below which power dissipation limits the
maximum permitted current flow, and above which the limit is applied voltage. Critical resistance is
determined by the design, materials and dimensions of the resistor.
70

Resistors can be made to control the flow of current, to work as Voltage dividers, to
dissipate power and it can shape electrical waves when used in combination of other components.
Basic unit is ohms.
Theory of operation:
Ohm's law:
The behavior of an ideal resistor is dictated by the relationship specified in Ohm's law:
V = IR
Ohm's law states that the voltage (V) across a resistor is proportional to the current (I)
through it where the constant of proportionality is the resistance (R).
Power dissipation:
The power dissipated by a resistor (or the equivalent resistance of a resistor network) is
calculated using the following:

Fig 3.3.12: Resistor

Fig 3.3.13: Color Bands In Resistor

3.4. LED:
71

A light-emitting diode (LED) is a semiconductor light source. LEDs are used as


indicator lamps in many devices, and are increasingly used for lighting. Introduced as a practical
electronic component in 1962, early LEDs emitted low-intensity red light, but modern versions are
available across the visible, ultraviolet and infrared wavelengths, with very high brightness. The
internal structure and parts of a led are shown in figures 3.4.1 and 3.4.2 respectively.

Fig 3.4.1: Inside a LED

Fig 3.4.2: Parts of a LED

Working:
The structure of the LED light is completely different than that of the light bulb.
Amazingly, the LED has a simple and strong structure. The light-emitting semiconductor material is
what determines the LED's color. The LED is based on the semiconductor diode.
When a diode is forward biased (switched on), electrons are able to recombine with
holes within the device, releasing energy in the form of photons. This effect is called
electroluminescence and the color of the light (corresponding to the energy of the photon) is
determined by the energy gap of the semiconductor. An LED is usually small in area (less than
1 mm2), and integrated optical components are used to shape its radiation pattern and assist in
reflection. LEDs present many advantages over incandescent light sources including lower energy
consumption, longer lifetime, improved robustness, smaller size, faster switching, and greater
durability and reliability. However, they are relatively expensive and require more precise current and
72

heat management than traditional light sources. Current LED products for general lighting are more
expensive to buy than fluorescent lamp sources of comparable output. They also enjoy use in
applications as diverse as replacements for traditional light sources in automotive lighting
(particularly indicators) and in traffic signals. The compact size of LEDs has allowed new text and
video displays and sensors to be developed, while their high switching rates are useful in advanced
communications technology. The electrical symbol and polarities of led are shown in fig: 3.4.3.

Fig 3.4.3: Electrical Symbol & Polarities of LED


LED lights have a variety of advantages over other light sources:

High-levels of brightness and intensity

High-efficiency

Low-voltage and current requirements

Low radiated heat

High reliability (resistant to shock and vibration)

No UV Rays

Long source life

Can be easily controlled and programmed

73

Applications of LED fall into three major categories:

Visual signal application where the light goes more or less directly from the LED to the human
eye, to convey a message or meaning.

Illumination where LED light is reflected from object to give visual response of these objects.

Generate light for measuring and interacting with processes that do not involve the human
visual system.

3.5 RS 232 &MAX 232


3.5.1 Serial Communication:
Computers transfer data in two ways: parallel and serial. In parallel data transfers,
often 8 or more lines are used to transfer data to a device that is only a few feet away. Although a lot
of data can be transferred in a short amount of time by using many wires in parallel, the distance
cannot be great. To transfer to a device located many meters away, the serial method is best suitable.
The fact that serial communication uses a single data line instead of the 8-bit data line
instead of the 8-bit data line of parallel communication not only makes it cheaper but also enables two
computers located in two different cities to communicate over the telephone.
Serial data communication uses two methods, asynchronous and synchronous. The synchronous
method transfers a block of data at a time, while the asynchronous method transfers a single byte at a
time. With synchronous communications, the two devices initially synchronize themselves to each
other, and then continually send characters to stay in sync. Even when data is not really being sent, a
constant flow of bits allows each device to know where the other is at any given time. That is, each
character that is sent is either actual data or an idle character. Synchronous communications allows
faster data transfer rates than asynchronous methods, because additional bits to mark the beginning
and end of each data byte are not required.
The serial ports on IBM-style PCs are asynchronous devices and therefore only support
asynchronous serial communications.
Asynchronous means "no synchronization", and thus does not require sending and
receiving idle characters. However, the beginning and end of each byte of data must be identified by
start and stop bits. The start bit indicates when the data byte is about to begin and the stop bit signals
when it ends. The requirement to send these additional two bits causes asynchronous communication
74

to be slightly slower than synchronous however it has the advantage that the processor does not have
to deal with the additional idle characters.
There are special IC chips made by many manufacturers for serial data
communications. These chips are commonly referred to as UART (universal asynchronous receivertransmitter) and USART (universal synchronous-asynchronous receiver-transmitter). The 8051 has a
built-in UART.
The main requirements for serial communication are:
Microcontroller
PC
RS 232 cable
MAX 232 IC
Hyper Terminal

3.5.2 RS 232 cable:

RS232 means recommended standard, it is a cable in which serial


communications can be done. Information being transferred between data processing equipment
and peripherals is in the form of digital data which is transferred in either a serial or parallel mode.
Parallel communications are used mainly for connections between test instruments or computers
and printers, while serial is often used between computer and other peripherals.
Serial transmission involves the sending of data one bit at a time, over single
communications line. In contrast, parallel communications require at least as many lines as there
are bits in a word being transmitted (for an 8-bit word, a minimum of 8 lines are needed) serial
transmission is beneficial for long distance communications, where as parallel is designed for
short distance or when very high transmission rates are required.
The RS-232 interface is the Electronic Industries Association (EIA) standard
for the interchange of serial binary data between two devices. It was initially developed by the
EIA to standardize the connection of computers with telephone line modems. The standard allows
75

as many as 20 signals to be defined, but gives complete freedom to the user. Three wires are
sufficient: send data, receive data, and signal ground. The remaining lines can be hardwired on or
off permanently. The signal transmission is bipolar, requiring two voltages, from 5 to 25 volts, of
opposite polarity.

Fig: 3.5.3 RS 232 cable

3.5.4 RS-232 Specifications:


TRANSMITTED SIGNAL VOLTAGE LEVELS:
Binary 0: +5 to +15 Vdc
(Called a space or on)
Binary 1: -5 to -15 Vdc
76

(Called a mark or off)


RECEIVED SIGNAL VOLTAGE LEVELS:
Binary 0: +3 to +13 Vdc
Binary 1: -3 to -13 Vdc
DATA FORMAT:
Start bit: Binary 0
Data: 5, 6, 7 or 8 bits
Parity: Odd, even, mark or space (not used with 8-bit data), Stop bit: Binary 1, one or two bits

3.5.5 DB9 pin connector:

Serial Ports come in two "sizes", There are the D-Type 25 pin connector and the D-Type 9
Pin connector both of which are male on the back of the PC, thus you will require a female connector
on your device. Below is a table of pin connections for the 9 pin and 25 pin D-Type connectors.

77

Fig 3.5.6:DB9 pin connector


The pins of above DB9 are:
1. Data carrier detect
2. Received data
3. Transmitted data
4. Data terminal ready
5. Signal ground
6. Data set ready
78

7. Request to send
8. Clear to send
9. Ring indictor
Serial Pinouts (D9 Connectors) D-Type-9 Pin No. Abbreviation Full Name:
Pin 3 TD Transmit Data
Pin 2 RD Receive Data
Pin 7 RTS Request to Send
Pin 8 CTS Clear To Send
Pin 6 DSR Data Set Ready
Pin 5 SG Signal Ground
Pin 1 CD Carrier Detect
Pin 4 DTR Data Terminal Ready
Pin 9 RI Ring Indicators

MAX232 integrated circuit:


79

A MAX232 IC has a set of four external capacitors of the specification 1 microfarad .This IC is
basically transceiver IC alike to assart chip used in data communicating devices like modem, drivers
and other electronic system devices .The capacitance can have a deviation of up to 0.1 microfarad.
The Maxim MAX232 communications interface IC is used to convert +5 volt TTL or CMOS levels to
RS232 levels. The dual level 10 volt signals are derived from the +5 volt power supply via charge
pump circuitry. This feature eliminates the +/- 12V rails that used to be required with older technology
devices such as the old industry standard 1488 and 1489 chips.
The MAX232 from Maxim was the first IC which in one package contains the necessary drivers (two)
and receivers (also two), to adapt the RS-232 signal voltage levels to TTL logic. It became popular,
because it just needs one voltage (+5V) and generates the necessary RS-232 voltage levels (approx.
-10V and +10V) internally. This greatly simplified the design of circuitry. Circuitry designers no
longer need to design and build a power supply with three voltages (e.g. -12V, +5V, and +12V), but
could just provide one +5V power supply, e.g. with the help of a simple 78x05 voltage converter.
The MAX232 has a successor, the MAX232A. The ICs are almost identical, however, the MAX232A
is much more often used (and easier to get) than the original MAX232, and the MAX232A only needs
external capacitors 1/10th the capacity of what the original MAX232 needs.
It should be noted that the MAX232 (A) is just a driver/receiver. It does not generate the necessary
RS-232 sequence of marks and spaces with the right timing, it does not decode the RS-232 signal, it
does not provide a serial/parallel conversion. All it does is to convert signal voltage levels. Generating
serial data with the right timing and decoding serial data has to be done by additional circuitry, e.g. by
a 16550 UART or one of these small micro controllers (e.g. Atmel AVR, Microchip PIC) getting more
and more popular.
The MAX232 and MAX232A were once rather expensive ICs, but today they are cheap. It has also
helped that many companies now produce clones (ie. Sipex). These clones sometimes need different
external circuitry, e.g. the capacities of the external capacitors vary. It is recommended to check the
data sheet of the particular manufacturer of an IC instead of relying on Maxim's original data sheet.
The original manufacturer (and now some clone manufacturers, too) offers a large series of similar
ICs, with different numbers of receivers and drivers, voltages, built-in or external capacitors, etc. E.g.
The MAX232 and MAX232A need external capacitors for the internal voltage pump, while the
80

MAX233 has these capacitors built-in. The MAX233 is also between three and ten times more
expensive in electronic shops than the MAX232A because of its internal capacitors. It is also more
difficult to get the MAX233 than the garden variety MAX232A.
A similar IC, the MAX3232 is nowadays available for low-power 3V logic.
The MAX232 (A) has two receivers (converts from RS-232 to TTL voltage levels) and two drivers
(converts from TTL logic to RS-232 voltage levels). This means only two of the RS-232 signals can
be converted in each direction. The old MC1488/1498 combo provided four drivers and receivers.
Typically a pair of a driver/receiver of the MAX232 is used for

TX and RX and the second one for

CTS and RTS.

There are not enough drivers/receivers in the MAX232 to also connect the DTR, DSR, and DCD
signals. Usually these signals can be omitted when e.g. communicating with a PC's serial interface. If
the DTE really requires these signals either a second MAX232 is needed, or some other IC from the
MAX232 family can be used (if it can be found in consumer electronic shops at all).

81

Description information:
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator to
supply TIA/EIA-232-F voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232F inputs to 5-V TTL/CMOS levels. These receivers have a typical threshold of 1.3 V, a typical
hysteresis of 0.5 V, and can accept 30-V inputs. Each driver converts TTL/CMOS input levels into
TIA/EIA-232-F levels. The driver, receiver, and
Voltage-generator functions are available as cells in the Texas Instruments
Serial RS-232 (V.24) communication works with voltages (between -15V ... -3V are used to
transmit a binary '1' and +3V ... +15V to transmit a binary '0') which are not compatible with today's
computer logic voltages. On the other hand, classic TTL computer logic operates between 0V ... +5V
(roughly 0V ... +0.8V referred to as low for binary '0', +2V ... +5V for high binary '1' ). Modern lowpower logic operates in the range of 0V ... +3.3V or even lower. So, the maximum RS-232 signal
levels are far too high for today's computer logic electronics, and the negative RS-232 voltage can't be
grokked at all by the computer logic. Therefore, to receive serial data from an RS-232 interface the
voltage has to be reduced, and the 0 and 1 voltage levels inverted. In the other direction (sending data
82

from some logic over RS-232) the low logic voltage has to be "bumped up", and a negative voltage
has to be generated, too.
RS-232

TTL

Logic

-----------------------------------------------15V ... -3V <-> +2V ... +5V <-> 1


+3V ... +15V <-> 0V ... +0.8V <-> 0
All this can be done with conventional analog electronics, e.g. a particular power supply and a couple
of transistors or the once popular 1488 (transmitter) and 1489 (receiver) ICs. However, since more
than a decade it has become standard in amateur electronics to do the necessary signal level
conversion with an integrated circuit (IC) from the MAX232 family (typically a MAX232A or some
clone). In fact, it is hard to find some RS-232 circuitry in amateur electronics without a MAX232A or
some clone.
Specifications:

1. Supply voltage: +5V dc.


2. Supply current: 10 MA max.
3. Tx o/p volts swing: +/-9 V typ
4. RS232 i/p range: +/-30V max
5. Operates upto 120 kbit/s
6. Two drivers and two receivers
7. low supply current :8 mA
Applications:
TIA/EIA-232-F, Battery-Powered Systems, Terminals, Modems, and Computers
The main requirements for serial communication are:
Microcontroller
PC
83

RS 232 cable
MAX 232 IC
Hyper Terminal

Fig 3.5.7: schematic diagram of pc interfacing with microcontroller

3.6 Zigbee

technology

Introduction:
When we hold the TV remote and wish to use it we have to necessarily point our control at
the device. This one-way, line-of-sight, short-range communication uses infrared (IR) sensors to
enable communication and control and it is possible to operate the TV remotely only with its control
unit.
84

Add other home theatre modules, an air- conditioner and remotely enabled fans and lights to
our room, and we become a juggler who has to handle not only these remotes, but also more numbers
that will accompany other home appliances we are likely to use.
Some remotes do serve to control more than one device after memorizing' access codes,
but this interoperability is restricted to LOS, that too only for a set of related equipment, like the
different units of a home entertainment system
Now picture a home with entertainment units, security systems including fire alarm,
smoke detector and burglar alarm, air-conditioners and kitchen appliances all within whispering
distance from each other and imagine a single unit that talks with all the devices, no longer depending
on line-of-sight, and traffic no longer being one-way.
This means that the devices and the control unit would all need a common standard to
enable intelligible communication. ZigBee is such a standard for embedded application software and
has been ratified in late 2004 under IEEE 802.15.4 Wireless Networking Standards.
ZigBee is an established set of specifications for wireless personal area networking
(WPAN), i.e., digital radio connections between computers and related devices. This kind of network
eliminates use of physical data buses like USB and Ethernet cables. The devices could include
telephones, hand-held digital assistants, sensors and controls located within a few meters of each
other.
ZigBee is one of the global standards of communication protocol formulated by the relevant
task force under the IEEE 802.15 working group. The fourth in the series, WPAN Low Rate/ZigBee is
the newest and provides specifications for devices that have low data rates, consume very low power
and are thus characterized by long battery life. Other standards like Blue tooth and IrDA address high
data rate applications such as voice, video and LAN communications.
The ZigBee Alliance has been set up as an association of companies working together to
enable reliable, cost-effective, low-power, wirelessly networked, monitoring and control products
based on an open global standard.
Once a manufacturer enrolls in this Alliance for a fee, he can have access to the standard
and implement it in his products in the form of ZigBee chipsets that would be built into the end
85

devices. Philips, Motorola, Intel, HP are all members of the Alliance. The goal is to provide the
consumer with ultimate flexibility, mobility, and ease of use by building wireless intelligence and
capabilities into every day devices.
ZigBee technology will be embedded in a wide range of products and applications across
consumer, commercial, industrial and government markets worldwide. For the first time, companies
will have a standards-based wireless platform optimized for the unique needs of remote monitoring
and control applications, including simplicity, reliability, low-cost and low-power.
The target networks encompass a wide range of devices with low data rates in the Industrial,
Scientific and Medical (ISM) radio bands, with building-automation controls like intruder/fire alarms,
thermostats and remote (wireless) switches, video/audio remote controls likely to be the most popular
applications. So far sensor and control devices have been marketed as proprietary items for want of a
standard. With acceptance and implementation of ZigBee, interoperability will be enabled in multipurpose, self-organizing mesh networks

Architecture:
Though WPAN implies a reach of only a few meters, 30 feet in the case of ZigBee, the network
will have several layers, so designed as to enable interpersonal communication within the network,
connection to a network of higher level and ultimately an uplink to the Web.
The ZigBee Standard has evolved standardized sets of solutions, called layers'. These layers facilitate
the features that make ZigBee very attractive: low cost, easy implementation, reliable data transfer,
short-range operations,
Very low power consumption and adequate security features.

1. Network and Application Support layer:

86

The network layer permits growth of network sans high power transmitters. This layer
can handle huge numbers of nodes. This level in the ZigBee architecture includes the ZigBee Device
Object (ZDO), user-defined application profile(s) and the Application Support (APS) sub-layer.
The APS sub-layer's responsibilities include maintenance of tables that enable matching
between two devices and communication among them, and also discovery, the aspect that identifies
other devices that operate in the operating space of any device.
The responsibility of determining the nature of the device (Coordinator / FFD or RFD)
in the network, commencing and replying to binding requests and ensuring a secure relationship
between devices rests with the ZDO (Zigbee Define Object). The user-defined application refers to the
end device that conforms to the ZigBee Standard.

2. Physical (PHY) layer:


The IEEE802.15.4 PHY physical layer accommodates high levels of integration by using
direct sequence to permit simplicity in the analog circuitry and enable cheaper implementations.
3. Media access control (MAC) layer:
The IEEE802.15.4 MAC media access control layer permits use of several topologies
without introducing complexity and is meant to work with large numbers of devices.

87

Figure 1: IEEE 802.15.4 / ZigBee Stack Architecture

Device types:
There are three different ZigBee device types that operate on these layers in any selforganizing application network.
These devices have 64-bit IEEE addresses, with option to enable shorter addresses to
reduce packet size, and work in either of two addressing modes star and peer-to-peer.

1. The ZigBee coordinator node:


There is one, and only one, ZigBee coordinator in each network to act as the router to other
networks, and can be likened to the root of a (network) tree. It is designed to store information about
the network.
2. The full function device FFD:
The FFD is an intermediary router transmitting data from other devices. It needs lesser memory
than the ZigBee coordinator node, and entails lesser manufacturing costs. It can operate in all
topologies and can act as a coordinator.
88

3. The reduced function device RFD:


This device is just capable of talking in the network; it cannot relay data from other devices.
Requiring even less memory, (no flash, very little ROM and RAM), an RFD will thus be cheaper than
an FFD. This device talks only to a network coordinator and can be implemented very simply in star
topology.
ZigBee Characteristics:
The focus of network applications under the IEEE 802.15.4 / ZigBee standard include the
features of low power consumption, needed for only two major modes (Tx/Rx or Sleep), high density
of nodes per network, low costs and simple implementation.

These features are enabled by the following characteristics:


2.4GHz and 868/915 MHz dual PHY modes
This represents three license-free bands: 2.4-2.4835 GHz, 868-870 MHz and 902-928 MHz. The
number of channels allotted to each frequency band is fixed at sixteen (numbered 11-26), one
(numbered 0) and ten (numbered 1-10) respectively. The higher frequency band is applicable
worldwide, and the lower band in the areas of North America, Europe, Australia and New Zealand.
Low power consumption, with battery life ranging from months to years. Considering the number of
devices with remotes in use at present, it is easy to see that more numbers of batteries need to be
provisioned every so often, entailing regular (as well as timely), recurring expenditure. In the ZigBee
standard, longer battery life is achievable by either of two means: continuous network connection and
slow but sure battery drain, or intermittent connection and even slower battery drain.
Maximum data rates allowed for each of these frequency bands are fixed as 250 kbps @2.4 GHz, 40
kbps @ 915 MHz, and 20 kbps @868 MHz.
High throughput and low latency for low duty-cycle applications (<0.1%)
89

Channel access using Carrier Sense Multiple Access with Collision Avoidance (CSMA - CA)
Addressing space of up to 64 bit IEEE address devices, 65,535 networks
50m typical range
Fully reliable hand-shacked data transfer protocol.
Different topologies as illustrated below: star, peer-to-peer, mesh

Figure 2: ZigBee Topologies

Traffic Types:
ZigBee/IEEE 802.15.4 addresses three typical traffic types. IEEE 802.15.4 MAC can
accommodate all the types.

90

1. Data is periodic: The application dictates the rate, and the sensor activates, checks for data and
deactivates.
2. Data is intermittent: The application, or other stimulus, determines the rate, as in the case of say
smoke detectors. The device needs to connect to the network only when communication is
necessitated. This type enables optimum saving on energy.
3. Data is repetitive, and the rate is fixed a priori. Depending on allotted time slots, called GTS
(guaranteed time slot), devices operate for fixed durations.
ZigBee employs either of two modes, beacon or non-beacon to enable the to-and-fro data
traffic. Beacon mode is used when the coordinator runs on batteries and thus offers maximum power
savings, whereas the non-beacon mode finds favor when the coordinator is mains-powered.
In the beacon mode, a device watches out for the coordinator's beacon that gets
transmitted at periodically, locks on and looks for messages addressed to it. If message transmission is
complete, the coordinator dictates a schedule for the next beacon so that the device goes to sleep'; in
fact, the coordinator itself switches to sleep mode.
While using the beacon mode, all the devices in a mesh network know when to communicate
with each other. In this mode, necessarily, the timing circuits have to be quite accurate, or wake up
sooner to be sure not to miss the beacon. This in turn means an increase in power consumption by the
coordinator's receiver, entailing an optimal increase in costs.

Figure 1: Beacon Network Communication


91

The non-beacon mode will be included in a system where devices are asleep' nearly always,
as in smoke detectors and burglar alarms. The devices wake up and confirm their continued presence
in the network at random intervals.
On detection of activity, the sensors spring to attention', as it were, and transmit to the everwaiting coordinator's receiver (since it is mains-powered). However, there is the remotest of chances
that a sensor finds the channel busy, in which case the receiver unfortunately would miss a call'.

Figure 2: Non-Beacon Network Communication

Network Model:
The functions of the Coordinator, which usually remains in the receptive mode, encompass
network set-up, beacon transmission, node management, storage of node information and message
routing between nodes.
The network node, however, is meant to save energy (and so sleeps' for long periods) and its
functions include searching for network availability, data transfer, checks for pending data and queries
for data from the coordinator.

92

Figure 1: ZigBee Network Model

For the sake of simplicity without jeopardizing robustness, this particular IEEE standard
defines a quartet frame structure and a super-frame structure used optionally only by the coordinator.
The four frame structures are

Beacon frame for transmission of beacons

Data frame for all data transfers

Acknowledgement frame for successful frame receipt confirmations

MAC command frame

93

These frame structures and the coordinator's super-frame structure play critical roles in
security of data and integrity in transmission.
All protocol layers contribute headers and footers to the frame structure, such that the total
overheads for each data packet range are from 15 octets (for short addresses) to 31 octets (for 64-bit
addresses).
The coordinator lays down the format for the super-frame for sending beacons after every 15.38 ms
or/and multiples thereof, up to 252s.
This interval is determined a priori and the coordinator thus enables sixteen time
slots of identical width between beacons so that channel access is contention-less. Within each time
slot, access is contention-based. Nonetheless, the coordinator provides as many as seven GTS
(guaranteed time slots) for every beacon interval to ensure better quality.
Technology Comparisons:
The Why ZigBee question has always had an implied, but never quite worded follower
phrase when there is Blue tooth. A comparative study of the two can be found in ZigBee:
'Wireless Control That Simply Works.
The bandwidth of Blue tooth is 1 Mbps; ZigBee's is one-fourth of this value. The strength of
Blue tooth lies in its ability to allow interoperability and replacement of cables, ZigBee's, of course, is
low costs and long battery life.
In terms of protocol stack size, ZigBee's 32 KB is about one-third of the stack size necessary
in other wireless technologies (for limited capability end devices, the stack size is as low as 4 KB).
Most important in any meaningful comparison are the diverse application areas of all the
different wireless technologies. Blue tooth is meant for such target areas as wireless USB's, handsets
and headsets, whereas ZigBee is meant to cater to the sensors and remote controls market and other
battery operated products.
In a gist, it may be said that they are neither complementary standards nor competitors,
but just essential standards for different targeted applications. The earlier Blue tooth targets interfaces
between PDA and other device (mobile phone / printer etc) and cordless audio applications.
94

The IEEE 802.15.4based ZigBee is designed for remote controls and sensors, which are very many
in number, but need only small data packets and, mainly, extremely low power consumption for (long)
life. Therefore they are naturally different in their approach to their respective application arenas.
ZigBee Applications:
The ZigBee Alliance targets applications "across consumer, commercial, industrial and
government markets worldwide".
Unwired applications are highly sought after in many networks that are characterized by numerous
nodes consuming minimum power and enjoying long battery lives.
ZigBee technology is designed to best suit these applications, for the reason that it enables
reduced costs of development, very fast market adoption, and rapid ROI.
Airbee Wireless Inc has tied up with Radio crafts AS to deliver "out-of-the-box" ZigBeeready solutions, the former supplying the software and the latter making the module platforms. With
even light controls and thermostat producers joining the ZigBee Alliance, the list is growing healthily
and includes big OEM names like HP, Philips, Motorola and Intel.
With ZigBee designed to enable two-way communications, not only will the consumer be able to
monitor and keep track of domestic utilities usage, but also feed it to a computer system for data
analysis.
A recent analyst report issued by West Technology Research Solutions estimates that by the
year 2008, "annual shipments for ZigBee chipsets into the home automation segment alone will
exceed 339 million units," and will show up in "light switches, fire and smoke detectors, thermostats,
appliances in the kitchen, video and audio remote controls, landscaping, and security systems."

3.7 METAL DETECTION SENSOR:


Metal detection Sensor SM12
A metal detector is a device which responds to metal that may not be readily apparent.

95

The simplest form of a metal detector consists of an oscillator producing an alternating current that
passes through a coil producing an alternating magnetic field. If a piece of electrically conductive
metal is close to the coil, eddy currents will be induced in the metal, and this produces an alternating
magnetic field of its own. If another coil is used to measure the magnetic field (acting as a
magnetometer), the change in the magnetic field due to the metallic object can be detected
The first industrial metal detectors were developed in the 1960s and were used extensively for mining
and other industrial applications. Uses include de-mining (the detection of land mines), the detection
of weapons such as knives and guns, especially in airport security, geophysical prospecting,
archaeology and treasure hunting. Metal detectors are also used to detect foreign bodies in food, and
in the construction industry to detect steel reinforcing bars in concrete and pipes and wires buried in
walls and floors.
Industrial metal detectors are used in the pharmaceutical, food, beverage, textile, garment, plastics,
chemicals, lumber, and packaging industries.
Contamination of food by metal shards from broken processing machinery during the manufacturing
process is a major safety issue in the food industry. Metal detectors for this purpose are widely used
and integrated into the production line.
Current practice at garment or apparel industry plants is to apply metal detecting after the garments
are completely sewn and before garments are packed to check whether there is any metal
contamination (needle, broken needle, etc.) in the garments. This needs to be done for safety reasons.
Model explanation of Inductance Proximity Switch:
1. Switch category(LM: inductance type CM: Inductance type SM: Hall type
2. Outward appearance code(30:6-36VDC 310:5-24VDC 320:12-60VDC 20:90-250VAC
220:380VAC 40:12-240VDC/24-240AC 50: special voltage)
3. Working voltage(30:6-36VDC 310:5-24VDC 320:12-60VDC 20:90-250VAC 220:380VAC
40:12-240VDC/24-240AC 50: special voltage)
4. Detection distance( 01: 1mm 05:5mm 10:10mm)
5. Output form(N: three-wire DC NPN output P: three-wire DC NPN output L: two-wire DC
PNP output AC two wire output W:AC three wire output NP: NPN+PNP double output)
96

6. Output state(A: Normally open (NO) B: Normally close (NC) C: Normally open +normally
close (NO+NC))
7. Subsidiary functions(T: with aviation connector Y: Water proof, oil proof I: Special
requirement H: High temp resistance r: Ring type)
Specification information:
1. Detection distance range: 10mm
2. Operating voltage : 4.5-24 v
3. Compact volume
4. high precision of repeated location
5. Diversified exterior structures
6. Good performance of anti-interference.
7. Many output forms
8. High on-off frequency.
9. Wide voltage range
10. Dust proof, vibration proof, water proof and oil proof.
11. With short-circuit protection and inverted connecting protection.
12. Long service life

97

Fig: Metal detection sensor


Metal detectors use electromagnetic fields to detect the presence of metallic objects. They
exist in a variety of walk-through, hand-held, and vehicle-mounted models and are used to search
personnel for hidden metallic objects at entrances to airports, public schools, courthouses, and other
guarded spaces; to hunt for landmines, archaeological artifacts, and miscellaneous valuables; and for
the detection of hidden or unwanted metallic objects in industry and construction. Metal detectors
detect metallic objects, but do not image them. An x-ray baggage scanner, for example, is not classed
as a metal detector because it images metallic objects rather than merely detecting their presence.
Metal detectors use electromagnetism in two fundamentally different ways, active and passive.
(1) Active detection methods illuminate some detection spacethe opening of a walk-through portal,
for example, or the space directly in front of a hand-held unitwith a time-varying electromagnetic
field. Energy reflected from or passing through the detection space is affected by the presence of
conductive material in that space; the detector detects metal by measuring these effects. (2) Passive
detection methods do not illuminate the detection space, but take advantage of the fact that every
unshielded detection space is already permeated by the Earth's natural magnetic field. Ferromagnetic
objects moving through the detection space cause temporary, but detectable changes in this natural
field. (Ferromagnetic objects are made of metals, such as iron, that are capable of being magnetized;
many metals, such as aluminum, are conducting but not ferromagnetic, and cannot be detected by
passive means.)
Types of Metal detection sensors:
1. Walk-through metal detectors
Walk-through or portal detectors are common in airports, public buildings, and military installations.
Their portals are bracketed with two large coils or loop-type antennae, one a source and the other a
detector. Electromagnetic waves (in this case, low-frequency radio waves) are emitted by the source
coil into the detection space. When the electromagnetic field of the transmitted wave impinges on a
conducting object, it induces transient currents on the surface of the object; these currents, in turn,
radiate electromagnetic waves. These secondary waves are sensed by the detector coil.
2. Hand-carried metal detectors.
98

Metal detectors small enough to be hand-held are often used at security checkpoints to localize metal
objects whose presence has been detected by a walk-through system. Some units are designed to be
carried by a pedestrian scanning for metal objects in the ground (e.g., nails, loose change, landmines).
All such devices operate on variations of the same physical principle as the walk-through metal
detector, that is, they emit time-varying electromagnetic fields and listen for waves coming back from
conducting objects. Some ground-search models further analyze the returned fields to distinguish
various common metals from each other. Hand-carried metal detectors have long been used to search
for landmines; however, modern land mines are often made largely of plastic to avoid this cheap and
obvious counter-measure. New technologies, especially neutron activation analysis and groundpenetrating radar, are being developed to search for nonmetallic landmines.

3. Gradiometer metal detectors.


Gradiometer metal detectors are passive systems that exploit the effect of moving ferromagnetic
objects on the earth's magnetic field. A gradiometer is an instrument that measures a gradientthe
difference in magnitude between two pointsin a magnetic field. When a ferromagnetic object moves
through a gradiometer metal detector's detection space, it causes a temporary disturbance in the earth's
magnetic field, and this disturbance (if large enough) is detected. Gradiometer metal detectors are
usually walk-through devices, but can also be mounted on a vehicle such as a police car, with the
intent of detecting ferromagnetic weapons (e.g., guns) borne by persons approaching the vehicle.
Gradiometer metal detectors are limited to the detection of ferromagnetic objects and so are not
suitable for security situations where a would-be evader of the system is likely to have access to non
ferromagnetic weapons.
4. Magnetic imaging portals
The magnetic imaging portal is a relatively new technology. Like traditional walk-through metal
detectors, it illuminates its detection space with radio-frequency electromagnetic waves; however, it
does so using a number of small antennas arranged ring like around its portal, pointing inward. Each
of these antennas transmits in turn to the antennas on the far side of the array; each antenna acts as a
receiver whenever it is not transmitting. A complete scan of the detection space can take place in the
time it takes a person to walk through the portal. Using computational techniques adapted from
99

computed axial tomography (CAT) scanning, a crude image of the person (or other object) inside the
portal is calculated and displayed. The magnetic imaging portal may for some purposes be classed as
a metal detector rather than as an imaging system because it does not produce a detailed image of the
metal object detected, but only reveals its location and approximate size.
Advantages of Metal detection sensor:
1. Metal Detectors are designed to safeguard security-sensitive areas like schools, courtrooms,
corrections facilities, sports events, businesses, nightclubs, bars and other public areas and events.
2. They are used along with walk-through metal detectors. Construction crews and woodworkers also
use metal detectors to find dangerous nails or other metallic debris in reclaimed building materials and
trees.
3. A recent study proves that metal detectors are just as accurate as x-rays in finding coins and other
metallic objects swallowed by children.
4. They are cheaper and radiation-free, are usually lightweight, highly sensitive and require little
maintenance. The special shape of the sensitive surface makes operation of the device easy, unlike
portable metal detectors with ring transducers. They come with 9V batteries or rechargeable NiMH
batteries.
5. Metal detectors are most commonly used for body searches for weapons in crowd control, and
checking parcels and letters.
6. Larger portable metal detectors are used by archaeologists and treasure hunters to locate metallic
items, such as jewelry, coins, bullets, and other various artifacts buried shallowly underground.
Disadvantages of Metal Detectors
Before you start searching for used metal detectors on sale however, you may have to consider the
pros and cons of having such a kind. The first advantage that you could get from a used one is
definitely a more affordable price tag. Because it's not anymore brand-new, it is naturally a cheaper.
Thus, you don't have to allot a large amount for it. Besides this though, there can be no other benefits
at all. It's not something that acquires skills when it gets a bit older. Thus, you can't expect it to be
much better than the new one because it is old and 'experienced.' The price drop reflects the
100

depreciation of the item. The depreciation rate may also be the measure of the decrease in its
effectiveness or efficiency.

It is obvious that a brand new metal detector may be more expensive but this should not be the reason
why you should turn your back on it. Compared to a used detector, you could rest assured that this is a
much better choice when you are after effectiveness and durability. Thus, you in fact get your money's
worth when you buy one if its price is half higher than the used detector.

3.8 Buzzer
Basically, the sound source of a piezoelectric sound component is a piezoelectric diaphragm. A
piezoelectric diaphragm consists of a piezoelectric ceramic plate which has electrodes on both sides
and a metal plate (brass or stainless steel, etc.). A piezoelectric ceramic plate is attached to a metal
plate with adhesives. Applying D.C. voltage between electrodes of a piezoelectric diaphragm causes
mechanical distortion due to the piezoelectric effect. For a misshaped piezoelectric element, the
distortion of the piezoelectric element expands in a radial direction. And the piezoelectric diaphragm
bends toward the direction. The metal plate bonded to the piezoelectric element does not expand.
Conversely, when the piezoelectric element shrinks, the piezoelectric diaphragm bends in the direction
Thus, when AC voltage is applied across electrodes, the bending is repeated, producing sound waves
in the air.
To interface a buzzer the standard transistor interfacing circuit is used. Note that if a different
power supply is used for the buzzer, the 0V rails of each power supply must be connected to provide a
common reference.
If a battery is used as the power supply, it is worth remembering that piezo sounders
draw much less current than buzzers. Buzzers also just have one tone, whereas a
piezo sounder is able to create sounds of many different tones.
To switch on buzzer -high 1
To switch off buzzer -low 1
Notice (Handling) In Using Self Drive Method
101

1) When the piezoelectric buzzer is set to produce intermittent sounds, sound may be heard
continuously even when the self drive circuit is turned ON / OFF at the "X" point shown in Fig. 9.
This is because of the failure of turning off the feedback voltage.
2) Build a circuit of the piezoelectric sounder exactly as per the recommended circuit shown in the
catalog. Hfe of the transistor and circuit constants are designed to ensure stable oscillation of the
piezoelectric sounder.
3) Design switching which ensures direct power switching.
4) The self drive circuit is already contained in the piezoelectric buzzer. So there is no need to prepare
another circuit to drive the piezoelectric buzzer.
5) Rated voltage (3.0 to 20Vdc) must be maintained. Products which can operate with voltage higher
than 20Vdc are also available.
6) Do not place resistors in series with the power source, as this may cause abnormal oscillation. If a
resistor is essential to adjust sound pressure, place a capacitor (about 1F) in parallel with the piezo
buzzer.
7) Do not close the sound emitting hole on the front side of casing.
8) Carefully install the piezo buzzer so that no obstacle is placed within 15mm from the sound release
hole on the front side of the casing.

102

Fig: Picture of buzzer

3.10 Relay
Relay

We know that most of the high end industrial application devices have relays for their effective
working. Relays are simple switches which are operated both electrically and mechanically. Relays
consist of an electromagnet and also a set of contacts. The switching mechanism is carried out with
the help of the electromagnet. There are also other operating principles for its working. But they differ
according to their applications. Most of the devices have the application of relays.
Why is a relay used?
The main operation of a relay comes in places where only a low-power signal can be used to
control a circuit. It is also used in places where only one signal can be used to control a lot of circuits.
The application of relays started during the invention of telephones. They played an important role in
switching calls in telephone exchanges. They were also used in long distance telegraphy. They were
used to switch the signal coming from one source to another destination. After the invention of
computers they were also used to perform Boolean and other logical operations. The high end
applications of relays require high power to be driven by electric motors and so on. Such relays are
called contactors.
103

Relay Design
There are only four main parts in a relay. They are

Electromagnet

Movable Armature

Switch point contacts

Spring

The figures given below show the actual design of a simple relay.

It is an electro-magnetic relay with a wire coil, surrounded by an iron core. A path


of very low reluctance for the magnetic flux is provided for the movable armature and
also the switch point contacts. The movable armature is connected to the yoke which is
104

mechanically connected to the switch point contacts. These parts are safely held with
the help of a spring. The spring is used so as to produce an air gap in the circuit when
the relay becomes de-energized.

How relay works?


The working of a relay can be better understood by explaining the following diagram given below.

The diagram shows an inner section diagram of a relay. An iron core is surrounded by a
control coil. As shown, the power source is given to the electromagnet through a control switch and
through contacts to the load. When current starts flowing through the control coil, the electromagnet
starts energizing and thus intensifies the magnetic field. Thus the upper contact arm starts to be
attracted to the lower fixed arm and thus closes the contacts causing a short circuit for the power to
the load. On the other hand, if the relay was already de-energized when the contacts were closed, then
the contact move oppositely and make an open circuit.
As soon as the coil current is off, the movable armature will be returned by a force back to its
initial position. This force will be almost equal to half the strength of the magnetic force. This force is
mainly provided by two factors. They are the spring and also gravity.
105

Relays are mainly made for two basic operations. One is low voltage application and the other
is high voltage. For low voltage applications, more preference will be given to reduce the noise of the
whole circuit. For high voltage applications, they are mainly designed to reduce a phenomenon called
arcing.
Relay Basics
The basics for all the relays are the same. Take a look at a 4 pin relay shown below. There
are two colours shown. The green colour represents the control circuit and the red colour represents
the load circuit. A small control coil is connected onto the control circuit. A switch is connected to the
load. This switch is controlled by the coil in the control circuit. Now let us take the different steps that
occour in a relay.

Energized Relay (ON)

As shown in the circuit, the current flowing through the coils represented by pins 1 and 3 causes a
magnetic field to be aroused. This magnetic field causes the closing of the pins 2 and 4. Thus the
switch plays an important role in the relay working. As it is a part of the load circuit, it is used to
control an electrical circuit that is connected to it. Thus, when the relay in energized the current flow
will be through the pins 2 and 4.
106

Energized Relay (ON)

De Energized Relay (OFF)

As soon as the current flow stops through pins 1 and 3, the switch opens and thus the open circuit
prevents the current flow through pins 2 and 4. Thus the relay becomes de-energized and thus in off
position.

107

De-Energized Relay (OFF)

Pole and Throw


Relays have the exact working of a switch. So, the same concept is also applied. A relay is said to
switch one or more poles. Each pole has contacts that can be thrown in mainly three ways. They are

Normally Open Contact (NO) NO contact is also called a make contact. It


closes the circuit when the relay is activated. It disconnects the circuit when the
relay is inactive.

Normally Closed Contact (NC) NC contact is also known as break contact.


This is opposite to the NO contact. When the relay is activated, the circuit
disconnects. When the relay is deactivated, the circuit connects.

Change-over (CO) / Double-throw (DT) Contacts This type of contacts are


used to control two types of circuits. They are used to control a NO contact and
also a NC contact with a common terminal. According to their type they are called
by the names break before make and make before break contacts.

Types of Relays:
Electromechanical relay:
We use Electro mechanical relays.
When an electric current is passed through the coil, the resulting magnetic field
attracts the armature and the consequent movement of the movable contact or contacts
either makes or breaks a connection with a fixed contact. If the set of contacts was
closed when the relay was De-energized, then the movement opens the contacts and
breaks the connection, and vice versa if the contacts were open. When the current to
the coil is switched off, the armature is returned by a force, approximately half as strong
as the magnetic force, to its relaxed position. Usually this force is provided by a spring,
but gravity is also used commonly in industrial motor starters. Most relays are
manufactured to operate quickly. In a low voltage application, this is to reduce noise. In
a high voltage or high current application, this is to reduce arcing.

108

If the coil is energized with DC, a diode is frequently installed across the coil, to
dissipate the energy from the collapsing magnetic field at deactivation, which would
otherwise generate a voltage spike dangerous to circuit components. Some automotive
relays already include a diode inside the relay case. Alternatively a contact protection
network, consisting of a capacitor and resistor in series, may absorb the surge. If the coil
is designed to be energized with AC, a small copper ring can be crimped to the end of
the solenoid. This "shading ring" creates a small out-of-phase current, which increases
the minimum pull on the armature during the AC cycle.

Latching Relay
Latching relays are also called impulse relays. They work in the bistable mode,
and thus have two relaxing states. They are also called keep relays or stay relays
because as soon as the current towards this relay is switched off, the relay continues the
process that it was doing in the last state. This can be achieved only with a solenoid
which is operating in a ratchet and cam mechanism. It can also be done by an overcentre spring mechanism or a permanent magnet mechanism in which, when the coil is
kept in the relaxed point, the over-centre spring holds the armature and the contacts in
the right spot. This can also be done with the help of a remanent core. In the ratchet and
cam method, power consumption occurs only for a particular time. Hence it is more
advantageous than the others.

Polarized Relay
This type of relay has been given more importance on its sensitivity. These relays
have been used since the invention of telephones. They played very important roles in
early telephone exchanges and also in detecting telegraphic distortion. The sensitivity of
these relays is very easy to adjust as the armature of the relay is placed between the
poles of a permanent magnet.

Overload protection Relay


As the name implies, these relays are used to prevent the electric motors from
damage by over current and short circuits. For this the heating element is kept in series

109

with the motor. Thus when over heat occurs the bi-metallic strip connected to the motor
heats up and in turn releases a spring to operate the contacts of the relay.

Contactor Relay
This is one of the most heavy load relay ever used. They are mainly used in
switching electric motors. They have a wide range of current ratings from a few amps to
hundreds. The contacts of these relays are usually made with alloys containing a small
percentage of silver. This is done so as to avoid the hazardous effects of arcing. These
type of relays are mainly categorized in the rough use areas. So, they produce loud
noises while operated and hence cannot be used in places where noise is a problem.

Solid State relay


A solid state relay (SSR) is a solid state electronic component that provides a similar function
to an electromechanical relay but does not have any moving components, increasing long-term
reliability. With early SSR's, the tradeoff came from the fact that every transistor has a small voltage
drop across it. This voltage drop limited the amount of current a given SSR could handle. As
transistors improved, higher current SSR's, able to handle 100 to 1,200 Amperes, have become
commercially available. Compared to electromagnetic relays, they may be falsely triggered by
transients.
Solid State Contactor Relay
These relays combine both the features of solid state relays and contactor relays.
As a result they have a number of advantages. They have a very good heat sink and can
be designed for the correct on-off cycles. They are mainly controlled with the help of
PLC, micro-processors or microcontrollers.

Relays are also named with designations like

Single Pole Single Throw (SPST) This type of relay has a total of four
terminals. Out of these two terminals can be connected or disconnected. The
other two terminals are needed for the coil.

Single Pole Double Throw (SPDT) This type of a relay has a total of five
terminals. Out f these two are the coil terminals. A common terminal is also
included which connects to either of two others.
110

Double Pole Single Throw (DPST) This relay has a total of six terminals.
These terminals are further divided into two pairs. Thus they can act as two
SPSTs which are actuated by a single coil. Out of the six terminals two of them
are coil terminals.

Double Pole Double Throw (DPDT) This is the biggest of all. It has mainly
eight relay terminals. Out of these two rows are designed to be change over
terminals. They are designed to act as two SPDT relays which are actuated by a
single coil.

Relay Applications

Relays are used to realize logic functions. They play a very important role in
providing safety critical logic.

Relays are used to provide time delay functions. They are used to time the delay
open and delay close of contacts.

Relays are used to control high voltage circuits with the help of low voltage
signals. Similarly they are used to control high current circuits with the help of low
current signals.

They are also used as protective relays. By this function all the faults during
transmission and reception can be detected and isolated.

Advantages of relays:

Relays can switch AC and DC, transistors can only switch DC.

Relays can switch high voltages, transistors cannot.

Relays are a better choice for switching large currents (> 5A).

Relays can switch many contacts at once.

Disadvantages of relays:

Relays are bulkier than transistors for switching small currents.

Relays cannot switch rapidly (except reed relays), transistors can switch many
times per second.

Relays use more power due to the current flowing through their coil.
111

Relays require more current than many ICs can provide, so a low power
transistor may be needed to switch the current for the relay's coil.

Relay Driver:
The current needed to operate the relay coil is more than can be supplied by most
chips (op. amps etc), so a transistor is usually needed, as shown in the diagram below.
Use BC109C or similar. A resistor of about 4k7 will probably be alright. The diode
is needed to short circuit the high voltage back emf induced when current flowing
through the coil is suddenly switched off.

Fig. 7.2 Relay Driver

3.11 D.C. Motor


A dc motor uses electrical energy to produce mechanical energy, very typically through
the interaction of magnetic fields and current-carrying conductors. The reverse process, producing
electrical energy from mechanical energy, is accomplished by an alternator, generator or dynamo.
Many types of electric motors can be run as generators, and vice versa. The input of a DC motor is
current/voltage and its output is torque (speed).

112

Fig 3.11.1: DC Motor


The DC motor has two basic parts: the rotating part that is called the armature and the stationary part
that includes coils of wire called the field coils. The stationary part is also called the stator. Figure
shows a picture of a typical DC motor, Figure shows a picture of a DC armature, and Fig shows a
picture of a typical stator. From the picture you can see the armature is made of coils of wire wrapped
around the core, and the core has an extended shaft that rotates on bearings. You should also notice
that the ends of each coil of wire on the armature are terminated at one end of the armature. The
termination points are called the commutator, and this is where the brushes make electrical contact to
bring electrical current from the stationary part to the rotating part of the machine.
Operation:
The DC motor you will find in modem industrial applications operates very similarly
to the simple DC motor described earlier in this chapter. Figure 12-9 shows an electrical diagram of a
simple DC motor. Notice that the DC voltage is applied directly to the field winding and the brushes.
The armature and the field are both shown as a coil of wire. In later diagrams, a field resistor will be
added in series with the field to control the motor speed.

When voltage is applied to the motor, current begins to flow through the field coil
from the negative terminal to the positive terminal. This sets up a strong magnetic field in the field
winding. Current also begins to flow through the brushes into a commutator segment and then through
an armature coil. The current continues to flow through the coil back to the brush that is attached to
other end of the coil and returns to the DC power source. The current flowing in the armature coil sets
up a strong magnetic field in the armature.

113

Fig 3.11.2: Simple electrical diagram of DC motor

Fig 3.11.3: Operation of a DC Motor


The magnetic field in the armature and field coil causes the armature to begin to rotate.
This occurs by the unlike magnetic poles attracting each other and the like magnetic poles repelling
each other. As the armature begins to rotate, the commutator segments will also begin to move under
the brushes. As an individual commutator segment moves under the brush connected to positive
voltage, it will become positive, and when it moves under a brush connected to negative voltage it
will become negative. In this way, the commutator segments continually change polarity from positive
to negative. Since the commutator segments are connected to the ends of the wires that make up the
field winding in the armature, it causes the magnetic field in the armature to change polarity
continually from North Pole to South Pole. The commutator segments and brushes are aligned in such
a way that the switch in polarity of the armature coincides with the location of the armature's magnetic
field and the field winding's magnetic field. The switching action is timed so that the armature will not
lock up magnetically with the field. Instead the magnetic fields tend to build on each other and
provide additional torque to keep the motor shaft rotating.

114

When the voltage is de-energized to the motor, the magnetic fields in the armature and
the field winding will quickly diminish and the armature shaft's speed will begin to drop to zero. If
voltage is applied to the motor again, the magnetic fields will strengthen and the armature will begin
to rotate again.
3.12 DC Motor Driver:
The L293 and L293D are quadruple high-current half-H drivers. The L293 is designed
to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V to 36 V. The L293D is
designed to provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V. Both
devices are designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping
motors, as well as other high-current/high-voltage loads in positive-supply applications.
All inputs are TTL compatible. Each output is a complete totem-pole drive circuit, with
a Darlington transistor sink and a pseudo-Darlington source. Drivers are enabled in pairs, with drivers
1 and 2 enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN.When an enable input is high, the
associated drivers are enabled and their outputs are active and in phase with their inputs.
When the enable input is low, those drivers are disabled and their outputs are off and in
the high-impedance state. With the proper data inputs, each pair of drivers forms a full-H (or bridge)
reversible drive suitable for solenoid or motor applications. On the L293, external high-speed output
clamp diodes should be used for inductive transient suppression. A VCC1 terminal, separate from
VCC2, is provided for the logic inputs to minimize device power dissipation. The L293and L293D is
characterized for operation from 0C to 70C.

115

Fig 3.12.1: L293D IC

Fig 3.12.2: L293D Pin

Diagram

Fig 3.12.3: Internal structure of L293D.


Features of L293D:

600mA Output current capability per channel


116

1.2A Peak output current (non repetitive) per channel


Enable facility
Over temperature protection
Logical 0input voltage up to 1.5 v
High noise immunity
Internal clamp diodes

PULSE WIDTH MODULATION (PWM):


Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a commonly used
technique for controlling power to inertial electrical devices, made practical by modern electronic
power switches.
The average value of voltage (and current) fed to the load is controlled by turning the switch
between supply and load on and off at a fast pace. The longer the switch is on compared to the off
periods, the higher the power supplied to the load is.
The PWM switching frequency has to be much faster than what would affect the load, which
is to say the device that uses the power. Typically switching have to be done several times a minute in
an electric stove, 120 Hz in a lamp dimmer, from few kilohertz (kHz) to tens of kHz for a motor drive
and well into the tens or hundreds of kHz in audio amplifiers and computer power supplies.
The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of
time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty
cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very low. When a
switch is off there is practically no current, and when it is on, there is almost no voltage drop across
the switch. Power loss, being the product of voltage and current, is thus in both cases close to zero.
PWM also works well with digital controls, which, because of their on/off nature, can easily set the
needed duty cycle. PWM has also been used in certain communication systems where its duty cycle
has been used to convey information over a communications channel.

117

Communication and control


One of the advantages of PWM is that the signal remains digital all the way from the processor to the
controlled system; no digital-to-analog conversion is necessary. By keeping the signal digital, noise
effects are minimized. Noise can only affect a digital signal if it is strong enough to change a logic-1
to a logic-0, or vice versa.
Increased noise immunity is yet another benefit of choosing PWM over analog control, and is the
principal reason PWM is sometimes used for communication. Switching from an analog signal to
PWM can increase the length of a communications channel dramatically. At the receiving end, a
suitable RC (resistor-capacitor) or LC (inductor-capacitor) network can remove the modulating high
frequency square wave and return the signal to analog form.
PWM finds application in a variety of systems. As a concrete example, consider a PWM-controlled
brake. To put it simply, a brake is a device that clamps down hard on something. In many brakes, the
amount of clamping pressure (or stopping power) is controlled with an analog input signal. The more
voltage or current that's applied to the brake, the more pressure the brake will exert.
The output of a PWM controller could be connected to a switch between the supply and the brake. To
produce more stopping power, the software need only increase the duty cycle of the PWM output. If a
specific amount of braking pressure is desired, measurements would need to be taken to determine the
mathematical relationship between duty cycle and pressure. (And the resulting formulae or lookup
tables would be tweaked for operating temperature, surface wear, and so on.)
To set the pressure on the brake to, say, 100 psi, the software would do a reverse lookup to determine
the duty cycle that should produce that amount of force. It would then set the PWM duty cycle to the
new value and the brake would respond accordingly. If a sensor is available in the system, the duty
cycle can be tweaked, under closed-loop control, until the desired pressure is precisely achieved.
PWM is economical, space saving, and noise immune. And it's now in your bag of tricks. So use it.

118

PWM controllers
Many microcontrollers include on-chip PWM controllers. For example, Microchip's PIC16C67
includes two, each of which has a selectable on-time and period. The duty cycle is the ratio of the ontime to the period; the modulating frequency is the inverse of the period. To start PWM operation, the
data sheet suggests the software should:

Set the period in the on-chip timer/counter that provides the modulating square wave

Set the on-time in the PWM control register

Set the direction of the PWM output, which is one of the general-purpose I/O pins

Start the timer

Enable the PWM controller

Although specific PWM controllers do vary in their programmatic details, the basic idea is generally
the same.

DC Motor Driver:

H Bridge
With switches:

An H bridge is an electronic circuit that enables a voltage to be applied across a load in either
direction. These circuits are often used in robotics and other applications to allow DC motors to run
forwards and backwards.

119

When the switches S1 and S4 (according to the first figure) are closed (and S2 and S3 are
open) a positive voltage will be applied across the motor. By opening S1 and S4 switches and closing
S2 and S3 switches, this voltage is reversed, allowing reverse operation of the motor.
Using the nomenclature above, the switches S1 and S2 should never be closed at the same
time, as this would cause a short circuit on the input voltage source. The same applies to the switches
S3 and S4. This condition is known as shoot-through.

The H-bridge arrangement is generally used to reverse the polarity of the motor, but can also be
used to 'brake' the motor, where the motor comes to a sudden stop, as the motor's terminals are
shorted, or to let the motor 'free run' to a stop, as the motor is effectively disconnected from the
circuit. The following table summarizes operation, with S1-S4 corresponding to the diagram above.

120

S1 S2

S3

S4

Result

1 0

Motor moves right

0 1

Motor moves left

0 0

Motor free runs

0 1

Motor brakes

1 0

Motor brakes

1 1

Shoot-through

0 0

Shoot-through

1 1

Shoot-through

With relays:

If you connect up these relay circuits, remember to put a diode across the coil of the relay.
This will keep the spike voltage (back EMF), coming out of the coil of the relay, from getting into the
MCU and damaging it. The anode, which is the arrow side of the diode, should connect to ground.
The bar, which is the Cathode side of the diode, should connect to the coil where the MCU connects
to the relay.

121

If you connect this circuit to a small hobby motor you can control the motor with a processor
(MCU, etc.) Applying a logical one, (+12 Volts in our example) to point A causes the motor to turn
forward. Applying a logical zero, (ground) causes the motor to stop turning (to coast and stop).

Hook the motor up in this fashion and the circuit turns the motor in reverse when you apply a
logical one (+12Volts) to point B. Apply a logical zero, which is usually a ground, causes the motor to
stop spinning.
If you hook up these circuits you can only get the motor to stop or turn in one direction, forward
for

the

first

circuit

or

reverse

for

the

second

circuit.

You can also pulse the motor control line, (A or B) on and off. This powers the motor in short burst
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
circuitry. You will need an H-Bridge. Notice the "H"-looking configuration in the next graphic. Relays
configured in this fashion make an H-Bridge. The "high side drivers" are the relays that control the
positive voltage to the motor. This is called sourcing current.
The "low side drivers" are the relays that control the negative voltage to sink current to the
motor. "Sinking current" is the term for connecting the circuit to the negative side of the power
supply, which is usually ground.

122

So, you turn on the upper left and lower right circuits, and power flows through the motor forward,
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 through the motor
in reverse, i.e.: 0 to A, 1 to B, 1 to C, and 0 to D.

123

You should be careful not to turn on both circuits on one side and the other, or you have a
direct short which will destroy your circuit; Example: A and C or B and D both high (logical 1).

With transistors:

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 circuits. You don't need diodes that
were across the relay coils now. You should use diodes across your transistors 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 relay
circuits. The high side drivers need to be current "sources" which is what PNP transistors and Pchannel 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.

124

If you turn on the two upper circuits, the motor resists turning, so you effectively have a
breaking mechanism. The same is true if you turn on both of the lower circuits. This is because the
motor is a generator and when it turns it generates a voltage. If the terminals of the motor are
connected (shorted), then the voltage generated counteracts the motors freedom to turn. It is as if you
are applying a similar but opposite voltage to the one generated by the motor 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 is generated
by the motor's coil when the power is switched on and off. This fly back voltage can be many times
higher than the supply voltage! If you don't use diodes, you could burn out your transistors.

Transistors, being a semiconductor device, will have some resistance, which causes them to get hot
when conducting much current. This is called not being able to sink or source very much power, i.e.:
Not able to provide much current from ground or from plus voltage.
125

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. This helps 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 to source 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 circuits to overcome the breakdown voltage.
It is important that the four quadrants of the H-Bridge circuits be turned on and off properly.
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 of the power supply
and can cause semiconductors to become ballistic, in circuits with large currents flowing. There are Hbridge chips available that are much easier, and safer, to use than designing your own H-Bridge
circuit.
H-Bridge Devices
The L293 has 2 H-Bridges, can provide about 1amp to each and occasional peak loads to 2 amps.
Motors typically controlled with this controller are near the size of a 35 mm film plastic canister.
The L298 has 2 h-bridges on board, can handle 1amp and peak current draws to about 3amps. You
often see motors between the size a of 35 mm film plastic canister and a coke can, driven by this type
H-Bridge. The LMD18200 has one h-bridge on board, can handle about 2 or 3 amps and can handle a
peak of about 6 amps. This H-Bridge chip can usually handle an average motor about the size of a
coke. There are several more commercially designed H-Bridge chips as well.

Schematic diagram:

126

Features:
Delivers up to 5 A continuous 6 A peak current
Optimized for DC motor management applications
Operates at supply voltages up to 40 V
Very low RDS ON
; typ. 200 m @ 25 C per switch
Output full short circuit protected
Overtemperature protection with hysteresis
and diagnosis
Short circuit and open load diagnosis
With open drain error flag
Undervoltage lockout
CMOS/TTL compatible inputs with hysteresis
127

No crossover current
Internal freewheeling diodes
Wide temperature range; 40 C < Tj< 150 C

3.10 3.10 WIRELESS A/V CAMERA:


Introduction:
Wireless security cameras are closed-circuit television (CCTV) cameras that transmit a video
and audio signal to a wireless receiver through a radio band. Many wireless security cameras require
at least one cable or wire for power; "wireless" refers to the transmission of video/audio. However,
some wireless security cameras are battery-powered, making the cameras truly wireless from top to
bottom.
Wireless cameras are proving very popular among modern security consumers due to their low
installation costs (there is no need to run expensive video extension cables) and flexible mounting
options; wireless cameras can be mounted/installed in locations previously unavailable to standard
wired cameras. In addition to the ease of use and convenience of access, wireless security camera
allows users to leverage broadband wireless internet to provide seamless video streaming overinternet.
(Model: SP-007AS)

Fig 3.10.1: Wireless A/V camera


128

A/V transmitter:
The camera is with 1.2GHZ, with Audio and CMOS and receiver unit with manual frequency
adjustment. This wholesale product is already popular with ChinaTronic customers because of
consistent high quality.

Linear Transmission Distance: 50-100m

Transmission Signal: Audio, Video

Receiving Signal: Audio, Video

Technical parameters of transmitting unit:


1. Video Camera Parts: 1/3CMOS, 1/4 Image Sensors
2. System: PAL/CCIR NTSC/EIA
3. Effective Pixel: PAL: 628 x 582, NTSC: 510 x 492
4. Image Area: PAL: 5.78 x 4.19mm, NTSC: 4.69 x 3.45mm
5. Horizontal Definition: 380 Lines
6. Scanning Frequency: PAL/CCIR: 50Hz, NTSC/EIA: 60Hz
7. Minimum Illumination: 3 LUX
8. Sensitivity: +18DB-AGL On-Off
9. Electrical Level Output: 50mW
10. Frequency Output: 1.2Ghz
11. Transmission Signal: Audio, Video
12. Linear Transmission Distance: 50-100m
13. Voltage: DC+9V
14. Current: 300mA
15. Power Dissipation: 640mW

129

Fig 3.10.2 Wireless camera


Technical parameters of receiving unit:

Wireless Audio/Video Receiver

Receiving Method: CPU Phase-Locked Loop Locking Frequency Points

4-Band Automatic Reception Switch

Reception Sensitivity: +18dB

Receiving Frequency: 1.2Ghz

Receiving Signal: Audio, Video

Voltage: DC+12V

Current: 500mA

Types:
Analog wireless:
Analog wireless is the transmission of audio and video signals using radio frequencies.
Typically, analog wireless has a transmission range of around 300 feet (91 meters) in open space;
walls, doors, and furniture will reduce this range.
130

Analog wireless is found in three frequencies: 900 MHz, 2.4 GHz, and 5.8 GHz. Currently, the
majority of wireless security cameras operates on the 2.4 GHz frequency. Most household routers,
cordless phones, video game controllers, and microwaves operate on the 2.4 GHz frequency and may
cause interference with your wireless security camera. 900 MHz is known as Wi-Fi Friendly because
it will not interfere with the Internet signal of your wireless network.
Advantages include:

Multiple receivers per camera: the signal from one camera can be picked up by any receiver;
you can have multiple receivers in various locations to create your wireless surveillance
network

Disadvantages:

Susceptible to interference from other household devices, such as microwaves, cordless


phones, video game controllers, and routers

About Digital Wireless Technology:


Digital wireless is the transmission of audio and video analog signals encoded as digital
packets over high-bandwidth radio frequencies.

The Digital Wireless signal transmission type used by the Lorex LW2275 Series is also known
as FHSSFrequency Hopping Spread Spectrum. This type of signal results in a private, interferencefree signal. The 2.4GHz (2.400-2.480GHz) band is divided into sections or paths of 2MHz per
section, and each second, the transmission signal hops hundreds of times in a specified sequence
within this frequency range. The overall bandwidth required for frequency hopping is much wider
than 2MHz; however, because transmission occurs only on a small section of this bandwidth at any
given time, the signal being transmitted does not suffer from greatly reduced signal degradation and
also avoids paths blocked by other devices that act as sources of competing signals.
The strength of the signal being transmitted is set to be from 13.5-16dBm, which is much
higher than the analog transmission signal allowed by authorities around the globe. When an image is
captured by the camera, it is instantly converted from an analog to a digital signal and is packaged
131

into small packets. With each successful transmission via the 2 MHz paths discussed above, the
packets of information containing images are delivered to the receiver and decoded into analog
information.
The information can then be displayed on devices that are connected to the wireless receiver
(RX). A device pairing process is required to synchronize the transmitter (TX, Camera) and the
receiver (RX). This allows the transmitter and receiver to be on the same frequency and use the same
algorithm for frequency hopping. This ensures that only the paired transmitter and receiver can
maintain communication signal by hopping to the same frequency paths at the exact same time. As a
result, the chance that other devices within the same frequency range are on the same frequency, at the
same time and in the same order is vastly reduced. Note that the pairing process is already done at the
factory for products that ship within the same packaging.
Facts about Digital Wireless Cameras:
Wired vs. Wireless Cameras:
A wired camera has a video cable that transmits the video signal from the camera to a
recording or viewing device.

A wireless camera does not use a video cable. Instead, it wirelessly transmits the video signal
to a wireless receiver that is connected to your recording or viewing device. Although the typical
digital wireless camera is priced slightly higher than a wired camera, wireless cameras can provide
cost savings compared to standard wired setups. For example, wireless cameras do not require cabling
to be run between the camera and the viewing / recording device, which reduces installation time and
cost.
Does a wireless camera require power?

Yes. Wireless cameras require two power sources: one connected to the camera, and the other
to the receiver.

How far can a wireless camera transmit a video signal?


In an open field (with line of sight), a typical wireless camera has a range between 250 to 450
feet. In a closed environmentsuch as an interior of a housethe wireless camera range is between
132

100 to 150 feet. The signal range varies depending on the type of building materials and/or objects the
wireless signal must pass through.
Cubical walls, drywall, glass, and windows generally do not degrade wireless signal strength.
Brick, concrete floors, and walls degrade signal strength1. Trees that are in the line of sight of the
wireless camera and receiver may impact signal strength. The signal range also depends on whether
there are competing signals using the same frequency as the camera. For example, signals from
cordless phones or routers may affect signal strength.
Range Limiting:

Signal Reduction through Materials:


Signal strength decreases as it passes through different types of material. Try to position your
wireless camera and receiver in a location where the signal does not pass through metal or concrete
blocks, which can significantly reduce signal strength (as shown in the table below).

133

Signals that must pass through wet or moist materials (i.e. shrubs and trees) may be
significantly reduced. The stronger the signal strength, the higher the video frame rate the lower the
signal Strength, the lower the video frame rate

Are digital wireless cameras signals secure?


Yes. Lorex digital wireless products feature a wireless transmission method called FHSS
Frequency Hopping Spread Spectrum. This type of signal is highly resistant to eavesdropping as it
generates a channel hopping sequence using an algorithm generated by the receiver, which only the
camera can follow through the "pairing" function. FHSS makes digital wireless signals secure,
private, and interference free.
How many frames per second should I expect from a digital wireless camera?
Current Lorex digital wireless cameras offer 10 - 30 FPS (Frames Per Second) Performance.
Actual frame rate depends mainly on signal strength and resolution (see the chart above). Most digital
wireless cameras support one or both of the following resolutions: QVGA and VGA.

QVGA produces video at up to 25-30 FPS at 320x240 resolution.

VGA produces video at up to 10-12 FPS at 640x480 resolution.

How many wireless cameras can I install?

It is recommended to install a maximum of 4 (four) wireless cameras per system.

Advantages include:
134

Wide transmission rangeusually close to 450 feet (open space, clear line of sight between
camera and receiver)

High quality video and audio

Two-way communication between the camera and the receiver

Digital signal means you can transmit commands and functions, such as turning lights on and
off

You can connect multiple receivers to one recording device, such as security DVR

Wireless range:

Range limiting factors:


Wireless security cameras function best when there is a clear line of sight between the
camera(s) and the receiver. Outdoors, and with clear line of sight, digital wireless cameras typically
have a range between 250 to 450 feet. Indoors, the range can be limited to 100 to 150 feet. The signal
range varies depending on the type of building materials and/or objects the wireless signal must pass
through.
Extending Wireless Signal Range:
135

Certain accessories are not available in all markets. There are several ways to boost your
wireless signal as well as options to help you extend the range of the wireless signal.
Clear Line-of-Sight:
The digital wireless signal is virtually interference free. However, you should always ensure
there is a clear line-of-sight between the camera and the receiver.

Obstacles:
There should be little to no obstacles obstructing the line-of-sight between the camera and the
receiver. Solid objects, such as concrete and metal, may limit the range of the wireless signal.
Extending Your Wireless Signal:
Even with a clear line-of-sight between your camera(s) and your receiver, you may experience
a lower video frame rate simply due to the distance between your wireless devices.
Accessory antennas are available that can help extend the range of your wireless signal.
GHZ Directional Wireless Panel Antenna:
Use the 2.4GHz Directional Wireless Panel Antenna (model #: ACCANTD9) to focus a
Directional Wireless Panel Antenna wireless signal onto one specific camera in order to increase range
of transmission (clear line-of-sight between the camera and the antenna is required). A 20 ft. extension
cable is included help with proper position.

Use the 2.4GHz Omni-Directional Wireless Antenna (model #: ACCANTO9) to extend the
range and boost the signal of several wireless cameras. You should position the Omni-Directional
136

Wireless Antenna in an elevated position to provide a clear line-of-sight to the cameras. A 20 ft.
extension cable is included help position the antenna

Features:

FHSS Digital Wireless Technology provides excellent image quality and clarity
Simple installation. No video cable required1
Connect multiple receivers to your surveillance recorder (DVR) to create a wireless
Surveillance solution2
Easily connects to a TV/monitor (RCA) or DVR (BNC adapter included)
Night viewing up to 100 ft. (30m)
Install camera indoors or outdoors
Up to 150 ft. (46m) indoor / 450 ft. (137m) outdoor wireless range5
Listen in with exceptional sound clarity
137

Receiver Features:
Compact receiver is easy to install and operate
VGA (640x480) & QVGA (320x240) resolution supported6
Convenient signal strength indicator
Plug directly into a TV or DVR (BNC adapter included) with termination cable for flexible
Installation
Listen-in audio
Camera Features:
VGA Resolution Camera
100 ft. (30m) IR Night Vision3
Auto infrared light filter ensures accurate color reproduction under any lighting condition
Weatherproof housing (IP66 rated)
Receiver Specifications:

Camera Specifications:

138

Troubleshooting:
If you have problems with your system, there is often a quick and simple solution. Please try
the following:
Built-in microphone

139

Uses and applications:


Wireless security cameras are becoming more and more popular in the consumer market,
being a cost-effective way to have a comprehensive surveillance system installed in a home or
business for an often less expensive price. Wireless cameras are also ideal for people renting homes or
apartments. Since there is no need to run video extension cables through walls or ceilings (from the
camera to the receiver or recording device) one does not need approval of a landlord to install a
wireless security camera system. Additionally, the lack of wiring allows for less "clutter," avoiding
damage to the look of a building.
140

A wireless security camera is also a great option for seasonal monitoring and surveillance. For
example, one can observe a pool or patio in summer months and take down the camera in the winter.

CHAPTER 4: SOFTWARE DESCRIPTION


This project is implemented using following softwares:

Express PCB for designing circuit

PIC C compiler - for compilation part

Proteus 7 (Embedded C) for simulation part


141

4.1 Express PCB:


Breadboards are great for prototyping equipment as it allows great flexibility to modify
a design when needed; however the final product of a project, ideally should have a neat PCB, few
cables, and survive a shake test. Not only is a proper PCB neater but it is also more durable as there
are no cables which can yank loose.
Express PCB is a software tool to design PCBs specifically for manufacture by the
company Express PCB (no other PCB maker accepts Express PCB files). It is very easy to use, but it
does have several limitations.
It can be likened to more of a toy then a professional CAD program.
It has a poor part library (which we can work around)
It cannot import or export files in different formats
It cannot be used to make prepare boards for DIY production
Express PCB has been used to design many PCBs (some layered and with surface-mount
parts. Print out PCB patterns and use the toner transfer method with an Etch Resistant Pen to make
boards. However, Express PCB does not have a nice print layout. Here is the procedure to design in
Express PCB and clean up the patterns so they print nicely.
4.1.1 Preparing Express PCB for First Use:
Express PCB comes with a less then exciting list of parts. So before any project is
started head over to Audio logical and grab the additional parts by morsel, ppl, and tangent, and
extract them into your Express PCB directory. At this point start the program and get ready to setup
the workspace to suit your style.
Click View -> Options. In this menu, setup the units for mm or in depending on
how you think, and click see through the top copper layer at the bottom. The standard color scheme
of red and green is generally used but it is not as pleasing as red and blue.
4.1.2 The Interface:

142

When a project is first started you will be greeted with a yellow outline. This yellow
outline is the dimension of the PCB. Typically after positioning of parts and traces, move them to their
final position and then crop the PCB to the correct size. However, in designing a board with a certain
size constraint, crop the PCB to the correct size before starting.
Fig: 4.1 show the toolbar in which the each button has the following functions:

Fig 4.1: Tool bar necessary for the interface

The select tool: It is fairly obvious what this does. It allows you to move

and manipulate

parts. When this tool is selected the top toolbar will show buttons to move traces to the top /
bottom copper layer, and rotate buttons.

The zoom to selection tool: does just that.

The place pad: button allows you to place small soldier pads which are useful for board
connections or if a part is not in the part library but the part dimensions are available. When
this tool is selected the top toolbar will give you a large selection of round holes, square holes
and surface mount pads.

The place component: tool allows you to select a component from the top toolbar and then by
clicking in the workspace places that component in the orientation chosen using the buttons
next to the component list. The components can always be rotated afterwards with the select
tool if the orientation is wrong.

The place trace: tool allows you to place a solid trace on the board of varying thicknesses. The
top toolbar allows you to select the top or bottom layer to place the trace on.

The Insert Corner in trace: button does exactly what it says. When this tool is selected,
clicking on a trace will insert a corner which can be moved to route around components and
other traces.

143

The remove a trace button is not very important since the delete key will achieve the same
result.

4.1.3 Design Considerations:


Before starting a project there are several ways to design a PCB and one must be
chosen to suit the projects needs.
Single sided, or double sided?
When making a PCB you have the option of making a single sided board, or a double
sided board. Single sided boards are cheaper to produce and easier to etch, but much harder to
design for large projects. If a lot of parts are being used in a small space it may be difficult to make
a single sided board without jumpering over traces with a cable. While theres technically nothing
wrong with this, it should be avoided if the signal travelling over the traces is sensitive (e.g. audio
signals).
A double sided board is more expensive to produce professionally, more difficult to
etch on a DIY board, but makes the layout of components a lot smaller and easier. It should be noted
that if a trace is running on the top layer, check with the components to make sure you can get to its
pins with a soldering iron. Large capacitors, relays, and similar parts which dont have axial leads
can NOT have traces on top unless boards are plated professionally.
Ground-plane or other special purposes for one side
When using a double sided board you must consider which traces should be on what
side of the board. Generally, put power traces on the top of the board, jumping only to the bottom if
a part cannot be soldiered onto the top plane (like a relay), and vice- versa.
Some projects like power supplies or amps can benefit from having a solid plane to use
for ground. In power supplies this can reduce noise, and in amps it minimizes the distance between
parts and their ground connections, and keeps the ground signal as simple as possible. However,
care must be taken with stubborn chips such as the TPA6120 amplifier from TI. The TPA6120
datasheet specifies not to run a ground plane under the pins or signal traces of this chip as the
capacitance generated could effect performance negatively.
144

4.2 PIC Compiler:


PIC compiler is software used where the machine language code is written and
compiled. After compilation, the machine source code is converted into hex code which is to be
dumped into the microcontroller for further processing. PIC compiler also supports C language code.
Its important that you know C language for microcontroller which is commonly
known as Embedded C. As we are going to use PIC Compiler, hence we also call it PIC C. The PCB,
PCM, and PCH are separate compilers. PCB is for 12-bit opcodes, PCM is for 14-bitopcodes, and
PCH is for 16-bit opcode PIC microcontrollers. Due to many similarities, all three compilers are
covered in this reference manual. Features and limitations that apply to only specific microcontrollers
are indicated within. These compilers are specifically designed to meet the unique needs of the PIC
microcontroller. This allows developers to quickly design applications software in a more readable,
high-level language. When compared to a more traditional C compiler, PCB, PCM, and PCH have
some limitations. As an example of the limitations, function recursion is not allowed.
This is due to the fact that the PIC has no stack to push variables onto, and also
because of the way the compilers optimize the code. The compilers can efficiently implement normal
C constructs, input/output operations, and bit twiddling operations. All normal C data types are
supported along with pointers to constant arrays, fixed point decimal, and arrays of bits.
PIC C is not much different from a normal C program. If you know assembly, writing
a C program is not a crisis. In PIC, we will have a main function, in which all your application
specific work will be defined. In case of embedded C, you do not have any operating system running
in there. So you have to make sure that your program or main file should never exit. This can be done
with the help of simple while (1) or for (;;) loop as they are going to run infinitely.
We have to add header file for controller you are using, otherwise you will not be able
to access registers related to peripherals.
#include <16F72.h> // header file for PIC 16F72//

4.3 Proteus:
Proteus is software which accepts only hex files. Once the machine code is converted
into hex code, that hex code has to be dumped into the microcontroller and this is done by the Proteus.
145

Proteus is a programmer which itself contains a microcontroller in it other than the one which is to be
programmed. This microcontroller has a program in it written in such a way that it accepts the hex file
from the pic compiler and dumps this hex file into the microcontroller which is to be programmed. As
the Proteus programmer requires power supply to be operated, this power supply is given from the
power supply circuit designed and connected to the microcontroller in proteus. The program which is
to be dumped in to the microcontroller is edited in proteus and is compiled and executed to check any
errors and hence after the successful compilation of the program the program is dumped in to the
microcontroller using a dumper.
4.4 Procedural steps for compilation, simulation and dumping:
4.4.1 Compilation and simulation steps:
For PIC microcontroller, PIC C compiler is used for compilation. The compilation
steps are as follows:

Open PIC C compiler.

You will be prompted to choose a name for the new project, so create a separate folder where
all the files of your project will be stored, choose a name and click save.

Fig 4.1: Picture of opening a new file using PIC C compiler


146

Click Project, New, and something the box named 'Text1' is where your code should be
written later.

Now you have to click 'File, Save as' and choose a file name for your source code ending with
the letter '.c'. You can name as 'project.c' for example and click save. Then you have to add
this file to your project work.

Fig 4.2: Picture of compiling a new file using PIC C compiler

147

Fig 4.3: Picture of compiling a project.c file using PIC C compiler

You can then start to write the source code in the window titled 'project.c' then before testing
your source code; you have to compile your source code, and correct eventual syntax errors.

148

Fig 4.4: Picture of checking errors and warnings using PIC C compiler

By clicking on compile option .hex file is generated automatically.

This is how we compile a program for checking errors and hence the compiled program is
saved in the file where we initiated the program.

149

Fig 4.5: Picture of .hex file existing using PIC C compiler

After compilation, next step is simulation. Here first circuit is designed in Express PCB
using Proteus 7 software and then simulation takes place followed by dumping. The simulation steps
are as follows:

Open Proteus 7 and click on IS1S6.

Now it displays PCB where circuit is designed using microcontroller. To design circuit
components are required. So click on component option.

10. Now click on letter p, then under that select PIC16F72 ,other components related to the project
and click OK. The PIC 16F72 will be called your 'Target device, which is the final destination of
your source code.

150

4.4.2 Dumping steps:


The steps involved in dumping the program edited in proteus 7 to microcontroller are
shown below:
1. Initially before connecting the program dumper to the microcontroller kit the window is
appeared as shown below.

Fig 4.6: Picture of program dumper window

2. Select Tools option and click on Check Communication for establishing a connection as shown
in below window
151

Fig 4.7: Picture of checking communications before dumping program into microcontroller

3. After connecting the dumper properly to the microcontroller kit the window is appeared as shown
below.

152

Fig 4.8: Picture after connecting the dumper to microcontroller


153

4. Again by selecting the Tools option and clicking on Check Communication the microcontroller
gets recognized by the dumper and hence the window is as shown below.

154

Fig 4.9: Picture of dumper recognition to microcontroller

155

5. Import the program which is .hex file from the saved location by selecting File option and
clicking on Import Hex as shown in below window.

156

157

Fig 4.10: Picture of program importing into the microcontroller

6. After clicking on Import Hex option we need to browse the location of our program and click the
prog.hex and click on open for dumping the program into the microcontroller.

Fig 4.11: Picture of program browsing which is to be dumped

7. After the successful dumping of program the window is as shown below.

158

Fig 4.12: Picture after program dumped into the microcontroller


159

CHAPTER 5: PROJECT DESCRIPTION


In this chapter, schematic diagram and interfacing of PIC16F72 microcontroller with
each module is considered.

160

Fig 5.1: schematic diagram of Bomb Detecting and diffusion wireless


controlled War field Robot through PC
The above schematic diagram of Bomb Detecting and diffusion wireless controlled War field Robot
through PC explains the interfacing section of each component with micro controller and PIR, metal
sensors, Zigbee module, RS232, DC motors and driver. The crystal oscillator connected to 9 th and 10th
pins of micro controller and regulated power supply is also connected to micro controller and LEDs
also connected to micro controller through resistors and motor driver connected to micro controller

161

CHAPTER 6: ADVANTAGES AND DISADVANTAGES

Advantages:
1. Detection of metals in mines.
2. This Robot can be operated from anywhere in the world.
3. Wireless controlling of Robot through PC using Zigbee technology.
4. Capable of detecting land mines.
5. Bomb detection and diffusion
6. Fast response.
7. Efficient and low cost design.
8. Low power consumption.

Disadvantages:
1. The quality of tone received depends on the network signal strength.
2. Status and feed back of robot is not obtained.
3. Limited distance.

Applications:
1. It can be used in places where humans cannot work.
2. Mainly in military applications, robots play a vital role for detection of explosives.
3. Can be used to detect metals.
4. Can be used in mines.

162

CHAPTER 7: RESULTS

7.1 Result:

The project Bomb Detecting and diffusion wireless controlled War field Robot through PC
was designed such that the robot can be operated using PC which is capable of detecting land mines in
its path and which is wirelessly controlled through PC using Zigbee technology. It is a very low cost
robot used to monitor the Warfield. The robot can be moved in all the directions using the PC
wirelessly. The robot system is also used for bomb detection and diffusion using robotic arm.
7.2 Conclusion:
Integrating features of all the hardware components used have been developed in it. Presence
of every module has been reasoned out and placed carefully, thus contributing to the best working of
the unit. Secondly, using highly advanced ICs with the help of growing technology, the project has
been successfully implemented. Thus the project has been successfully designed and tested.
7.3 Future Scope:
Our project Bomb Detecting and diffusion wireless controlled War field Robot through PC
is mainly intended to operate a robot using PC. The system also to detects the metallic presence stops
buzzers an alarm system. The micro controller is programmed in such a way that the depending on the
pressed key the robot will move intelligently and with the help of metal detection sensor it detects the
presence of metallic objects in mines and alerts through buzzer alarm system. The robot system is also
used for bomb detection and diffusion using robotic arm.
The drawback of this project is that the status of robot is not known. This can eliminate by
having a GSM module, which gives the status of robot working. We can also add Ultrasonic module,
which is used for obstacle detection with GSM module which gives respective information.

163

By connecting wireless camera to the robot, then we can see the outer world from our
personal computer only by using GPRS and GPS. We can use this robot at so many fields and we can
use to handle so many situations.
By connecting bomb detector to the robot, we can send it to anywhere i.e (battle field,
forests, coal mines, to anyplace) by using our personal computer and we can able to detect the bomb
at field, here sensor detects the bomb and gives information to micro controller and it gives the
information to transceiver and it sends the information to the personal computer.
By connecting temperature sensor to the robot we can get the temperature of dangerous
zones in personal computer itself instead of sending human to there and facing problems at field we
can send robot to there and sensor will detect the temperature and it gives information to the micro
controller and micro controller gives the information to the transceiver from that we can get the data
at pc side. By connecting smoke sensor to the robot we can get the information related concentration
of smoke or gases in respective fields i.e. (coal mines, dangerous zones, etc). sensor sense the
information and it give to the micro controller and it gives to the transceiver and from that we get the
information in personal computer.
By connecting corresponding instruments to the robot we can use it in agriculture for
farming purpose. This robot can move either forward and backward and left and right depend upon
our instructions so we can do some part of agriculture from pc only by using robot.
By connecting firing instrument and wireless camera to the robot we can fire the target
from pc. Here by using camera we can see the opposite target and we can fire the target from personal
computer by pressing selected button and we can easily handle the situations like Mumbai terrorists
attack without loss of human lifes and we can decrease our soldiers effort too.

164

REFERENCES
The sites which were used while doing this project:

1. www.wikipedia.com
2. www.allaboutcircuits.com
3. www.microchip.com
4. www.howstuffworks.com

Books referred:

1. Raj kamal Microcontrollers Architecture, Programming, Interfacing and System Design.


2. Mazidi and Mazidi Embedded Systems.
3. PCB Design Tutorial David.L.Jones.
4. PIC Microcontroller Manual Microchip.
5. Pyroelectric Sensor Module- Murata.
6. Embedded C Michael.J.Pont.

165

APPENDIX
Program Code:
The program code which is dumped in the microcontroller of our project is shown
below.
#include <16F72.h>

#include <16F72.h>
#use delay

(clock=20000000)

#include <dcmotor.h>
#use rs232(baud=9600,xmit=PIN_B0, rcv=PIN_B1)
unsigned long duty = 0;
void main()
{
int i=0;
unsigned int command;
char ch;
output_high(PIN_C4);
output_high(PIN_C5);
delay_ms(500);
output_low(PIN_C4);
output_low(PIN_C5);
delay_ms(500);
output_high(PIN_C4);
output_high(PIN_C5);
delay_ms(500);
output_low(PIN_C4);
output_low(PIN_C5);
while(1)
{
ch = getc();
if(!(input(pin_A1))) // Metal sensor
{
output_high(pin_C5); //Buzzer
delay_ms(100);
}

166

else
{
output_low(pin_C52);
}
if(ch == 'f')
{
output_high(PIN_C3);
Motor_M1_On(150,1); //1=forward, 0=reverse
Motor_M2_On(150,1); //1=forward, 0=reverse
}
else if(ch == 'b')
{
output_high(PIN_C42);
Motor_M1_On(150,0); //1=forward, 0=reverse
Motor_M2_On(150,0); //1=forward, 0=reverse
}
else if(ch == 'r')
{
output_high(PIN_C3);
Motor_M1_On(100,1); //1=forward, 0=reverse
Motor_M2_On(100,0); //1=forward, 0=reverse
}
else if(ch == 'l')
{
output_high(PIN_C4);
Motor_M1_On(100,0); //1=forward, 0=reverse
Motor_M2_On(100,1); //1=forward, 0=reverse
}
else if(ch == 'u')
{
forward();
}
else if(ch == 'd')
{
reverse();
}
else if(ch == 'o')
{
forward();
}
else if(ch == 'c')
{
reverse();
}
else if(ch == 's')
{

167

Motor_M1_Off(100,0); //1=forward, 0=reverse


Motor_M2_Off(100,0); //1=forward, 0=reverse
}
delay_ms(50);
set_pwm1_duty(0);
set_pwm2_duty(0);
output_low(PIN_C4);
output_low(PIN_C5);
}
}

168

Você também pode gostar