You are on page 1of 65

CHAPTER 1

INTRODUCTION
1.1 OVERVIEW
From the early days till today meter reading for electricity consumption and billing is
done by human operators from houses to houses. This therefore requires a very large number of
human operators and long working hours to acquire complete data reading and billing in a
particular area. However, there may be cases where human operators miss to bill few houses in
an area or restricted and slowed down by bad weather condition, transportation problems, etc.
Moreover human operators are very much likely to make mistake while billing or reading a
meter and sometimes the houses electric power meter may be placed in a location where it is not
easily accessible. Again printed billing has the tendency of being lost in the mail box or being
never delivered. Day by day due to the increasing number of residential housings and
commercial buildings, more human operators and longer working hours is needed to complete
the meter reading task which eventually increases the energy provider operation costs for meter
reading.
To achieve efficient meter reading, reduce billing error and operation costs, an Automatic
Electric Meter reading system can be introduced with every energy meter in an area. It is an
effective means of data collection that allow substantial saving through the reduction of meter re
read, greater data accuracy, frequent reading, improved billing and customer service, more
energy profiles and consumption trends updates and better deployment of human resource.
"Electricity meter reading using GSM" implements the emerging applications of the
GSM technology. GSM is a Global system for mobile communication (GSM) and is a wide area
wireless communications system that uses digital radio transmission to provide voice, data, and
multimedia communication services. A GSM system coordinates the communication between
mobile telephones (mobile stations), base stations (cell sites), and switching systems. Each GSM
radio channel is 200 KHz wide channels that are further divided into frames that hold 8 time
slots. The GSM system includes mobile telephones (mobile stations), radio towers (base
stations), and interconnection switching systems. We have selected a particular GSM modem
1

SIM300 for our project. The message are sent from the mobile set that contain commands in
written form which are then processed accordingly to perform the required task. The proposed
approach for designing this system is to implement 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. First, the sent SMS is stored and polled
from the receiver mobile station and then the required control signal is generated and sent to the
intermediate hardware that we have designed according to the command received in form of the
sent message.

1.2 OBJECTIVE OF THE PROJECT


The main objectives of the project are:
(i) To co-ordinate appliances and other devices through Short Message Service (SMS).
(ii) To efficiently receive and transmit data via SMS.
(iii) Minimize power and time wastage.
(iv) To eliminate the need of being physically present in any location for tasks involving the
operation of appliances within a household/office.
(v) To design a circuit that can automatically switch ON and OFF the home appliance.

1.3 NEED FOR GSM BASED EB SYSTEM WITH LOAD CONTROL


The present day electricity billing (EB) system therefore requires a very large number of
human operators and long working hours to acquire complete data reading and billing in a
particular area. Inorder to reduce the man power and to save time automation in billing system is
required. This automation is achieved by interfacing a GSM module along with the energy meter.
The GSM module is interfaced using a microcontroller.
The GSM module gets the meter reading and it sends the current reading information to
the customers mobile in the form of SMS. The customers mobile number is to be registered
before in the GSM module. There for the billing information is sent to the electricity distribution
office and even to the user .Therefore a lot of time is saved and man power requirement is also
reduced. Certain attempts have been made to achieve automation in electricity billing system.

Many companies came up with automatic meter reading system with GSM and few
companies came up with smart home technologies which involve control of home appliances.
Here control of home appliances includes ON and OFF of electrical and electronic home
appliances. Our project involves both automatic meter reading system and load control system.
Therefore our project provides billing information to the user as well as also helps the user to
control the load (home appliance).

1.4 RELATED WORK


This section provides a previous study of related work regarding the application of SMS
services in a various fields. Some previous researches have been studied to gain more
information about current existing GSM control system that was previously implemented. It is
necessary to know and understand how the software and hardware were used in the SMS
controlled system development. This is to ensure that the study that currently being conducted
contribute at certain level of application thus it become more efficient and practical. Several
smart home projects such as Home Security with Messaging System , Security & Control System
, and Remote and Security Control via SMS were the three alarm system that were designed
using SMS application to securely monitor the home condition when the owner are away or at
night. A system as suggested by messaging system triggered by SMS to the home owner to notify
the owner of any incident happened around the house such as robbery or fire.
Meanwhile, the system developed by tan, H.G.R Lee, C.H.R Mok is automating the
power reading meter to send the energy consumed to e-billing system at authorized office. The
system works by integrating the GSM modem that was embedded with digital kWh power meter.
It utilizes the GSM network to send power usage reading using SMS to the authorized office.
The authorized office collect and manage the received SMS message contains the meter reading
to generate the billing cost and send back the cost to the respective consumer through SMS. The
work presented by mohd helmy is about the development of Integrated Water Billing System
with SMS capability. The system is designed to facilitate the Water authorized to manage the
monthly billing system without the use of human services. The system receives SMS from the
meter to central databases. Then the information received is processed to generate current billing.
The system again sends a SMS notification to the user regarding the total amount that has been
3

billed. The system was implemented using Visual Basic and database in order to perform the
prototype and the system works successfully in sending SMS to user for notification.

1.5 PROBLEM FORMULATION


The Electricity meter reading using GSM system takes the advantage of existing GSM
infrastructure that have virtually full coverage of all housing and building area across the country
which lead to low infrastructure implementation cost, simple and easy installation of GSM
system at consumer side as this system is no difference from existing ordinary analogue or digital
meter installation. The complete Electricity Meter Reading Using GSM required an ICT
expertise personnel to setup, run and maintain all the servers. The Electricity Meter Reading
Using GSM provides effective, reliable and efficient wireless automatic electric meter readiFng,
billing and notification through the use of GSM network, thus reducing human operator meter
reading operation cost.
The importance of proposed work can be well understood if we keep in mind the amount
of electricity being stolen every day. As a user can get his or her bill at any instant and can even
pay it at any instant, so any kind of misuse by any other person can be avoided. The message are
sent from the mobile set that contain commands in written form which are then processed
accordingly to perform the required task.
The proposed approach for designing this system is to implement 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. First, the sent SMS is stored and
polled from the receiver mobile station and then the required control signal is generated and sent
to the intermediate hardware that we have designed according to the command received in form
of the sent message

CHAPTER 2
HARDWARE DEVELOPMENT
2.1 BLOCK DIAGRAM

Figure 2.1 Block diagram of GSM based electricity system with load control

BLOCKS
Transformer
Rectifier
Voltage Regulator
Micro Controller
Energy Meter
Comparator
GSM Modem
Crystal Oscillator
Relay Driver
Relay
Load
LCD Display

COMPONENT USED
Step down transformer
Bridge rectifier
LM7805
AT89S52
Electro-mechanical type
LM358
SIM 300
11.0592 MHz
ULN2003A
SPDT Relay
Any electrical appliance
162 LCD Display

Table 2.1 Block description

2.2 POWER SUPPLY


Every electronic system whether an entertainment gadget or a test and measurement
equipment requires one or more than one DC voltages for its operation, most of the time it is
essential and almost always desirable that these DC voltages are nicely filtered and well
regulated. Power supply does the job of providing required DC voltages from available AC
mains in case of mains operated systems and DC input in case of portable systems. Power
supplies are often classified as linear power supplies depending upon the nature of regulation
circuit.

Figure 2.2 Block Diagram of Power Supply


Linear power supply unit essentially comprises of:

Mains Transformer
Rectifier
Filter
Regulator
Here 5V D.C. output is used as power supply to AT89S52 Microcontroller, RF

Transmitter & Receiver pair and LCD display etc and 12 Volt D.C. power supply is mainly used
for relays.

2.2.1 DESCRIPTION OF A POWER SUPPLY UNIT


A 220v ac to 12-0-12v transformer is used and for rectification, four diodes IN4007 are
connected for rectification of the step down ac supply. Filter capacitor of 1000F is used. It is
regulated to +5v using a regulator 7805.
2.2.1.1 Transformer
A bridge rectifier coupled with a step down transformer is used for our design. The
voltage rating of transformer used is 0-12V and the current rating is 500mA. When AC voltage
of 230V is applied across the primary winding an output AC voltage of 12V is obtained. One
alteration of input causes the top of transformer to be positive and the bottom negative. The next
alteration will temporarily cause the reverse.
2.2.1.2 Rectifier
In the power supply unit, rectification is normally achieved using a solid state
diode. Diode has the property that will let the electron flow easily at one direction at proper
biasing condition. Bridge rectifiers of 4 diodes are used to achieve full wave rectification. Two
diodes will conduct during the negative cycle and the other two will conduct during the positive
half cycle.

2.2.1.3 Filtering Unit


7

Filter circuit which is usually a capacitor acts as a surge arrester always follows the
rectifier unit. This capacitor is also called as a decoupling capacitor or a bypass capacitor, is used
not only to short the ripple with frequency to ground but also leave the frequency of the DC to
appear at the output.
2.2.1.4 Voltage Regulators
The voltage regulators play an important role in any power supply unit. The
primary purpose of a regulator is to aid the rectifier and filter circuit in providing a constant DC
voltage to the device. Power supplies without regulators have an inherent problem of changing
DC voltage values due to variations in the load or due to fluctuations in the AC line voltage.
With a regulator connected to DC output, the voltage can be maintained within a close tolerant
region of the desired output.

Figure 2.3 LM7805


2.2.2 OPERATION
The transformer provides voltage transformation and produces AC voltage required for
producing the desired DC voltages across its secondary windings. It also provides electrical
isolation between the power supply input i.e., AC mains and output. The rectifier circuit changes
the AC voltages appearing at transformer secondary to DC. Commonly used rectifier circuits
include half-wave rectifier, conventional full-wave rectifier requiring a tapped secondary or a
bridge rectifier.

Figure 2.4 A Simple 5V DC Regulated Power System


The rectified voltage will always have some AC content known as power supply
ripple. The filter circuit levels the ripple of the rectified voltage. The filtering action of the
capacitor connected across the output of the rectifier comes from the fact that it offers a low
reactance to AC components. The ripple in nature is inversely proportional to capacitance. Thus,
the capacitor connected across the output of the rectifier, which provides the filtering action,
must be large enough to avoid the ripple.
The regulated circuit is a type of feedback circuit that ensures the output DC
voltage does not change from its normal value due to changes in line voltage or load current. It is
the nature of regulator circuit that distinguishes the linear power supply from a switching supply.
In a linear power supply, the active device (linear regulator) that provides regulation, usually
bipolar transistor is operated anywhere between cut-off and saturation i.e., in active region
whereas in switching mode power supply, switching regulator is operated either in cut-off or in
saturation. 7812 or 7805 are linear, fixed voltage series regulators, which provide regulated 12V
and 5V DC respectively. In case of a series regulator a change in the output voltage due to a
change in input voltage or load current results in a change in the voltage drop across the
regulator transistor so as to maintain a constant output voltage across the load. 12V and 5V
regulated DC power supplies are obtained across 10 micro farad capacitors.

2.3 MICRO CONTROLLER


9

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with


8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels
high-density nonvolatile memory technology and is compatible with the industry-standard 80C51
instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed
in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit
CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful
microcontroller which provides a highly-flexible and cost-effective solution to many embedded
control applications.
The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes
of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a sixvector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock
circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero
frequency and supports two software selectable power saving modes. The Idle Mode stops the
CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue
functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling
all other chip functions until the next interrupt or hardware reset.
2.3.1 FEATURES

Compatible with MCS-51 Products.


8K Bytes of In-System Programmable (ISP) Flash Memory.
Endurance: 10,000 Write/Erase Cycles.
4.0V to 5.5V Operating Range.
Fully Static Operation: 0 Hz to 33 MHz.
Three-level Program Memory Lock.
256 x 8-bit Internal RAM.
32 Programmable I/O Lines.
Three 16-bit Timer/Counters.
Eight Interrupt Sources.
Full Duplex UART Serial Channel.
Low-power Idle and Power-down Modes.
Interrupt Recovery from Power-down Mode.
Watchdog Timer.
Dual Data Pointer.
Power-off Flag.
10

Fast Programming Time.


Flexible ISP Programming (Byte and Page Mode).
Green (Pb/Halide-free) Packaging Option.

2.3.2 PIN DIAGRAM

Figure 2.5 Pin Diagram of AT89S52

2.3.3 PIN DESCRIPTION


VCC: Supply voltage.
GND: Ground.

11

Port 0: Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink
eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance
inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during
accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also
receives the code bytes during Flash programming and outputs the code bytes during program
verification. External pull-ups are required during program verification.
Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers
can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled
low will source current (IIL) because of the internal pull-ups. In addition, P1.0 and P1.1 can be
configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2
trigger input (P1.1/T2EX), respectively, as shown in the following table. Port 1 also receives the
low-order address bytes during Flash programming and verification.
Port Pin

Alternate Functions

P1.0
P1.1
P1.5
P1.6
P1.7

T2(external count input to Timer/Counter 2), clock-out


T2EX (Timer/Counter 2 capture/reload trigger and direction control)
MOSI (used for In-System Programming)
MISO (used for In-System Programming)
SCK (used for In-System Programming)
Table 2.2 Alternate functions of Port 1

Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers
can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled
low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-order address
byte during fetches from external program memory and during accesses to external data memory
that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pullups when emitting 1s. During accesses to external data memory that uses 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also
receives the high-order address bits and some control signals during Flash programming and
verification.
12

Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers
can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled
low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for
Flash programming and verification. Port 3 also serves the functions of various special features
of the AT89S52, as shown in the following table.
Port Pin

Alternate Functions

P3.0
P3.1
P3.2

RXD (serial input port)


TXD (serial output port)

0 (external interrupt 0)

P3.3

(external interrupt 1)

P3.4
P3.5
P3.6

T0 (timer 0 external input)


T1 (timer 1 external input)

WR
(external data memory write strobe)

P3.7

RD
(external data memory read strobe)
Table 2.3 Alternate Functions of Port 3

RST: Reset input. A high on this pin for two machine cycles while the oscillator is running resets
the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The
DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state
of bit DISRTO, the RESET HIGH out feature is enabled.
ALE/PROG: Address Latch Enable (ALE) is an output pulse for latching the low byte of the
address during accesses to external memory. This pin is also the program pulse input (PROG)
during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the
oscillator frequency and may be used for external timing or clocking purposes. Note, however,
that one ALE pulse is skipped during each access to external data memory. If desired, ALE
operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active
only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the
ALE-disable bit has no effect if the microcontroller is in external execution mode.

13

PSEN: Program Store Enable (PSEN) is the read strobe to external program memory. When the
AT89S52 is executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to external data
memory.
EA/VPP: External Access Enable. EA must be strapped to GND in order to enable the device to
fetch code from external program memory locations starting at 0000H up to FFFFH. Note,
however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be
strapped to VCC for internal program executions. This pin also receives the 12-volt
programming enable voltage (VPP) during Flash programming.
XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL2: Output from the inverting oscillator amplifier.
Memory Organization: MCS-51 devices have a separate address space for Program and Data
Memory. Up to 64K bytes each of external Program and Data Memory can be addressed.
Program Memory: If the EA pin is connected to GND, all program fetches are directed to
external memory. On the AT89S52, if EA is connected to VCC, program fetches to addresses
0000H through 1FFFH are directed to internal memory and fetches to addresses 2000H through
FFFFH are to external memory.
Data Memory: The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes
occupy a parallel address space to the Special Function Registers. This means that the upper 128
bytes have the same addresses as the SFR space but are physically separate from SFR space.
When an instruction accesses an internal location above address 7FH, the address mode used in
the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR
space. Instructions which use direct addressing access the SFR space. For example, the following
direct addressing instruction accesses the SFR at location 0A0H (which is P2). MOV 0A0H,
#data instructions that use indirect addressing access the upper 128 bytes of RAM. For example,
the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at
address 0A0H, rather than P2 (whose address is 0A0H). MOV @R0, #data Note that stack
14

operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available
as stack space.
Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
that can be configured for use as an on-chip oscillator, as shown in Figure 16-1. Either a quartz
crystal or ceramic resonator may be used. To drive the device from an external clock source,
XTAL2 should be left unconnected while XTAL1 is driven, as shown in Figure 16-2. There are
no requirements on the duty cycle of the external clock signal, since the input to the internal
clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high
and low time specifications must be observed.

Figure 2.6 Oscillator characteristics


C1, C2 = 30pF 10pF for Crystals
= 40pF 10pF for Ceramic Resonator

2.3.4 BLOCK DIAGRAM

15

Figure 2.7 Block diagram of 8051 micro controller


2.3.5 MODES
2.3.5.1 Idle Mode
In idle mode, the CPU puts itself to sleep while all the on-chip peripherals remain
active. The mode is invoked by software. The content of the on-chip RAM and all the special
16

functions registers remain unchanged during this mode. The idle mode can be terminated by any
enabled interrupt or by a hardware reset. Note that when idle mode is terminated by a hardware
reset, the device normally resumes pro-gram execution from where it left off, up to two machine
cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to
internal RAM in this event, but access to the port pins is not inhibited. To eliminate the
possibility of an unexpected write to a port pin when idle mode is terminated by a reset, the
instruction following the one that invokes idle mode should not write to a port pin or to external
memory.
2.3.5.2 Power-Down Mode
In the Power-down mode, the oscillator is stopped, and the instruction that invokes
Power-down is the last instruction executed. The on-chip RAM and Special Function Registers
retain their values until the Power-down mode is terminated. Exit from Power-down mode can be
initiated either by a hardware reset or by an enabled external interrupt. Reset redefines the SFRs
but does not change the on-chip RAM. The reset should not be activated before VCC is restored
to its normal operating level and must be held active long enough to allow the oscillator to restart
and stabilize.
Mode

Program

ALE

Idle
Idle
Power-Down
Power-Down

Memory
Internal
External
Internal
External

1
1
0
0

Port 0
PSEN
1
1
0
0

Data
Float
Data
Float

Port 1

Port 2

Port 3

Data
Data
Data
Data

Data
Address
Data
Data

Data
Data
Data
Data

Table 2.4 Status of External Pins During Idle and Power-Down Mode

2.4 COMPARATOR & CRYSTAL OSCILLATOR


2.4.1 COMPARATOR (LM358)
A Dual Op-Amp IC with high gain, frequency compensated operational amplifier
with single power source. These circuits consist of two independent, high gain, internally
frequency-compensated op-amps, specifically designed to operate from a single power supply
over a wide range of voltages. The low-power supply drain is independent of the magnitude of
the power supply voltage. Application areas include transducer amplifiers, DC gain blocks and
17

all the conventional op-amp circuits, which can now be more easily implemented in single
power supply systems. For example, these circuits can be directly supplied with the standard
+5 V, which is used in logic systems and will easily provide the required interface electronics
with no additional power supply.

Figure 2.8 LM358 IC


2.4.1.1 Features

Large DC voltage gain: 100 dB

Wide bandwidth (unity gain): 1.1 MHz (temperature compensated)

Very low supply current per operator essentially independent of supply voltage

Low input bias current: 20 nA (temperature compensated)

Low input offset voltage: 2 mV

Low input offset current: 2 nA

Input common-mode voltage range includes negative rails

Differential input voltage range equal to the power supply voltage

18

Large output voltage swing 0 V to (VCC + -1.5 V)

2.4.1.2 Specification

Supply Voltage: 3.0 V to 32 V

Output Current: 40mA per Channel

Package: 8 pin DIP package.

2.4.1.3 Pin Diagram

Figure 2.9 Pin diagram of LM358 IC

2.4.2 CRYSTAL OSCILLATOR


A crystal oscillator is an electronic oscillator circuit that uses the
mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal
with a very precise frequency. This frequency is commonly used to keep track of time (as
in quartz wristwatches), to provide a stable clock signal for digital integrated circuits, and to
19

stabilize frequencies for radio transmitters and receivers. The most common type of piezoelectric
resonator used is the quartz crystal, so oscillator circuits incorporating them became known as
crystal oscillators, but other piezoelectric materials including polycrystalline ceramics are used in
similar circuits.
Quartz crystals are manufactured for frequencies from a few tens of kilohertz to hundreds
of megahertz. More than two billion crystals are manufactured annually. Most are used for
consumer devices such as wristwatches, clocks, radios, computers, and cell phones. Quartz
crystals are also found inside test and measurement equipment, such as counters, signal
generators, and oscilloscopes.

Figure 2.10 Crystal Oscillator 11.0592 MHz

2.5 RELAY DRIVER & RELAY SWITCH


2.5.1 RELAY DRIVER (ULN 2003)
The ULN2003 is a monolithic high voltage and high current Darlington transistor arrays. It
consists of seven NPN darlington pairs that features high-voltage outputs with common-cathode
clamp diode for switching inductive loads. The collector-current rating of a single darlington pair
is 500mA. The darlington pairs may be paralleled for higher current capability. Applications
include relay drivers, hammer drivers, lamp drivers, display drivers (LED gas discharge), line
20

drivers, and logic buffers. The ULN2003 has a 2.7k series base resistor for each darlington pair
for operation directly with TTL or 5V CMOS devices.

Figure 2.11 ULN2003 IC


2.5.2 FEATURES
* 500mA rated collector current (Single output)
* High-voltage outputs: 50V
* Inputs compatible with various types of logic.
* Relay driver application
2.5.3 PIN DIAGRAM

21

Figure 2.12 Pin diagram of ULN2003


2.5.2 RELAY SWITCH
A relay is an electrically operated switch. Many relays use an electromagnet to mechanically
operate a switch, but other operating principles are also used, such as solid-state relays. Relays
are used where it is necessary to control a circuit by a low-power signal or where several circuits
must be controlled by one signal. The first relays were used in long distance telegraph circuits as
amplifiers: they repeated the signal coming in from one circuit and re-transmitted it on another
circuit. Relays were used extensively in telephone exchanges and early computers to perform
logical operations.
The Single Pole Double Throw Relay

Figure 2.13 SPDT relay


A single pole double throw (SPDT) relay configuration switches one common pole to two other
poles, flipping between them. As shown in the schematic diagram, the common point E
completes a circuit with C when the relay coil is at rest, that is, no voltage is applied to it. This
circuit is "closed." A gap between the contacts of point E and D creates an "open" circuit. When
you apply power to the coil, a metal level is pulled down, closing the circuit between points E
and D and opening the circuit between E and C. A single pole double throw relay can be used to
alternate which circuit a voltage or signal will be sent to.

22

2.6 LINEAR ELEMENTS


2.6.1 CAPACITOR
A capacitor is a passive two-terminal electrical component used to store energy electrostatically in an electric field. The forms of practical capacitors vary widely, but all contain at
least two electrical conductors (plates) separated by a dielectric (i.e. insulator). The conductors
can be thin films, foils or sintered beads of metal or conductive electrolyte, etc. The nonconducting dielectric acts to increase the capacitor's charge capacity. A dielectric can be glass,
ceramic, plastic film, air ,vacuum, paper, mica, oxide layer etc. Capacitors are widely used as
parts of electrical circuits in many common electrical devices. Unlike a resistor, an ideal
capacitor does not dissipate energy. Instead, a capacitor stores energy in the form of an
electrostatic field between its plates. Capacitors used in the project are 10F, 100F, 1000F.

Figure 2.14 Capacitor working

Figure 2.15 100F capacitor

23

Figure 2.16 1000F capacitor

Figure 2.17 10F capacitor

2.6.2 RESISTORS
A resistor is a passive two-terminal electrical component that implements electrical resistance as
a circuit element. Resistors act to reduce current flow, and, at the same time, act to lower voltage
levels within circuits. In electronic circuits resistors are used to limit current flow, to adjust
signal levels, bias active elements, terminate transmission lines among other uses. High-power
resistors that can dissipate many watts of electrical power as heat may be used as part of motor
controls, in power distribution systems, or as test loads for generators. Fixed resistors have
resistances that only change slightly with temperature, time or operating voltage. Variable
resistors can be used to adjust circuit elements (such as a volume control or a lamp dimmer), or
as sensing devices for heat, light, humidity, force, or chemical activity.
The resistors used in the project are mainly 1K and 10K.

24

Figure 2.18 1K and 10K resistors


2.6.3 CONNECTORS
Connector is a device for keeping two parts of an electric circuit in contact. A connector is
best known for providing the physical link between two components. Connections differ in
various ways, which help in determining where that type of connector can be used. These
features include:

Shape

Size

Gender

Connection mechanism

Function

2.6.3.1 Jumpers
Jumpers are small blocks on a circuit board with two or more pins emerging from them. Plastic
plugs containing a wire fit down over the pins. The wire connects the pins and creates a circuit.
To change a jumper setting, pull the plug off its pin(s) and carefully fit it down onto the pin(s)
indicated. A jumper is referred to as open or unjumpered when the plug is pushed down over
only one pin or if there is no plug at all. When the plug is pushed down over two pins, the jumper
is referred to as jumpered. The jumper setting is often shown in text as two numbers, such as 1-2.
The number 1 is printed on the circuit board so that you can identify each pin number based on
the location of pin 1. There are two types of jumper connectors:
1. Male jumper connector

25

Figure 2.19 Male jumper connector


2. Female jumper connector

Figure 2.20 Female jumper connector

2.7 GSM MODULE


GSM (Global System for Mobile Communications) is a standard developed by
the European Telecommunications Standards Institute (ETSI) to describe protocols for secondgeneration (2G) digital cellular networks used by mobile phones. As of 2014 it has become the
default global standard for mobile communications - with over 90% market share, operating in
over 219 countries and territories.
2G networks developed as a replacement for first generation (1G) analog cellular networks, and
the GSM standard originally described a digital, circuit-switched network optimized for full
duplex voice telephony. This expanded over time to include data communications, first by
circuit-switched transport, then by packet data transport via GPRS (General Packet Radio
Services) and EDGE (Enhanced Data rates for GSM Evolution or EGPRS).
Subsequently, the 3GPP developed third-generation (3G) UMTS standards followed by fourthgeneration (4G) LTE Advanced standards, which do not form part of the ETSI GSM standard.

26

Figure 2.21 SIM 300 GSM Module

2.7.1 NETWORK STRUCTURE


The network is structured into a number of discrete sections:

Base Station Subsystem the base stations and their controllers explained

Network and Switching Subsystem the part of the network most similar to a fixed
network, sometimes just

called the "core network"

GPRS Core Network the optional part which allows packet-based Internet connections

Operations support system (OSS) network maintenance

27

Figure 2.22 Structure of a GSM network


2.7.1.1 Base Station Subsystem

28

GSM is a cellular network, which means that cell phones connect to it by searching for cells in
the immediate vicinity. There are five different cell sizes in a GSM network
macro, micro, pico, femto, and umbrella cells. The coverage area of each cell varies according to
the implementation environment. Macro cells can be regarded as cells where the base
station antenna is installed on a mast or a building above average rooftop level. Micro cells are

cells whose antenna height is under average rooftop level; they are typically used in urban areas.
Picocells are small cells whose coverage diameter is a few dozen metres; they are mainly used
indoors. Femtocells are cells designed for use in residential or small business environments and

Figure 2.23 Base station


connect to the service providers network via a broadband internet connection. Umbrella cells are
used to cover shadowed regions of smaller cells and fill in gaps in coverage between those cells.
Cell horizontal radius varies depending on antenna height, antenna gain, and propagation
conditions from a couple of hundred meters to several tens of kilometres. The longest distance
the GSM specification supports in practical use is 35 kilometres (22 mi). There are also several
implementations of the concept of an extended cell, where the cell radius could be double or
even more, depending on the antenna system, the type of terrain, and the timing advance.
Indoor coverage is also supported by GSM and may be achieved by using an indoor picocell base
station, or an indoor repeater with distributed indoor antennas fed through power splitters, to
deliver the radio signals from an antenna outdoors to the separate indoor distributed antenna
system. These are typically deployed when significant call capacity is needed indoors, like in
29

shopping centers or airports. However, this is not a prerequisite, since indoor coverage is also
provided by in-building penetration of the radio signals from any nearby cell.
2.7.2 GSM CARRIER FREQUENCIES
GSM networks operate in a number of different carrier frequency ranges (separated into GSM
frequency ranges for 2G and UMTS frequency bands for 3G), with most 2G GSM networks
operating in the 900 MHz or 1800 MHz bands. Where these bands were already allocated, the
850 MHz and 1900 MHz bands were used instead (for example in Canada and the United
States). In rare cases the 400 and 450 MHz frequency bands are assigned in some countries
because they were previously used for first-generation systems.
Most 3G networks in Europe operate in the 2100 MHz frequency band. For more information on
worldwide GSM frequency usage, see GSM frequency bands.
Regardless of the frequency selected by an operator, it is divided into timeslots for individual
phones. This allows eight full-rate or sixteen half-rate speech channels per radio frequency.
These eight radio timeslots (or burst periods) are grouped into a TDMA frame. Half-rate
channels use alternate frames in the same timeslot. The channel data rate for all 8
channels is 270.833 kbit/s, and the frame duration is 4.615 ms.
The transmission power in the handset is limited to a maximum of 2 watts in GSM
850/900 and 1 watt in GSM 1800/1900.
2.7.3 SUBSCRIBER IDENTITY MODULE (SIM)
One of the key features of GSM is the Subscriber Identity Module, commonly known as a SIM
card. The SIM is a detachable smart card containing the user's subscription information and
phone book. This allows the user to retain his or her information after switching handsets.
Alternatively, the user can also change operators while retaining the handset simply by changing
the SIM. Some operators will block this by allowing the phone to use only a single SIM, or only
a SIM issued by them; this practice is known as SIM locking.

30

2.7.4 GSM SERVICE SECURITY


GSM was designed with a moderate level of service security. The system was designed to
authenticate the subscriber using a pre-shared key and challenge-response. Communications
between the subscriber and the base station can be encrypted. The development
of UMTS introduces an optional Universal Subscriber Identity Module (USIM), that uses a
longer authentication key to give greater security, as well as mutually authenticating the network
and the user, whereas GSM only authenticates the user to the network (and not vice versa). The
security model therefore offers confidentiality and authentication, but limited authorization
capabilities, and no non-repudiation.
GSM uses several cryptographic algorithms for security. The A5/1, A5/2, and A5/3 stream
ciphers are used for ensuring over-the-air voice privacy. A5/1 was developed first and is a
stronger algorithm used within Europe and the United States; A5/2 is weaker and used in other
countries. Serious weaknesses have been found in both algorithms: it is possible to break A5/2 in
real-time with a ciphertext-only attack, and in January 2007, The Hacker's Choice started the
A5/1 cracking project with plans to use FPGAs that allow A5/1 to be broken with a rainbow
table attack. The system supports multiple algorithms so operators may replace that cipher with a
stronger one.
New attacks have been observed that take advantage of poor security implementations,
architecture, and development for smart phone applications. Some wiretapping and
eavesdropping techniques hijack the audio input and output providing an opportunity for a third
party to listen in to the conversation.
GSM uses General Packet Radio Service (GPRS) for data transmissions like browsing the web.
The most commonly deployed GPRS ciphers were publicly broken in 2011.
The researchers revealed flaws in the commonly used GEA/1 and GEA/2 ciphers and published
the open-source "gprs decode" software for sniffing GPRS networks. They also noted that some
carriers do not encrypt the data (i.e., using GEA/0) in order to detect the use of traffic or
protocols they do not like (e.g., Skype), leaving customers unprotected. GEA/3 seems to remain
relatively hard to break and is said to be in use on some more modern networks. If used
31

with USIM to prevent connections to fake base stations and downgrade attacks, users will be
protected in the medium term, though migration to 128-bit GEA/4 is still recommended.

2.8 ENERGY METER


An electricity meter, electric meter, or energy meter is a device that measures the amount
of electric energy consumed by a residence, business, or an electrically powered device.
Electric utilities use electric meters installed at customers premises to measure electric energy
delivered to their customers for billing purposes. They are typically calibrated in billing units, the
most common one being the kilowatt hour [kWh]. They are usually read once each billing period.
In settings when energy savings during certain periods are desired, meters may measure demand,
the maximum use of power in some interval. "Time of day" metering allows electric rates to be
changed during a day, to record usage during peak high-cost periods and off-peak, lower-cost,
periods. Also, in some areas meters have relays for demand response load shedding during peak
load periods.

Figure 2.24 Energy meter


Units of measurement

32

The most common unit of measurement on the electricity meter is the kilowatt hour [kWh],
which is equal to the amount of energy used by a load of one kilowatt over a period of one hour,
or 3,600,000 joules. Some electricity companies use the SI megajoule instead. There are two
types of energy meters. They are:
2.8.1 ELECTROMECHANICAL METERS
The most common type of electricity meter is the electromechanical induction watt-hour meter.
The electromechanical induction meter operates by counting the revolutions of a non-magnetic,
but electrically conductive, metal disc which is made to rotate at a speed proportional to the
power passing through the meter. The number of revolutions is thus proportional to the energy
usage. The voltage coil consumes a small and relatively constant amount of power, typically
around 2 watts which is not registered on the meter. The current coil similarly consumes a small
amount of power in proportion to the square of the current flowing through it, typically up to a
couple of watts at full load, which is registered on the meter.
The disc is acted upon by two sets of coils, which form, in effect, a two phase induction motor.
One coil is connected in such a way that it produces a magnetic flux in proportion to
the voltage and the other produces a magnetic flux in proportion to the current. The field of the
voltage coil is delayed by 90 degrees, due to the coil's inductive nature, and calibrated using a lag
coil. This produces eddy currents in the disc and the effect is such that a force is exerted on the
disc in proportion to the product of the instantaneous current, voltage and phase angle (power
factor) between them. A permanent magnet exerts an opposing force proportional to the speed of
rotation of the disc. The equilibrium between these two opposing forces results in the disc
rotating at a speed proportional to the power or rate of energy usage. The disc drives a register
mechanism which counts revolutions, much like the odometer in a car, in order to render a
measurement of the total energy used.

33

Figure 2.25 Electro-mechanical meter


1 - Voltage coil - many turns of fine wire encased in plastic, connected in parallel with load.
2 - Current coil - three turns of thick wire, connected in series with load.
3 - Stator - concentrates and confines magnetic field.
4 - Aluminum rotor disc.
5 - Rotor brake magnets.
6 - Spindle with worm gear.
7 - Display dials - note that the 1/10, 10 and 1000 dials rotate clockwise while the 1, 100 and
10000 dials rotate counter-clockwise.
2.8.2 ELECTRONIC METERS
Electronic meters display the energy used on an LCD or LED display, and some can also
transmit readings to remote places. In addition to measuring energy used, electronic meters can
also record other parameters of the load and supply such as instantaneous and maximum rate of
usage demands, voltages, power factor and reactive power used etc. They can also support timeof-day billing, for example, recording the amount of energy used during on-peak and off-peak
hours.

34

Figure 2.26 Electronic Meter

2.9 LCD DISPLAY (16x2)


LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of
applications. A 16x2 LCD display is very basic module and is very commonly used in various
devices and circuits. These modules are preferred over seven segments and other multi
segment LEDs. The reasons being: LCDs are economical; easily programmable; have no
limitation

of

displaying

special

&

even custom

characters (unlike

in

seven

segments), animations and so on.


A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD
each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command
and Data.
The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the
cursor position, controlling display etc. The data register stores the data to be displayed on the
LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn
more about internal structure of a LCD.
35

Figure 2.27 16x2 LCD Display

36

2.9.1 PIN DESCRIPTION

Pin
No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Function

Name

Ground (0V)
Ground
Supply voltage; 5V (4.7V 5.3V)
Vcc
Contrast adjustment; through a variable resistor
VEE
Selects command register when low; and data register when
Register Select
high
Low to write to the register; High to read from the register
Read/write
Sends data to data pins when a high to low pulse is given
Enable
DB0
DB1
DB2
DB3
8-bit data pins
DB4
DB5
DB6
DB7
Backlight VCC (5V)
Led+
Backlight Ground (0V)
Led-

Table 2.5 Pin description of LCD display

37

CHAPTER 3
IMPLEMENTATION AND WORKING
Implementation part includes bringing together all the hardware components used in the project
and interfacing them to the microcontroller which is the heart of the project. We need to interface
GSM modem, LCD display and energy meter to the microcontroller.

3.1 INTERFACING GSM MODULE AND LCD DISPLAY

Figure 3.1 Interfacing of GSM and LCD display to microcontroller

38

Serial communication takes place between GSM module and microcontroller. This serial
communication is achieved by RS232 serial protocol.
3.1.1 RS-232 SERIAL PROTOCOL
One of the most common serial interfaces is based on the RS-232 standard. This standard was
developed to allow individuals to use remote computer systems over dialup telephone lines with remote
terminals. The standard includes provisions for a remote terminal that is connected to a modem that
places a telephone call, a modem that answers the telephone call, and a computer that is connected to
that modem. The terminal can be connected directly to the computer, eliminating the need for two
modems, through the use of a special device called a null modem adapter. Sometimes this device is built
directly into a cable, in which case the cable is called a null modem cable.

3.1.2 AT COMMANDS
GSM modem communicates with the microcontroller in the form of AT commands. Here AT
refers to attention.

Figure 3.2 Communication between microcontroller and GSM module


The microcontroller sends the AT command through the Tx pin and this command is received by
the receiver of the GSM module. The GSM module responds to the command and transmits the

39

information required and the result code. This information is received by the microcontroller and
it displays the result in the LCD display.

3.1.2.1 List of Important AT Commands:

Overview of AT Commands
AT+CMGD
AT+CMGF
AT+CMGL
AT+CMGR
AT+CMGS
AT+CMGW
AT+CMSS
AT+CMGC
AT+CNMI
AT+CPMS
AT+CRES
AT+CSAS
AT+CSCA
AT+CSCB
AT+CSDH
AT+CSMP
AT+CSMS

Description
DELETE SMS MESSAGE
SELECT
SMS
MESSAGE
FORMAT
LIST SMS MESSAGES FROM
PREFERRED STORE
READ SMS MESSAGE
SEND SMS MESSAGE
WRITE SMS MESSAGE TO
MEMORY
SEND SMS MESSAGE FROM
STORAGE
SEND SMS COMMAND
NEW
SMS
MESSAGE
INDICATIONS
PREFERRED SMS MESSAGE
STORAGE
RESTORE SMS SETTINGS
SAVE SMS SETTINGS
SMS
SERVICE
CENTER
ADDRESS
SELECT CELL BROADCAST SMS
MESSAGES
SHOW SMS
TEXT MODE
PARAMETERS
SET
SMS
TEXT
MODE
PARAMETERS
SELECT MESSAGE SERVICE

40

Table 3.1 List of AT Commands

3.2 INTERFACING ENERGY METER


Energy meter produces pulses when LED blinks. These pulses produced due to LED blinking are
to be given to microcontroller to display to the meter reading in the LCD display. A comparator
circuit which is basically an op-amp LM385 IC is used to convert these pulses into 5V dc and the
output of the this IC is given to the microcontroller.

3.3 WORKING OF THE PROJECT


The energy meter records the amount of power consumption. It does so by an electromechanical
system. The system is provided with such a mechanism that an increment in amount of current
flow through circuit causes the disc to rotate faster, means that the rotational speed of disc is
directly proportional to the amount of current flowing through circuit. This rotation effect of disc
causes the gear mechanism to work accordingly. And in similar fashion rate of power
consumption increases the blinking rate of LED integrated within the meter. This blinking of
LED regards to number of Pulses. The pulses from this LED are fed to comparator circuit that is
Op-Amp (LM358), So that the pulse amplitude is level to the required microcontroller voltage.
These compared pulses are fed to microcontroller for counting operation i.e. these
pulses are counted by microcontroller and readings are stored in registers. Then Microcontroller
displays the readings on LCD, and also readings are fed to GSM modem for sending SMS to the
registered user number. Whenever a command is sent to the GSM modem , it decodes the
commands and works accordingly and sends the same information via wireless network.
LOAD CONTROL
To control the load first mobile number should be registered and it can be done by
sending any SMS to the number installed in GSM modem. Once the SMS is received, System
replies Mobile no is Registered and at the same time it is displayed on LCD Mobile no is
registered. User should send * to ON the Load, # to OFF the Load and @ for bill request.
When modem receives the above Symbols

it converts into hex format and it is fed to


41

microcontroller, then microcontroller sends logic 1 or 0 as per the received symbol, to relay
driver this switches the relay 1 to ON 0 to OFF and hence load is controlled.

CHAPTER 4
RESULTS

At first when initializing the Electricity Meter Reading using GSM system, the
microcontroller sends command to operate the GSM modem. The GSM modem will now

read the immediate incoming messages.


Whenever the GSM modem gets the command message i.e. "STATUS", for sending the
present meter reading. Then the GSM modem will send the current meter reading to the

mobile number which is stored in the microcontroller


The project- GSM based Electricity Billing System with load control is designed in such
way that it sends the power usage reading to the consumer and the company through an
SMS and it can even control the electrical and electronic appliances.

PROJECT OUTLOOK

Figure 4.1 Project Outlook


42

43

Figure 4.2 Initial MSG 1

Figure 4.3 Initial MSG 2

Firstly an initial message is displayed on the LCD. It indicates that we need to send a message to
the stored mobile number in the GSM module.

Figure 4.4 Register our mobile number

Figure 4.5 Acknowledgement to mobile

In the first step we need to send a message which may contain any symbol to stored number in
GSM module. Then an acknowledgment is received to the mobile which acknowledges us that
the mobile number has been registered.
44

Figure 4.6 Acknowledgement displayed on LCD

Figure 4.7 Initial MSG

The acknowledgement is displayed on the LCD. Later it displays an initial message.

Figure 4.8 load ON request

Figure 4.9 Acknowledgement on LCD display

In order to ON the load we need to send symbol * as a message to the GSM modem. The GSM
modem sends the symbol to microcontroller. Then the loads are switched ON.

45

Figure 4.10 Load OFF request

Figure 4.11 Acknowledgement on LCD display

The loads are switched OFF by sending the symbol #. The acknowledgement is displayed on
the LCD display.

Figure 4.12 Request for meter reading

Figure 4.13 Reading received as SMS

To get the meter reading we have to send @ symbol as text message and the meter reading is
displayed on the LCD display as well as an SMS is sent to the mobile also.
46

CONCLUSION
There is a lot of wastage of power due to inefficient consumption of electricity by
consumers. The distribution company, most of the time, has to receive huge amounts due to
pending bills which results in substantial revenue losses and also causes hurdles to
modernization because of lack of funds. The consumer, on the other hand, is facing problems like
receiving due bills for bills that have already been paid and poor reliability of electricity supply.
The remedy for all these problems is to keep track of the consumers load on a
timely basis, which will help assure accurate billing, track maximum demand, and detect online
theft. These are all the features to be taken into account for designing an efficient energy billing
system. The present project incorporates these features to address the problems faced by both the
consumers and the distribution companies.

47

REFERENCES
1. Dr.T. Vigneswaran, M. Srikarthik and S. Altamash, Modern Electricity Billing System
Using GSM, International Conference on Computing and Control Engineering (ICCCE),
Vol 40, pp. 315-317,12 and 13April, 2012
2. M.A. Mazidi and Janice G. Mazidi And Rolin D. Mckinlay, The 8051 Microcontroller
and Embedded
3. Systems Using Assembly and C Prentice Hall, pp. 300-330.
4. Frederic P. Miller, Agnes F. Vandome, GSM: Cellular Network, Subscriber Identity
Module 2004.
5. The ATMEL AT89S52 8-Bit Microcontroller, 8KB ISP Flash
6. http://www.atmel.com/devices/AT89S52.aspx
7. Prepaid
electricity
billing
system
using

GSM

mobile

http://www.seminarprojects.com/Threadprepaid-energy-meter-using-gsmmobile#
ixzz1BUylZEck
8. http://probots.co.in/Manuals/SIM300.pdf
9. http://www.engineersgarage.com/tutorials/at-commands
10. Ramakant A. Gayakwad, Op-Amps and Linear Integrated Circuit PHI Learning, 4th
edition, pp. 315-317

APPENDIX
48

Program code:
#include<reg51.h>
#include<string.h>
#include"serial.h"
#define lcd_data P2
sbit lcd_rs = P2^0;
sbit lcd_en = P2^1;
sbit relay1 = P1^0;
sbit relay2= P1^1;
sbit mtr = P1^2;
int energy_val,relay_val;
int amt;
unsigned char rcv;
unsigned char rcg,pastnumber[11],i,count;
void lcdcmd(unsigned char value)
// LCD COMMAND
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
}
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x0e);
lcdcmd(0x06);
lcdcmd(0x01);

//cursor blinking
//move the cursor to right side
//clear the lcd

}
void lcddata(unsigned char value)
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=1; //select data register
49

lcd_en=1; //enable the lcd to execute data


delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(3);
lcd_en=0;
delay(3);
}
void msgdisplay(unsigned char b[]) // send string to lcd
{
unsigned char s,count=0;
for(s=0;b[s]!='\0';s++)
{
count++;
if(s==16)
lcdcmd(0xc0);
if(s==32)
{
lcdcmd(1);
count=0;
}
lcddata(b[s]);
}
}
void okcheck()
{
do{
rcv=receive();
}while(rcv!='K');
}
void sie()
{
ET0 = 0;
ES = 1;
EA = 1;
}
void sid()
{
ET0 = 1;
ES = 0;
EA = 0;
}

/* allow serial interrupts */

/* allow serial interrupts */

50

unsigned convert1(unsigned int value)


{
unsigned char a,b,c,d;
a=value/100;
b=value%100;
c=b/10;
d=b%10;
a=a|0x30;
c=c|0x30;
d=d|0x30;
//

lcddata(a);
lcddata(c);
lcddata(d);

return 1;
}
unsigned convert(unsigned int value)
{
unsigned char a,b,c,d;
a=value/100;
b=value%100;
c=b/10;
d=b%10;
a=a|0x30;
c=c|0x30;
d=d|0x30;
sertx(a);
sertx(c);
sertx(d);
return 1;
}
void main()
{
unsigned int pulse_val=0;
relay1=0;
relay2=0;
mtr=1;

51

lcd_init();
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("ENERGY METER BASED DEVICE");
delay(100);
serinit();
sertxs("AT\r\n");
sertxs("AT+CMGF=1\r\n");
sertxs("AT+CNMI=1,2,0,0\r\n");
lcdcmd(0x01);
msgdisplay("SEND MESSAGE TO STR MOBL NUM");
do
{
rcg=receive();
}while(rcg != '+');
for(count=0;count<9;count++)
{
rcg=receive();
}
for(count=0;count<10;count++)
{
pastnumber[count]=receive();
}
sertxs("AT+CMGS=\"");
sertxs(pastnumber);
sertxs("\"\r\n");
sertxs("Mobile no. registered\r\n");
sertx(0x1A);
lcdcmd(0x01);
msgdisplay("MOBILE NUMBER IS REGISTERED");
delay(200);
lcdcmd(0x01);
sie();
delay(10);
msgdisplay("ENERGY METER BAS");
while(1)
{
if(relay_val==1)
{ relay_val=3;
relay1=1;
52

relay2=1;
lcdcmd(0x01);
msgdisplay("LIGHTS ON");
}
else if(relay_val==2)
{
relay_val=3;
relay1=0;
relay2=0;
lcdcmd(0x01);
msgdisplay("LIGHTS OFF");
}
if(energy_val==1)
{ sid();
energy_val=0;
sertxs("AT+CMGS=\"");
sertxs(pastnumber);
sertxs("\"\r\n");
sertxs("READING:");
sertxs("\"\r\n");
convert(pulse_val);
sertxs("\r\n");
sertx(0x1A);
sie();
}
if(mtr==0)
{
pulse_val++;
lcdcmd(0xc0);
msgdisplay("PULSE:");
convert1(pulse_val);
while(mtr == 0);
}
}
}
void serial_int (void) interrupt 4
{
if (RI == 1)
{

/* it was a receive interrupt */

53

//

rcv = SBUF;
/* read the character into our local buffer */
RI = 0;
/* clear the received interrupt flag */
}
//
lcdcmd(0x01);
msgdisplay("* rcvd");
if(rcv=='*')
{
relay_val=1;
}
else if(rcv=='#')
{
relay_val=2;
}
else if(rcv=='@')
{
energy_val=1;
rcv=0; } }
}

SOFTWARE DESCRIPTION
This project is implemented using following software:
Embedded Keil C language
54

INTRODUCTION TO KIEL SOFTWARE


Many companies provide the 8051 assembler, some of them provide shareware
version of their product on the Web, Kiel is one of them. We can download them from their
Websites. However, the size of code for these shareware versions is limited and we have to
consider which assembler is suitable for our application.
KIEL:
This is an IDE (Integrated Development Environment) that helps you write, compile, and
debug embedded programs. It encapsulates the following components:
.

A project manager

A make facility

Tool configuration

Editor

A powerful debugger

To get start here are some several example programs.

BUILDING AN APPLICATION
To build (compile, assemble, and link) an application in uVision2, you must:
.

Select ProjectOpen Project


(For example, \C166\EXAMPLES\HELLO\HELLO.UV2)

Select Project - Rebuild all target files or Build target. UVision2 compiles, assembles,

and links the files in your project.

CREATING YOUR OWN APPLICATION


To create a new project, you must:
.

Select Project - New Project.


55

Select a directory and enter the name of the project file.

Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the
Device

Database

Create source files to add to the project.

Select Project - Targets, Groups, and Files. Add/Files, select Source Group1, and add the
source files to the project.

Select Project - Options and set the tool options. Note when you select the target device
from the Device Database all-special options are set automatically. You only need to
configure the memory map of your target hardware. Default memory model settings are
optimal for most.

APPLICATIONS:
.

Select Project - Rebuild all target files or Build target.


DEBUGGING AN APPLICATION:

To debug an application created, you must:


.

Select Debug - Start/Stop Debug Session.

Use the Step toolbar buttons to single-step through your program. You may enter G, main
in the Output Window to execute to the main C function.

Open the Serial Window using the Serial #1 button on the toolbar.

Debug your program using standard options like Step, Go, Break, and so on.

PERIPHERAL SIMULATION
The Keil 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 u vision2.
Select the Simulated Peripherals item from the Help menu. You may also use the web-based
56

device database. We are constantly adding new devices and simulation support for on-chip
peripherals so be sure to check Device Database often.

STEPS FOR EXECUTING THE KEIL PROGRAMS


1.

Click on the Keil uVision Icon on Desktop

2.

The following fig will appear

3.

Click on the Project menu from the title bar

4.

Then Click on New Project

57

5.

Save the Project by typing suitable project name with no extension in u r own folder
sited in either C:\ or D:\

6.

Then Click on Save button above.

7.

Select the component for u r project. i.e. Atmel


58

8.

Click on the + Symbol beside of Atmel

9.

Select AT89S52 as shown below

59

10.

Then Click on OK

11.

The Following fig will appear

12.

Then Click either YES or NOmostly NO

13.

Now your project is ready to USE

14.

Now double click on the Target1, you would get another option Source group 1 as
shown in next page.

15.

Click on the file option from menu bar and select new

60

16.

The next screen will be as shown in next page, and just maximize it by double
clicking on its blue boarder.

17.

Now start writing program in either in C or ASM

18.

For a program written in Assembly, then save it with extension . asm and for C
based program save it with extension .C

61

19.

Now right click on Source group 1 and click on Add files to Group Source

20.

Now you will get another window, on which by default C files will appear.

62

21.

Now select as per your file extension given while saving the file

22.

Click only one time on option ADD

23.

Now Press function key F7 to compile. Any error will appear if so happen.

24.

If the file contains no error, then press Control+F5 simultaneously.

25.

The new window is as follows

63

26.

Then Click OK

27.

Now Click on the Peripherals from menu bar, and check your required port as shown
in fig below

28.

Drag the port a side and click in the program file.

64

29.

Now keep Pressing function key F11 slowly and observe.

30.

You are running your program successfully.

65

You might also like