GSM Based Industrial automation
1. INTRODUCTION1.1 Introduction to Project:Wireless
communication has announced its arrival on big stage and the world
is going mobile. We want to control everything and without moving
an inch. This remote control of appliances is possible through
Embedded Systems. The use of Embedded System in Communication has
given rise to many interesting applications that ensures comfort
and safety to human life. GSM (Global System for Mobile
communications) is an open, digital cellular technology used for
transmitting mobile voice and data services. Here we are using it
only for transmitting and receiving the messages. GSM wireless data
module is used for remote wireless applications, machine to machine
or user to machine and remote data communications in many
applications. The communication used in this project is the mobile
communication. GSM (GLOBAL SYSTEM FOR MOBILE COMMUNICATION) modem
is connected to the microcontroller through a MAX232 which is a TTL
level converter. GSM based Industrial automation implements the
emerging applications of the GSM technology. Using GSM networks, a
control system has been proposed that will act as an embedded
system which can monitor and control appliances and other devices
locally using built-in input and output peripherals. Remotely the
system allows the user to effectively monitor and control the
house/office appliances and equipments via the mobile phone set by
sending commands in the form of SMS messages and receiving the
appliances status.
ECE Department, RVRIET
1
GSM Based Industrial automation
The objective of this project is to develop a device that allows
for a user to remotely control and monitor multiple home/office
appliances using a cellular phone. This system will be a powerful
and flexible tool that will offer this service at any time, and
from anywhere with the constraints of the technologies being
applied. Possible target appliances include (but are not limited
to) climate control system, security systems, lights; anything with
an electrical interface. The proposed approach for designing this
system is to implement a microcontroller-based control module that
receives its instructions and command from a cellular phone over
the GSM network. The microcontroller then will carry out the issued
commands and then communicate the status of a given appliance or
device back to the cellular phone.
1.2 Background:The new age of technology has redefined
communication. Most people nowadays have access to mobile phones
and thus the world indeed has become a global village. At any given
moment, any particular individual can be contacted with the mobile
phone. But the application of mobile phone can not just be
restricted to sending SMS or starting conversations. New
innovations and ideas can be generated from it that can further
enhance its capabilities. Technologies such as Infra-red,
Bluetooth, etc which has developed in recent years goes to show the
very fact that improvements are in fact possible and these
improvements have eased our life and the way we live. Remote
management of several home and office appliances is a subject of
growing interest and in recent years we have seen many systems
providing such controls.
ECE Department, RVRIET
2
GSM Based Industrial automation
These days, apart from supporting voice calls a mobile phone can
be used to send text messages as well as multimedia messages (that
may contain pictures, graphics, animations, etc.). Sending written
text messages is very popular among mobile phone users. Instant
messaging, as it is also known, allows quick transmission of short
messages that allow an individual to share ideas, opinions and
other relevant information. We have used the very concept to design
a system that acts a platform to receive messages which in fact are
commands sent to control different appliances and devices connected
to the platform. We have designed a control system which is based
on the GSM technology that effectively allows control from a remote
area to the desired location. The application of our suggested
system is immense in the ever changing technological world. It
allows a greater degree of freedom to an individual whether it is
controlling the household appliances or office equipments. The need
to be physically present in order to control appliances of a
certain location is eliminated with the use of our system. With the
advancement and breakthroughs in technology over the years, the
lives of people have become more complicated and thus they have
become busier than before. With the adoption of our system, we can
gain control over certain things that required constant attention.
The application of our system comes in handy when people who forget
to do simple things such as turn ON or OFF devices at their home or
in their office, they can now do so without their presence by the
transmission of a simple text message from their mobile phone. This
development, we believe, will ultimately save a lot of time
especially when people dont have to come back for simple things
such as to turn ON/OFF switches at their home or at their office
once they set out for their respective work.
1.3 History of Embedded Systems:-
In the earliest years of computers in the 1930-40s, 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
ECE Department, RVRIET
3
GSM Based Industrial automation
programmable controllers evolved from traditional
electromechanical sequencers, via solid state devices, to the use
of computer technology. Since these early applications in the
1960s, embedded systems have come down in price and there has been
a dramatic rise in processing power and functionality. The first
microprocessor for example, the Intel 4004, was designed for
calculators and other small systems but still required many
external memory and support chips. In 1978 National Engineering
Manufacturers Association released a standard" for programmable
microcontrollers, including almost any computer-based controllers,
such as single board computers, numerical, and event-based
controllers. The integration of microcontrollers has further
increased the applications for which embedded systems are used into
areas where traditionally a computer would not have been
considered. A general purpose and comparatively low-cost
microcontroller may often be programmed to fulfill the same role as
a large number of separate components. Although in this context an
embedded system is usually more complex than a traditional
solution, most of the complexity is contained within the
microcontroller itself. The intangible nature of software makes it
much easier to prototype and test new revisions compared with the
design and construction of a new circuit not using an embedded
processor.
ECE Department, RVRIET
4
GSM Based Industrial automation
Figure 1.1: Blocks of an Embedded System Embedded Device
Technology is a transformational technology a technology that is
revolutionizing the way we function. Embedded Systems can be seen
everywhere from Wrist Watches, Washing Machines, Microwave Ovens
and Mobile Telephones to Automobiles, Aircrafts and Nuclear Power
Plants. Embedded Systems are the brains behind 90% of all
electronic devices worldwide. The explosion of Embedded System
Technology is expected to happen across product categories like
office products, consumer products, products, automobiles, medical
instrumentation, vending machines, communications infrastructure,
etc. An Embedded System is a combination of hardware and software
designed to control the additional hardware attached to the system.
The software system is completely encapsulated by the hardware that
it controls. Embedded system means the processor is embedded into
that application or it is meant for that specific application. Thus
printer, keyboard, and video game player etc. are all examples of
devices performing specific application.
ECE Department, RVRIET
5
GSM Based Industrial automation
In an Embedded System, there is only one application software
that is typically burned into ROM. An Embedded System is
time-constrained and often resourceconstrained. The brain of an
Embedded System is the processor. It may be generalpurpose
microprocessor like Intel x86 families or a microcontroller like
8051 family. An embedded product uses a microprocessor or
microcontroller to do one specific task only.
A microcontroller is a specific kind of microprocessor whose
primary job is to control the hardware it is attached to. A
microcontroller has more pins dedicated to carrying I/O signals as
compared to microprocessor. A Microcontroller has built-in memory
and peripherals (single-chip computer). Whereas a microprocessor
has memory and supporting peripherals externally connected.
1.4 Examples of embedded systems:1. Cellular telephones and
telephone switches 2. Engine controllers and antilock brake
controllers for automobiles 3. Household appliances, including
microwave ovens, DVD players 4. Automatic teller machines (ATMs) 5.
Home appliances such as fan, refrigerator and tube light etc. 6.
Hand held calculators. An embedded system typically has a
specialized function with programs stored on ROM. Examples of
embedded systems are chips that monitor automobile functions,
including engine controls, antilock brakes, air bags, active
suspension systems, environmental systems, security systems, and
entertainment systems. Everything needed for those functions is
custom designed into specific chips. No external operating system
is required.
ECE Department, RVRIET
6
GSM Based Industrial automation
Figure 1.2: Examples of Embedded Systems An embedded system is a
special-purpose computer system designed to perform a dedicated
function. Unlike a general-purpose computer, such as a personal
computer, an embedded system performs one or a few pre-defined
tasks, usually with very specific requirements, and often includes
task-specific hardware and mechanical parts not usually found in a
general-purpose computer. Since the system is dedicated to specific
tasks, design engineers can optimize it, reducing the size and cost
of the product. Embedded systems are often 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. In terms of complexity embedded systems run from simple,
with a single microcontroller chip, to very complex with multiple
units, peripherals and networks mounted inside a large chassis or
enclosure.
ECE Department, RVRIET
7
GSM Based Industrial automation
Mobile phones or handheld computers share some elements with
embedded systems, such as the operating systems and microprocessors
which power them, but are not truly embedded systems themselves
because they tend to be more general purpose, allowing different
applications to be loaded and peripherals to be connected. Network
managers will need to manage more and more embedded systems
devices, ranging from printers to scanners, to handheld computing
devices, to cell phones. All of these have a need to connect with
other devices, either directly or through a wireless or
direct-connect network. Most will have custom operating systems or
variations of existing operating systems (e.g., Microsoft Windows
CE). It's easy to picture nearly every electronic device as having
an embedded system. For example, refrigerators, washing machines,
and even coffee brewers will benefit in some way from embedded
systems. A critical feature of an embedded system is its ability to
communicate, so embedded systems support Ethernet, Bluetooth
(wireless), infrared, or other technologies. A weather station on
top of a building may employ an embedded system that gathers
information from external sensors. This information can be pushed
or pulled. In the push scenario, the data is automatically sent to
devices that have requested it. In the pull scenario, users or
network devices access the weather station to read the latest
information.
ECE Department, RVRIET
8
GSM Based Industrial automation
1.5 Organization of Thesis: Chapter 2 deals with the block
diagram of the project, and the Peripherals of the
project. Chapter 3 provides information on hardware design
Chapter 4 deals with software design Chapter 5 is all about testing
methodology Chapter 6 is about source code Chapter 7 is all about
project results
Chapter 8 provides the details conclusion and future scope
chapter 9 is about microcontroller
Chapter 10 is L293D Chapter 11 is about LM324 and IR Sensors
Chapter 12 is about index Chapter 13 is References
ECE Department, RVRIET
9
GSM Based Industrial automation
2. PLAN OF IMPLEMENTATION2.1 Block Diagram:-
Figure 2.1: Block Diagram
2.2 Micro Controller:A microcontroller is a small computer on a
single integrated circuit containing a processor core, memory and
programmable input/output peripherals. Microcontrollers are
designed for embedded applications, in contrast to the
microprocessors used in personal computers. Microcontrollers are
used in automatically controlled products and devices, such as
automobile engine control systems, implantable medical devices, and
remote
ECE Department, RVRIET
10
GSM Based Industrial automation
controls, office machines, appliances, power tools, and toys. By
reducing the size and cost compared to a design that uses a
separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more
devices and processes. Mixed signal microcontrollers are common,
integrating analog components needed to control non-digital
electronic systems.
2.3 DC Motor:A direct current (DC) motor is a fairly simple
electric motor that uses electricity and a magnetic field to
produce torque, which turns the motor. At its most simple, a DC
motor requires two magnets of opposite polarity and an electric
coil, which acts as an electromagnet. The repellent and attractive
electromagnetic forces of the magnets provide the torque that
causes the DC motor to turn. A DC motor requires at least one
electromagnet. This electromagnet switches the current flow as the
motor turns, changing its polarity to keep the motor running. The
other magnet or magnets can either be permanent magnets or other
electromagnets. Often, the electromagnet is located in the center
of the motor and turns within the permanent magnets, but this
arrangement is not necessary.
2.4 Liquid Crystal Display:A liquid crystal display (LCD) is a
thin, flat electronic visual display that uses the light modulating
properties of liquid crystals (LCs). LCs does not emit light
directly. LCDs are more energy efficient and offer safer disposal
than CRTs. Its low electrical power consumption enables it to be
used in battery-powered electronic equipment. It is an
electronically-modulated optical device made up of any number of
pixels filled with Liquid crystals and arrayed in front of a light
source (backlight) or reflector to produce images in colour or
monochrome.
ECE Department, RVRIET
11
GSM Based Industrial automation
2.5 Power Supply:A power supply is a device that supplies
electrical energy to one or more electric loads. The term is most
commonly applied to devices that convert one form of electrical
energy to another, though it may also refer to devices that convert
another form of energy (e.g., mechanical, chemical, solar) to
electrical energy. A power supply is one that controls the output
voltage or current to a specific value; the controlled value is
held nearly constant despite variations in either load current or
the voltage supplied by the power supply's energy source.
2.6 L293D Motor driver:Large amount of current is required to
run a motor. The microcontroller can drive only smaller currents.
So a motor driver is interfaced with the microcontroller to which
provides necessary current to drive the motors. It also acts as an
isolator in between the microcontroller and motors to protect the
microcontroller from the back e.m.f produced by the motors.
2.7 IR Tran receivers (TCRT5000):TheTCRT5000 is reflective
sensors which include an infrared emitter and phototransistor in a
leaded package which blocks visible light. We used two pairs of
sensors in our project one is for sensing minimum level and other
is for maximum level of water.
2.8 Relay:A relay is an electrically controllable switch widely
used in industrial controls, automobiles and appliances.
ECE Department, RVRIET
12
GSM Based Industrial automation
The relay allows the isolation of two separate sections of a
system with two different voltage sources i.e., a small amount of
voltage/current on one side can handle a large amount of
voltage/current on the other side but there is no chance that these
two voltages mix up. When current flows through the coil, a
magnetic field are created around the coil i.e., the coil is
energized. This causes the armature to be attracted to the coil.
The armatures contact acts like a switch and closes or opens the
circuit. When the coil is not energized, a spring pulls the
armature to its normal state of open or closed. There are all types
of relays for all kinds of applications.
2.9 LDR:LDRs or Light Dependent Resistors are very useful
especially in light/dark sensor circuits. Normally the resistance
of an LDR is very high, sometimes as high as 1000,000 ohms, but
when they are illuminated with light resistance drops dramatically.
LDR is light dependent resistor; its resistance in complete dark is
around 100 Kilo ohms that drops to few ohms depending upon
intensity of light. This sensor is quite frequently used by
students and hobbyists.
2.10 MAX232:The MAX232 is an integrated circuit that converts
signals from an RS-232 serial port to signals suitable for use in
TTL compatible digital logic circuits. The MAX232 is a dual
driver/receiver and typically converts the RX, TX, CTS and RTS
signals. The drivers provide RS-232 voltage level outputs (approx.
7.5 V) from a single + 5 V supply via on-chip charge pumps and
external capacitors. This makes it useful for implementing RS-232
in devices that otherwise do not need any voltages outside the 0 V
to + 5 V range, as power supply design does not need to be made
more complicated just for driving the RS-232 in this case. The
receivers reduce RS-232 inputs (which may be as high as 25 V), to
standard 5 V TTL levels.
ECE Department, RVRIET
13
GSM Based Industrial automation
2.11 4X4 Matrix Keypad:A keypad is a set of buttons arranged in
a block or "pad" which usually bear digits and other symbols and
usually a complete set of alphabetical letters. If it mostly
contains numbers then it can also be called a numeric keypad.
Keypads are found on many alphanumeric keyboards and on other
devices such as calculators, push-button telephones, combination
locks, and digital door locks, which require mainly numeric input.
In order to detect which key is pressed from the matrix, we make
row lines low one by one and read the columns. Lets say we first
make Row1 low, and then read the columns. If any one of the key in
row1 is pressed it will make the corresponding column as low i.e.
if second key is pressed in Row1, then the column2 will be low. So
we come to know that key 2 of Row1 is pressed. This is how scanning
is done.
2.12 GSM Module:Sim300 GSM Smart Modem is a multi-functional,
ready to use, rugged unit that can be embedded or plugged into any
application. The Smart Modem can be controlled and customized to
various levels by using the standard AT commands. The modem is
fully type-approved, it can speed up the operational time with full
range of Voice, Data, Fax and Short Messages (Point to Point and
Cell Broadcast).
ECE Department, RVRIET
14
GSM Based Industrial automation
3. HARDWARE DESIGN3.1 Design and interface of JHD162A with
AT89S52:Liquid Crystal Display also called as LCD is very helpful
in providing user interface as well as for debugging purpose. The
most common type of LCD controller is HITACHI 44780 which provides
a simple interface between the controller & an LCD. These LCD's
are very simple to interface with the controller as well as are
cost effective. The most commonly used ALPHANUMERIC displays are:A.
1x16 (Single Line & 16 characters), B. 2x16 (Double Line &
16 character per line), C. 4x20 (four lines & Twenty characters
per line).
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or
4) data lines. The number on data lines depends on the mode of
operation. If operated in 8-bit mode then 8 data lines + 3 control
lines i.e. total 11 lines are required. And if operated in 4bit
mode then 4 data lines + 3 control lines i.e. 7 lines are required.
How do we decide which mode to use? Its simple if you have
sufficient data lines you can go for 8 bit mode & if there is a
time constrain i.e. display should be faster than we have to use
8bit mode because basically 4-bit mode takes twice as more time as
compared to 8-bit mode. 3.1.1 Connections:The LCD has 3control
pins: a) RS: Register[To select command(RS=0) or data
register(RS=1)] b) R/W: Read/Write[To send read(R/W=1) or write
command (R/W=0)] c) E: Enable [To latch the data and command to
LCD(high to low transition)]. The LCD has 8 data pins [DB0 TO DB7]:
Pins on LCD are Pin-7 to Pin-14
ECE Department, RVRIET
15
GSM Based Industrial automation
3.1.2 Other Connections: The LED+ and LED- pins of LCD are used
for the Backlight of LCD. Vcc, Vee and Vss of LCD are used for
powering the LCD and controlling the contrast of LCD. When RS is
low (0), the data is to be treated as a command. When RS is high
(1), the data being sent is considered as text data which should be
displayed on the screen. When R/W is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the
program is effectively reading from the LCD. Most of the times
there is no need to read from the LCD so this line can directly be
connected to Ground thus saving one controller line. The ENABLE pin
is used to latch the data present on the data pins. A HIGH LOW
signal is required to latch the data. The LCD interprets and
executes our command at the instant the EN line is brought low. If
you never bring EN low, your instruction will never be executed.
PIN 1 2 3 4 5 6 7 8 9 10 11 12 13 14 SYMBOL VSS VCC VEE RS R/W EN
DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 I/O ---I I I/O I/O I/O I/O I/O I/O
I/O I/O I/O DESCRIPTION Ground +5V power supply Power supply to
control contrast RS=0 to select command register RS=1 to select
data register R/W=0 for write, R/W=1 for read Enable The 8-bit data
bus The 8-bit data bus The 8-bit data bus The 8-bit data bus The
8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit data
bus
Table 3.1: LCD Pin Description
3.2 LCD Interfacing to micro controller:ECE Department, RVRIET
16
GSM Based Industrial automation
Figure 3.1: LCD Interfacing To Micro Controller For Contrast
setting a 10K pot should be used as shown in the figure, Display
Data Ram (DDRAM) stores the display data. So when we have to
display a character on LCD we basically write it into DDRAM. For a
2x16 LCD the DDRAM address for first line is from 80h to 8fh &
for second line is 0c0h to 0cfh. So if we want to display
Table 3.2: LCD Commands to pins
3.3 Interfacing the Keypad to the Microcontroller:At the lowest
level, keyboards are organized in a matrix of rows and columns. The
CPU accesses both rows and columns through ports; therefore, with
two 8-bit ports, an 8x8 matrix of keys can be connected to a
microprocessor. When a key is pressed, a row and a column make a
contact; otherwise, there is no connection between
ECE Department, RVRIET
17
GSM Based Industrial automation
rows and columns. In IBM PC keyboards, a single microcontroller
(consisting of a microprocessor, RAM and EPROM, and several PORTS
all on a single chip) takes care of hardware and software
interfacing of the keyboard, in such systems, it is the function of
programs stored in the EPROM of the microcontroller to scan the
keys continuously, identify which one has been activated, and
present it to the motherboard. In this section we look at the
mechanism by which the microcontroller scans and identifies the
key. 3.3.1 Scanning and Identifying the Key:-
Figure 3.2: 4X4 Matrix Keypad Fig shows a 4x4 matrix connected
to two ports. The rows are connected to an output port and the
columns are connected to an input port. If no key has been pressed,
reading the input port will yield 1s for all columns since they are
all connected to high (Vcc). If all the rows are grounded and a key
is pressed, one of the columns will have 0 since the pressed
provides the path to ground. It is the function of the
microcontroller to scan the keyboard continuously to detect and
identify the key pressed. How it is done is explained next. 3.3.2
Grounding Rows and Reading the Columns:To detect a pressed key, the
microcontroller grounds all rows by providing 0 to the output
latch, and then it reads the columns. If the data read from the
columns is D3ECE Department, RVRIET 18
GSM Based Industrial automation
D0=1111, no key has been pressed and the process continues until
a key press is detected. However, if one of the column bits has a
0, this means that a key press has occurred. For Example, if
D3-D0=1101, this means that a key in the D1 column has been
pressed. After a key press is detected the microcontroller will go
through the process of identifying the key. Starting with the top
row, the microcontroller grounds it by providing a low to row D0
only; then it reads the columns. If the data reads is all 1s, no
key in that row is activated and the process is moved to the next
row. It grounds the next row, reads the columns, and checks for any
0. This process continues until the row is identified. After
identification of the row in which the key has been pressed, the
next task is to find out which column the pressed key belongs to.
This should be easy since the microcontroller knows at any time
which row and column are being accessed. 3.3.3 The Process of
Scanning a Key goes through the following 4 Steps:1. To make sense
that the preceding key has been released, 0s are output to all rows
at
once and the columns are read and checked repeatedly until all
the columns are high. When all columns are found to be high, the
program waits for a short amount of time before it goes to the next
stage of waiting for a key to be pressed.
2. To see if any key is pressed, the columns scanned over and
over in an infinite loop until one of them has a zero (0) on it.
Remember that the output latches connected to rows still have their
initial zeros making them grounded. After the key press detection
it waits 20ms for bounce and then scans the columns again. This
serves two functions It ensures that the first key detection was
not an erroneous one due to a spike noise and The 20ms delay
prevents the same key press from being interpreted as a multiple
key press .If after 20 ms delay the key is still pressed, it goes
to the
ECE Department, RVRIET
19
GSM Based Industrial automation
next stage to detect which row it belongs to ;otherwise it goes
back in to the loop to detect a read key press. 3. To detect which
row the key press belongs to, it grounds one row at a time reading
the column search time .If it finds that all columns are high this
means that the key press does not belongs to the row, therefore it
grounds the next row and continues until it finds the row key press
belongs to, it sets up the starting address for the look up table
holding the scan codes for that row and goes to The next stage to
identify the key. 4. To identify the key press, it rotates the
column bits one bit at a time in to the carry flag and check to see
if it is low. Upon finding the zero, it pulls out the (ASCII code)
character for that key from the look up table. Otherwise it
increments the pointer to point to the next element of the look up
table.
3.4 Interfacing L293 Driver to the Microcontroller:L293D is a
dual H-Bridge motor driver, So with one IC we can interface two DC
motors which can be controlled in both clockwise and counter
clockwise direction and if you have motor with fix direction of
motion the you can make use of all the four I/Os to connect up to
four DC motors. L293D has output current of 600mA and peak output
current of 1.2A per channel. Moreover for protection of circuit
from back
EMF ouput diodes are included within the IC. The output supply
(VCC2) has a wide range from 4.5V to 36V, which has made L293D a
best choice for DC motor driver.A simple schematic for interfacing
a DC motor using L293D is shown below.
ECE Department, RVRIET
20
GSM Based Industrial automation
Figure 3.3: interfacing of L293 As in the above figure, three
pins are needed for interfacing a DC motor (A, B, Enable). If you
want the o/p to be enabled completely then you can connect Enable
to VCC and only 2 pins needed from controller to make the motor
work. As per the truth mentioned in the image above its fairly
simple to program the microcontroller. Its also clear from the
truth table of BJT circuit and L293D the programming will be same
for both of them, just keeping in mind the allowed combinations of
A and B. We will discuss about programming in C as well as assembly
for running motor with the help of a microcontroller.
3.5 GSM modem:3.5.1 Introduction:-
ECE Department, RVRIET
21
GSM Based Industrial automation
Sim300 GSM Smart Modem is a multi-functional, ready to use,
rugged unit that can be embedded or plugged into any application.
The Smart Modem can be controlled and customized to various levels
by using the standard AT commands. The modem is fully
type-approved, it can speed up the operational time with full range
of Voice, Data, Fax and Short Messages (Point to Point and Cell
Broadcast). 3.5.2 Description of the interfaces:The modem comprises
several interfaces: LED Function including operating Status
External antenna Serial and control link Power Supply SIM card
holder
3.5.3 LED Status Indicator:The LED will indicate different
status of the modem: OFF ON Flashing Slowly Flashing rapidly Modem
Switched off Modem is connecting to the network Modem is in idle
mode Modem is in transmission/communication (GSM only)
GSM is one of the latest mobile technologies using smart MODEM,
which can easily interfaced to embedded microcontrollers. Now
everything is going to be automated using this technology, using
this technology we can access the devices remotely. Using GSM and
GPS now we can identify the people, vehicles etc in anywhere of the
world.
MODEM is communicating with the microcontroller using AT
commands, for example if we want to send an SMS to number
98xxxxxxxxx,the commands we have to send is AT+CMGS=, , , .
ECE Department, RVRIET
22
GSM Based Industrial automation
Figure 3.4 GSM checking HyperTerminal snapshot In this project
it is used to send SMS to the mobile In this project MODEM is
communication with the microcontroller through serial port, the
microcontroller will send the commands to the modem through RS
232.and the data is read through serial port therefore to make
compatible computer serial port with microcontroller serial port we
are using the RS 232 converter. The GSM module has GSM modem, DB9
connector, MAX 232 line driver for its communication with the
microcontroller. Since the operating voltage different for the
microcontroller and the modem, the MAX 232 is used which provides
the electrical interface between an asynchronous communication
controller and the serial port connector .The serial port connector
here is DB9 connecter. The microcontroller has TTL logic levels for
TXD, RXD pins and for RS232 different voltage levels logics. So for
proper communications MAX232 is used to convert RS 232 voltages to
TTL logic voltage levels. The baud rate is set to 9,600 bits/s. GSM
modems in use has baud rate of 9600 bits/sec. It enables us to send
and receive 30 messages at a time. With GSM modems, you must insert
a valid SIM card into the slot on the front of the modem. Once the
modem has been prepared for use, connect it to a serial port on
your PC using the data cable that is included with the modem.
ECE Department, RVRIET
23
GSM Based Industrial automation
Figure 3.5 GSM module interface with AT89S52
3.6 Reset Circuit:High logical state on this input halts the MCU
and clears all the registers. Bringing this pin back to logical
state zero starts the program a new as if the power had just been
turned on. In another words, positive voltage impulse on this pin
resets the MCU. Depending on the device's purpose and environs,
this pin is usually connected to the push-button, reset-upon-start
circuit or a brown out reset circuit. The image shows one simple
circuit for safe reset upon starting the controller. It is utilized
in situations when power fails to reach its optimal voltage. 3.7.
Crystal Oscillator Circuit:Input(X1) and output(X2) of internal
oscillator. Quartz crystal controlling the frequency commonly
connects to these pins. Capacitances within the oscillator
mechanism are not critical and are normally about 30pF. Instead of
a quartz crystal, miniature ceramic resonators can be used for
dictating the pace.
ECE Department, RVRIET
24
GSM Based Industrial automation
3.8 Schematic diagram:-
Figure 3.6: Schematic diagram
4. SOFTWARE DESIGN4.1 Cross Complier:-
ECE Department, RVRIET
25
GSM Based Industrial automation
A cross
compiler is
a compiler capable
of
creating executable code
for
a platform other than the one on which the compiler is run.
Cross compiler tools are used to generate executable for embedded
system or multiple platforms. It is used to compile for a platform
upon which it is not feasible to do the compiling, like
microcontrollers that don't support an operating system. It has
become more common to use this tool for Para virtualization where a
system may have one or more platforms in use. Not targeted by this
definition are source to source translators, which are often
mistakenly called cross compilers.
4.1.1 Uses of Cross Compliers:The fundamental use of a cross
compiler is to separate the build environment from target
environment. This is useful in a number of situations: Embedded
computers where a device has extremely limited resources. For
example, a microwave oven will have an extremely small computer to
read its touchpad and door sensor, provide output to a digital
display and speaker, and to control the machinery for cooking food.
This computer will not be powerful enough to run a compiler, a file
system, or a development environment. Since debugging and testing
may also require more resources than are available on an embedded
system, crosscompilation can be less involved and less prone to
errors than native compilation. Compiling for multiple machines.
For example, a company may wish to support several different
versions of an operating system or to support several different
operating systems. By using a cross compiler, a single build
environment can be set up to compile for each of these targets.
Compiling on a server farm. Similar to compiling for multiple
machines, a complicated build that involves many compile operations
can be executed across any machine that is free, regardless of its
underlying hardware or the operating system version that it is
running.
Boot strapping to a new platform. When developing software for a
new platform, or the emulator of a future platform, one uses a
cross compiler to compile
ECE Department, RVRIET
26
GSM Based Industrial automation
necessary tools such as the operating system and a native
compiler. Compiling native code for emulators for older
now-obsolete platforms like the Commodore 64 or Apple II by
enthusiasts who use cross compilers that run on a current platform
(such as Aztec C's MS DOS 6502 cross compilers running under
Windows XP).
4.2 Embedded driver code for LCD:Before starting to display on
LCD we need to initialize it. Firstly we must tell the LCD whether
we'll be using 8-bit or 4-bit mode. Also we will be telling the LCD
that we need 5x8 character font. Both these options are selected
using a single command i.e. 38h. So to activate both these options
we must execute following instructions.
4.3 Basic Commands of LCD:When LCD is powered up the display
should show a series of dark squares, possibly only on part of
display. These characters are actually in their off state, so the
contrast control should be adjusted anti-clockwise until the
squares are just visible. The display module resets itself to an
initial state when power is applied, which curiously the display
has blanked off so that even if characters are entered, they cannot
be seen. It is therefore necessary to issue a command at this
point, to switch the display on.
4.3.1 Circuit Description of LCD Experiment:The circuit can be
wired up on a plug-in-style prototyping board, using dual-inline
switches for the data lines (S1-S8). A toggle switch for the RS
input (S10) and a momentary action switch (or macro switch) for
usage.
Most of the LCD modules conform to a standard interface
specification. A 14pin access is provided having eight data lines,
three control lines and three power
ECE Department, RVRIET
27
GSM Based Industrial automation
lines. The connections are laid out in one of the two common
configurations, either two rows of seven pins, or a single row of
14 pins. One of the, pins are numbered on the LCDs print circuit
board (PCB), but if not, it is quite easy to locate pin1. Since
this pin is connected to ground, it often has a thicker PCB track,
connected to it, and it is generally connected to metalwork at same
point. The LCD requires either 8 or 11 I/O lines to communicate
with. For the sake of this tutorial, e going to use an 8-bit data
bus--so we'll be using 11 of the 8051's I/O pins to interface with
the LCD. A 1-to-1 relation is established between a pin on the 8051
and a line on the 44780 LCD. Thus write assembly program to access
the LCD, and equate constants to the 8051 ports so that refer to
the lines by their 44780 name as opposed to P0.1, P0.2, etc. DB0
EQU P1.0 DB1 EQU P1.1 DB2 EQU P1.2 DB3 EQU P1.3 DB4 EQU P1.4 DB5
EQU P1.5 DB6 EQU P1.6 DB7 EQU P1.7 EN EQU P3.7 RS EQU P3.6 RW EQU
P3.5 DATA EQU P1 Having established the above equates, we may now
refer to our I/O lines by their 44780 name. For example, to set the
RW line high (1), we can execute the following instruction: SETB
RW
4.3.2 Handling the EN Control Line:-
ECE Department, RVRIET
28
GSM Based Industrial automation
As mentioned above, the EN line is used to tell the LCD that you
are ready for it to execute an instruction that you've prepared on
the data bus and on the other control lines. Note that the EN line
must be raised/lowered before/after each instruction sent to the
LCD regardless of whether that instruction is read or write text or
instruction. In short, you must always manipulate EN when
communicating with the LCD. EN is the LCD's way of knowing that you
are talking to it. If you don't raise/lower EN, the LCD doesn't
know you're talking to it on the other lines. Thus, before we
interact in any way with the LCD we will always bring the EN line
low with the following instruction: CLR EN And once finished
setting up instruction with the other control lines and data bus
lines, we'll always bring this line high: SETB EN The line must be
left high for the amount of time required by the LCD as specified
in its datasheet. This is normally on the order of about 250
nanoseconds, but checks the datasheet. In the case of a typical
8051 running at 12 MHz, an instruction requires 1.08 microseconds
to execute so the EN line can be brought low the very next
instruction. However, faster microcontrollers (such as the DS89C420
which executes an instruction in 90 nanoseconds given an 11.0592
Mhz crystal) will require a number of NOPs to create a delay while
EN is held high. The number of NOPs that must be inserted depends
on the microcontroller you are using and the crystal you have
selected.The instruction is executed by the LCD at the moment the
EN line is brought low with a final CLR EN instruction. Programming
Tip: The LCD interprets and executes our command at the instant the
EN line is brought low. If you never bring EN low, your instruction
will never be executed. Additionally, when you bring EN low and the
LCD executes your instruction, it requires a certain amount of time
to execute the command. The time it requires to execute an
instruction depends on the instruction and the speed of the crystal
which is attached to the 44780's oscillator input. 4.3.3 Checking
the Busy Status of the LCD:-
ECE Department, RVRIET
29
GSM Based Industrial automation
As previously mentioned, it takes a certain amount of time for
each instruction to be executed by the LCD. The delay varies
depending on the frequency of the crystal attached to the
oscillator input of the 44780 as well as the instruction which is
being executed. While it is possible to write code that waits for a
specific amount of time to allow the LCD to execute instructions,
this method of "waiting" is not very flexible. If the crystal
frequency is changed, the software will need to be modified.
Additionally, if the LCD itself is changed for another LCD which,
although 44780 compatible, requires more time to perform its
operations, the program will not work until it is properly
modified. A more robust method of programming is to use the "Get
LCD Status" command to determine whether the LCD is still busy
executing the last instruction received. The "Get LCD Status"
command will return to us two tit-bits of information; the
information that is useful to us right now is found in DB7. In
summary, when we issue the "Get LCD Status" command the LCD will
immediately raise DB7 if it's still busy executing a command or
lower DB7 to indicate that the LCD is no longer occupied. Thus our
program can query the LCD until DB7 goes low, indicating the LCD is
no longer busy. Since programmer use this code every time we send
an instruction to the LCD, it is useful to make it a subroutine.
Let's write the code: WAIT_LCD: CLR RS ;It's a command SETB RW
;It's a read command MOV DATA,#0FFh ;Set all pins to FF initially
SETB EN ;Clock out command to LCD MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy CLR EN ;Finish the
command CLR RW ;Turn off RW for future commands Thus, standard
practice will be to send an instruction to the LCD and then call
our WAIT_LCD routine to wait until the instruction is completely
executed by the
ECE Department, RVRIET
30
GSM Based Industrial automation
LCD. This will assure that our program gives the LCD the time it
needs to execute instructions and also makes our program compatible
with any LCD, regardless of how fast or slow it is. Programming
Tip: The above routine does the job of waiting for the LCD, but was
it to be used in a real application a very definite improvement
would need to be made: as written, if the LCD never becomes "not
busy" the program will effectively "hang," waiting for DB7 to go
low. If this never happens, the program will freeze. Of course,
this should never happen and won't happen when the hardware is
working properly. But in a real application it would be wise to put
some kind of time limit on the delay--for example, a maximum of 256
attempts to wait for the busy signal to go low. This would
guarantee that even if the LCD hardware fails, the program would
not lock up. 4.3.4 Initializing the LCD:Before using the LCD, it
must initialize and configure it. This is accomplished by sending a
number of initialization instructions to the LCD. The first
instruction send must tell the LCD whether be communicating with it
with an 8-bit or 4-bit data bus. Also select a 5x8 dot character
font. These two options are selected by sending the command 38h to
the LCD as a command. Thus, to send this 38h command to the LCD
must execute the following 8051 instructions: CLR RS MOV DATA,#38h
SETB EN CLR EN LCALL WAIT_LCD Programming Tip: The command 06h is
really the instruction 04h plus 02h to configure the LCD such that
every time we send it a character, the cursor position
automatically moves to the right So, in all, initialization code is
as follows: INIT_LCD:
ECE Department, RVRIET
31
GSM Based Industrial automation
CLR RS MOV DATA,#38h SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV
DATA,#0Eh SETB EN CLR EN LCALL WAIT_LCD CLR RS MOV DATA,#06h SETB
EN CLR EN LCALL WAIT_LCD RET Having executed this code the LCD will
be fully initialized and ready to send display data to it. 4.3.5
Clearing the Display:When the LCD is first initialized, the screen
should automatically be cleared by the 44780 controller. An LCD
command exists to accomplish this function. Not surprisingly, it is
the command 01h. Since clearing the screen is a function very
likely will wish to call more than once, it's a good idea to make
it a subroutine: CLEAR_LCD: CLR RS MOV DATA, #01h SETB EN
ECE Department, RVRIET
32
GSM Based Industrial automation
CLR EN LCALL WAIT_LCD RET How that we've written a "Clear
Screen" routine, may clear the LCD at any time by simply executing
an LCALL CLEAR_LCD. Programming Tip: Executing the "Clear Screen"
instruction on the LCD also positions the cursor in the upper
left-hand corner 4.3.6 Writing Text to the LCD:Writing text to the
LCD is something we'll almost certainly want to do over and
over--so let's make it a subroutine. WRITE_TEXT: SETB RS MOV DATA,
A SETB EN CLR EN LCALL WAIT_LCD RET The WRITE_TEXT routine that
wrote will send the character in the accumulator to the LCD which
will, in turn, display it. Thus to display text on the LCD all need
to do is load the accumulator with the byte to display and make a
call to this routine. A "HELLO WORLD" Program Now that we have all
the component subroutines written, writing the classic "Hello
World" program--which displays the text "Hello World" on the LCD is
a relatively trivial matter. Consider: LCALL INIT_LCD LCALL
CLEAR_LCD MOV A,#'H' LCALL WRITE_TEXT
ECE Department, RVRIET
33
GSM Based Industrial automation
MOV A,#'E' LCALL WRITE_TEXT MOV A,#'L' LCALL WRITE_TEXT MOV
A,#'L' LCALL WRITE_TEXT MOV A,#'O' LCALL WRITE_TEXT MOV A,#' '
LCALL WRITE_TEXT MOV A,#'W' LCALL WRITE_TEXT MOV A,#'O' LCALL
WRITE_TEXT MOV A,#'R' LCALL WRITE_TEXT MOV A,#'L' LCALL WRITE_TEXT
MOV A,#'D' LCALL WRITE_TEXT The above "Hello World" program should,
when executed, initialize the LCD, clear the LCD screen, and
display "Hello World" in the upper left-hand corner of the display.
4.3.7 Cursor Positioning:The above "Hello World" program is
simplistic in the sense that it prints its text in the upper
left-hand corner of the screen. However, what if we wanted to
display the word "Hello" in the upper left-hand corner but wanted
to display the word "World" on the second line at the tenth
character? This sounds simple--and actually, it is simple. However,
it requires a little more understanding of the design of the
ECE Department, RVRIET
34
GSM Based Industrial automation
LCD.The 44780 contains a certain amount of memory which is
assigned to the display. All the text we write to the 44780 is
stored in this memory, and the 44780 subsequently reads this memory
to display the text on the LCD itself. This memory can be
represented with the following "memory map": In the above memory
map, the area shaded in blue is the visible display. As you can
see, it measures 16 characters per line by 2 lines. The numbers in
each box is the memory address that corresponds to that screen
position. Thus, the first character in the upper left-hand corner
is at address 00h. The following character position (character #2
on the first line) is address 01h, etc. This continues until we
reach the 16th character of the first line which is at address 0Fh.
However, the first character of line 2, as shown in the memory map,
is at address 40h. This means if we write a character to the last
position of the first line and then write a second character, the
second character will not appear on the second line. That is
because the second character will effectively be written to address
10h--but the second line begins at address 40h. Thus we need to
send a command to the LCD that tells it to position the cursor on
the second line. The "Set Cursor Position" instruction is 80h. To
this we must add the address of the location where we wish to
position the cursor. In our example, we said we wanted to display
"World" on the second line on the tenth character position.
Referring again to the memory map, we see that the tenth character
position of the second line is address 4Ah. Thus, before writing
the word "World" to the LCD, we must send a "Set Cursor Position"
instruction--the value of this command will be 80h (the instruction
code to position the cursor) plus the address 4Ah. 80h + 4Ah = CAh.
Thus sending the command CAh to the LCD will position the cursor on
the second line at the tenth character position: CLR RS MOV
DATA,#0CAh SETB EN
ECE Department, RVRIET
35
GSM Based Industrial automation
CLR EN LCALL WAIT_LCD The above code will position the cursor on
line 2, character 10. To display "Hello" in the upper left-hand
corner with the word "World" on the second line at character
position 10 just requires us to insert the above code into our
existing "Hello World" program. This results in the following: CALL
lcd_command Now that we have to Turn On the display & set the
cursor option i.e. cursor ON/OFF & Cursor blinking ON/OFF for
that we will use the command 0Eh i.e. Display On , Cursor ON but
Cursor blinking OFF. MOV A,#0Eh CALL lcd_command And the last
command we require is to configure the LCD in such a way that
everytime we send a character to it the cursor position
automatically increments by one & moves to right i.e. 06h. MOV
A,#06h CALL lcd_command The lcd_initialize contains the following
instructions lcd_initialize: MOV A,#38h CALL lcd_command MOV A,
#38h CALL lcd_command MOV A,#38h CALL lcd_command Ret
ECE Department, RVRIET
36
GSM Based Industrial automation
4.4 Flow Chart for displaying data on screen:-
Fig Flowchart for LCD
4.5 LCD Test Code to Display a Message on Screen:#include sbit
r0=P1^0; sbit r1=P1^1; sbit r2=P1^2;
ECE Department, RVRIET
37
GSM Based Industrial automation
sbit r3=P1^3; sbit c0=P1^4; sbit c1=P1^5; sbit c2=P1^6; sbit
c3=P1^7; sfr ldata=0x80; sbit rs=P2^7; sbit rw=P2^6; sbit en=P2^5;
sbit busy=P0^7; void lcdcmd(unsigned char); void lcddata(unsigned
char); void lcdready(void); void MSDelay(unsigned int); void
WriteString(unsigned char,unsigned char *); unsigned char
KeyTest(void); void Start(void); void LCDClear(void); void lcdcmd
(unsigned char value) { lcdready(); ldata=value; rs=0; rw=0; en=1;
MSDelay(1); en=0; } void lcddata (unsigned char value) {
lcdready();
ECE Department, RVRIET
38
GSM Based Industrial automation
ldata=value; rs=1; rw=0; en=1; MSDelay(1); en=0; } void
lcdready(void) { busy=1; rs=0; rw=1; while(busy==1) { en=0;
MSDelay(1); en=1; } } void MSDelay(unsigned int Iter) { unsigned
int i, j; for(i=0;iI/O Ports=>Port N from the pulldown menus,
where is the port number. A checked box in the port window
indicates a high (1) pin, and an empty box indicates a low (0) pin.
Both the I/O port data and the data at the left side of the screen
are updated whenever the program is paused. The debugger will help
eliminate many programming errors, however the simulation is not
perfect and code that executes properly in simulation may not
always work on the actual microcontroller.
ECE Department, RVRIET
47
GSM Based Industrial automation
5.3 Device Database:A unique feature of the Keil Vision3 IDE is
the Device Database, which contains information about more than 400
supported micro controllers. When you create a new n e w Vision3
project and select the target chip from the database, Vision3 sets
all assembler, compiler, linker, and debugger options for you. The
only option you must configure is the memory map.
5.4 Peripheral Simulation:The Vision3 Debugger provides complete
simulation for the CPU and on-chip peripherals of most embedded
devices. To discover which peripherals of a device are supported,
in Vision3 select the Simulated Peripherals item from the Help
menu. You may also use the web-based Device Database. We are
constantly adding new devices and simulation support for on-chip
peripherals so be sure to check Device Database often.
5.5 Programmer:The programmer used is a powerful programmer for
the Atmel 89 series of microcontrollers that includes 89C51/52/55,
89S51/52/55 and many more. It is simple to use & low cost, yet
powerful flash microcontroller programmer for the Atmel 89 series.
It will Program, Read and Verify Code Data, Write Lock Bits, Erase
and Blank Check. All fuse and lock bits are programmable. This
programmer has intelligent onboard firmware and connects to the
serial port. It can be used with any type of computer and requires
no special hardware. All that is needed is a serial communication
port which all computers have. All devices also have a number of
lock bits to provide various levels of software and programming
protection. These lock bits are fully programmable using this
programmer. Lock bits are useful to protect the program to be read
back from micro controller only allowing erase to reprogram the
micro controller. Major parts of this programmer are Serial Port,
Power
ECE Department, RVRIET
48
GSM Based Industrial automation
Supply and Firm ware microcontroller. Serial data is sent and
received from 9 pin connector by MAX232 chip. A Male to Female
serial port cable, connects to the 9 pin connector of hardware and
another side connects to back of computer. All the programming
intelligence is built into the programmer so you do not need any
special hardware to run it. Programmer comes with window based
software for easy programming of the devices.
5.6 Pro Load Programming Software:Pro Load is a software working
as a user friendly interface for programmer boards from Sun ROM
Technologies. Pro Load gets its name from Program Loader term,
because that is what it is supposed to do. It takes in compiled HEX
file and loads it to the hardware. Any compiler can be used with
it, Assembly or C, as all of them generate compiled HEX files. Pro
Load accepts the Intel HEX format file generated from compiler to
be sent to target microcontroller. It auto detects the hardware
connected to the serial port. It also auto detects the chip
inserted and bytes used. The software is developed in Delhi and
requires no overhead of any external DLL. The programmer connects
to the computers serial port (Comm 1, 2, 3 or 4) with a standard
DB9 Male to DB9 Female cable. Baud Rate - 57600, COMx Automatically
selected by window software. No PC Card Required. After making the
necessary selections, the Auto Program button is clicked as shown
in the figure below which burns the selected hex file onto the
microcontroller.
ECE Department, RVRIET
49
GSM Based Industrial automation
Figure: 5.7 Programming window
ECE Department, RVRIET
50
GSM Based Industrial automation
6. SOURCE CODE
#include sbit r0=P1^0; //keypad rows sbit r1=P1^1; sbit r2=P1^2;
sbit r3=P1^3; sbit c0=P1^4; //keypad columns sbit c1=P1^5; sbit
c2=P1^6; sbit c3=P1^7; sfr ldata=0x80; // PORT0 for SFR address(LCD
data pins) sbit rs=P2^7; sbit rw=P2^6; sbit en=P2^5; sbit
busy=P0^7; //RS set for Giving the Command or Data // Read/write
command for the data in the LCD RAM // Enable Bit of the LCD //busy
pin of the controller
sbit Motor_In1=P2^0; sbit Motor_In2=P2^3; sbit en1=P2^1; sbit
sense1=P3^2; sbit sense2=P3^3; void lcdcmd (unsigned char); void
lcddata (unsigned char); void lcdready(void); void MSDelay(unsigned
int); void WriteString(unsigned char,unsigned char *); unsigned
char KeyTest(void); void Start(void); void LCDClear(void); void
MainMenu(void);
ECE Department, RVRIET
51
GSM Based Industrial automation
void UpdateService(void); unsigned char
MY_PWD[4]={'1','2','3','4'};
void lcdcmd (unsigned char value) { lcdready(); ldata=value;
rs=0; rw=0; en=1; MSDelay(1); en=0; } void lcddata (unsigned char
value) { lcdready(); ldata=value; rs=1; rw=0; en=1; MSDelay(1);
en=0; } void lcdready(void) { busy=1; rs=0; rw=1; while(busy==1) {
en=0; MSDelay(1);ECE Department, RVRIET 52
GSM Based Industrial automation
en=1;
} } void MSDelay(unsigned int Iter) { unsigned int i, j;
for(i=0;i