You are on page 1of 40

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

PROJECT REPORT ON
Energy Meter data logging and online monitoring
using Matlab and Visual Basic.
Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 1
Introduction
A data logger (also datalogger or data recorder) is an electronic device that records data
over time or in relation to location either with a built in instrument or sensor or via
external instruments and sensors. Increasingly, but not entirely, they are based on a
digital processor (or computer). They generally are small, battery powered, portable,
and equipped with a microprocessor, internal memory for data storage, and sensors.
Some data loggers interface with a personal computer and utilize software to activate
the data logger and view and analyze the collected data, while others have a local
interface device (keypad, LCD) and can be used as a stand-alone device.
Data loggers vary between general purpose types for a range of measurement
applications to very specific devices for measuring in one environment or application
type only. It is common for general purpose types to be programmable; however, many

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

remain as static machines with only a limited number or no changeable parameters.


Electronic data loggers have replaced chart recorders in many applications.

One of the primary benefits of using data loggers is the ability to automatically collect
data on a 24-hour basis. Upon activation, data loggers are typically deployed and left
unattended to measure and record information for the duration of the monitoring
period. This allows for a comprehensive, accurate picture of the environmental
conditions being monitored, such as air temperature and relative humidity.
The cost of data loggers has been declining over the years as technology improves and
costs are reduced. Simple single channel data loggers cost as little.

1.6 Project Specifications


Our industrial automation project is having following features and specification.
1. Number of devices to be controlled: 1
2. Current rating : 10A
3. Voltage : 220V
4. PC based control
5. Hardware interface : USB
6. Control Software : computer interface(GUI)
7. The project is very user friendly because of the computer interface developed by
us, even layman could operate it.
8. The GUI is platform free and doesnt require any tool like MATLAB. A single
setup file that can be executed on any both windows operating system i.e. 32/64
bits.
9. We have developed MATLAB based GUI as well.
10. The controlling hardware is using USB that makes it ultra-portable. Unlike to the
old systems of serial ports.
11. The Data is stored in a Microsoft Excel compatible file.

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 2
Objective
The main objective of our project is to log data. The project is has got load support.
Load can be connected through the project. This project will show the energy
consumption live on the computer software. These readings of consumption are also
recorded in a separate log file. This log file is compatible for Microsoft Excel.
These file stores energy reading with date and time. These log file are very useful in
industry and needed to be observed in most of the industries.

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 3
Methodology
The following block diagram explains working of the system, later we shall discuss all of
the components of the diagram.

Fig.2 | Block diagram

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 4
Programming of hardware controller
This chapter elaborate the programming of hardware controller.

4.1 Introduction to embedded C


Our project is made using embedded programming. The programming language
required for construction of the project is Embedded C. Here in this chapter we will see
the programming of the project and interfacing with the compiler. Before moving ahead
have a look on embedded system.
An embedded system is a computer system with a dedicated function within a larger
mechanical or electrical system, often with real-time computing constraints.It is
embedded as part of a complete device often including hardware and mechanical parts.
By contrast, a general-purpose computer, such as a personal computer (PC), is designed
to be flexible and to meet a wide range of end-user needs. Embedded systems control
many devices in common use today.
Modern embedded systems are often based on microcontrollers (i.e CPUs with
integrated memory and/or peripheral interfaces) but ordinary microprocessors (using

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

external chips for memory and peripheral interface circuits) are also still common,
especially in more complex systems. In either case, the processor(s) used may be types
ranging from rather general purpose to very specialised in certain class of
computations, or even custom designed for the application at hand. A common standard
class of dedicated processors is the digital signal processor (DSP).
The key characteristic, however, is being dedicated to handle a particular task. Since the
embedded system is dedicated to specific tasks, design engineers can optimize it to
reduce the size and cost of the product and increase the reliability and performance.
Some embedded systems are mass-produced, benefiting from economies of scale.
Physically, embedded systems range from portable devices such as digital watches and
MP3 players, to large stationary installations like traffic lights, factory controllers, and
largely complex systems like hybrid vehicles, MRI, and avionics. Complexity varies from
low, with a single microcontroller chip, to very high with multiple units, peripherals and
networks mounted inside a large chassis or enclosure.
Embedded systems are commonly found in consumer, cooking, industrial, automotive,
medical, commercial and military applications.

Telecommunications systems employ numerous embedded systems from telephone


switches for the network to cell phones at the end-user. Computer networking uses
dedicated routers and network bridges to route data.
Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile
phones, videogame consoles, digital cameras, DVD players, GPS receivers, and printers.
Household appliances, such as microwave ovens, washing machines and dishwashers,
include embedded systems to provide flexibility, efficiency and features. Advanced
HVAC systems use networked thermostats to more accurately and efficiently control
temperature that can change by time of day and season. Home automation uses wiredand wireless-networking that can be used to control lights, climate, security,
audio/visual, surveillance, etc., all of which use embedded devices for sensing and
controlling.

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Transportation systems from flight to automobiles increasingly use embedded systems.


New airplanes contain advanced avionics such as inertial guidance systems and GPS
receivers that also have considerable safety requirements. Various electric motors
brushless DC motors, induction motors and DC motors use electric/electronic motor
controllers. Automobiles, electric vehicles, and hybrid vehicles increasingly use
embedded systems to maximize efficiency and reduce pollution. Other automotive
safety systems include anti-lock braking system (ABS), Electronic Stability Control
(ESC/ESP), traction control (TCS) and automatic four-wheel drive.
Medical equipment uses embedded systems for vital signs monitoring, electronic
stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT, MRI)
for non-invasive internal inspections. Embedded systems within medical equipment are
often powered by industrial computers. Embedded systems are used in transportation,
fire safety, safety and security, medical applications and life critical systems, as these
systems can be isolated from hacking and thus, be more reliable.[citation needed] For
fire safety, the systems can be designed to have greater ability to handle higher
temperatures and continue to operate. In dealing with security, the embedded systems
can be self-sufficient and be able to deal with cut electrical and communication systems.
A new class of miniature wireless devices called motes are quickly gaining popularity as
the field of wireless sensor networking is increasing. Wireless sensor networking, WSN,
makes use of miniaturization made possible by advanced IC design to couple full
wireless subsystems to sophisticated sensors, enabling people and companies to
measure a myriad of things in the physical world and act on this information through IT
monitoring and control systems. These motes are completely self-contained, and will
typically run off a battery source for years before the batteries need to be changed or
charged.
Embedded Wi-Fi modules provide a simple means of wirelessly enabling any device
which communicates via a serial port.

4.2 The compiler


Atmel Studio 6 is the integrated development platform (IDP) for developing and
debugging Atmel ARM Cortex-M and Atmel AVR microcontroller (MCU) based

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

applications. The Atmel Studio 6 IDP gives you a seamless and easy-to-use environment
to write, build and debug your applications written in C/C++ or assembly code.
Atmel Studio 6 is free of charge and is integrated with the Atmel Software Framework
(ASF)a large library of free source code with 1,600 ARM and AVR project examples.
ASF strengthens the IDP by providing, in the same environment, access to ready-to-use
code that minimizes much of the low-level design required for projects. Use the IDP for
our wide variety of AVR and ARM Cortex-M processor-based MCUs, including our
broadened portfolio of Atmel SAM3 ARM Cortex-M3 and M4 Flash devices.
With the introduction of Atmel Gallery and Atmel Spaces, Atmel Studio 6 further
simplifies embedded MCU designs to reduce development time and cost. Atmel Gallery
is an online apps store for development tools and embedded software. Atmel Spaces is a
cloud-based collaborative development workspace allowing you to host software and
hardware projects targeting Atmel MCUs.
In summary, standard integrated development environments (IDEs) are suited for
creating new software for an MCU project. By contrast, the Atmel Studio 6 IDP also:
Facilitates reuse of existing software and, by doing so, enables design differentiation.
Supports the product development process with easy access to integrated tools and
software extensions through Atmel Gallery. Reduces time to market by providing
advanced features, an extensible software eco-system, and powerful debug integration.

fig | Atmel Studio

Robo India | www.roboindia.com

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Robo India | www.roboindia.com

10

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 5
The parts & Interfacing
Following are the parts of the project.

5.1. Energy Meter


An electricity meter or energy meter is a device that measures the amount of electric
energy consumed by a residence, business, or an electrically powered device.
Electricity meters are typically calibrated in billing units, the most common one being
the kilowatt hour [kWh]. Periodic readings of electricity meters establishes billing
cycles and energy used during a cycle.
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.
As commercial use of electric energy spread in the 1880s, it became increasingly
important that an electric energy meter, similar to the then existing gas meters, was
required to properly bill customers for the cost of energy, instead of billing for a fixed
number of lamps per month. Many experimental types of meter were developed. Edison
at first worked on a DC electromechanical meter with a direct reading register, but
instead developed an electrochemical metering system, which used an electrolytic cell
to totalise current consumption. At periodic intervals the plates were removed,

Robo India | www.roboindia.com

11

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

weighed, and the customer billed. The electrochemical meter was labor-intensive to
read and not well received by customers.
An early type of electrochemical meter used in the United Kingdom was the 'Reason'
meter. This consisted of a vertically mounted glass structure with a mercury reservoir
at the top of the meter. As current was drawn from the supply, electrochemical action
transferred the mercury to the bottom of the column. Like all other DC meters, it
recorded ampere-hours. Once the mercury pool was exhausted, the meter became an
open circuit. It was therefore necessary for the consumer to pay for a further supply of
electricity, whereupon, the supplier's agent would unlock the meter from its mounting
and invert it restoring the mercury to the reservoir and the supply.
In 1885 Ferranti offered a mercury motor meter with a register similar to gas meters;
this had the advantage that the consumer could easily read the meter and verify
consumption. The first accurate, recording electricity consumption meter was a DC
meter by Dr Hermann Aron, who patented it in 1883. Hugo Hirst of the British General
Electric Company introduced it commercially into Great Britain from 1888.[3] Unlike
their AC counterparts, DC meters did not measure energy. Instead they measured
charge in ampere-hours. Since the voltage of the supply should remain substantially
constant, the reading of the meter was proportional to actual energy consumed. For
example: if a meter recorded that 100 ampere-hours had been consumed on a 200 volt
supply, then 20 kilowatt-hours of energy had been supplied. Aron's meter recorded the
total charge used over time, and showed it on a series of clock dials.
The first specimen of the AC kilowatt-hour meter produced on the basis of Hungarian
Ott Blthy's patent and named after him was presented by the Ganz Works at the
Frankfurt Fair in the autumn of 1889, and the first induction kilowatt-hour meter was
already marketed by the factory at the end of the same year. These were the first
alternating-current watt-hour meters, known by the name of Blthy-meters. The AC
kilowatt hour meters used at present operate on the same principle as Blthy's original
invention. Also around 1889, Elihu Thomson of the American General Electric company
developed a recording watt meter (watt-hour meter) based on an ironless commutator

Robo India | www.roboindia.com

12

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

motor. This meter overcame the disadvantages of the electrochemical type and could
operate on either alternating or direct current.
In 1894 Oliver Shallenberger of the Westinghouse Electric Corporation applied the
induction principle previously used only in AC ampere-hour meters to produce a watthour meter of the modern electromechanical form, using an induction disk whose
rotational speed was made proportional to the power in the circuit. The Blthy meter
was similar to Shallenberger and Thomson meter in that they are two-phase motor
meter. Although the induction meter would only work on alternating current, it
eliminated the delicate and troublesome commutator of the Thomson design.
Shallenberger fell ill and was unable to refine his initial large and heavy design,
although he did also develop a polyphase version.
5.2 Energy Meter Reading
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.
Demand is normally measured in watts, but averaged over a period, most often a
quarter or half hour.
Reactive power is measured in "thousands of volt-ampere reactive-hours", (kvarh). By
convention, a "lagging" or inductive load, such as a motor, will have positive reactive
power. A "leading", or capacitive load, will have negative reactive power.
Volt-amperes measures all power passed through a distribution network, including
reactive and actual. This is equal to the product of root-mean-square volts and amperes.
Distortion of the electric current by loads is measured in several ways. Power factor is
the ratio of resistive (or real power) to volt-amperes. A capacitive load has a leading
power factor, and an inductive load has a lagging power factor. A purely resistive load
(such as a filament lamp, heater or kettle) exhibits a power factor of 1. Current
harmonics are a measure of distortion of the wave form. For example, electronic loads

Robo India | www.roboindia.com

13

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

such as computer power supplies draw their current at the voltage peak to fill their
internal storage elements. This can lead to a significant voltage drop near the supply
voltage peak which shows as a flattening of the voltage waveform. This flattening causes
odd harmonics which are not permissible if they exceed specific limits, as they are not
only wasteful, but may interfere with the operation of other equipment. Harmonic
emissions are mandated by law in EU and other countries to fall within specified limits.

5.3 Electro Mechanical Meter


The most common type of electricity meter is the electromechanical induction watthour meter.
The electromechanical induction meter operates by counting the revolutions of a nonmagnetic, 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.

Robo India | www.roboindia.com

14

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig | Enegy 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

Robo India | www.roboindia.com

15

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

mechanism which counts revolutions, much like the odometer in a car, in order to
render a measurement of the total energy used.
The type of meter described above is used on a single-phase AC supply. Different phase
configurations use additional voltage and current coils.
Three-phase electromechanical induction meter, metering 100 A 240/415 V supply.
Horizontal aluminum rotor disc is visible in center of meter
The disc is supported by a spindle which has a worm gear which drives the register. The
register is a series of dials which record the amount of energy used. The dials may be of
the cyclometer type, an odometer-like display that is easy to read where for each dial a
single digit is shown through a window in the face of the meter, or of the pointer type
where a pointer indicates each digit. With the dial pointer type, adjacent pointers
generally rotate in opposite directions due to the gearing mechanism.
The amount of energy represented by one revolution of the disc is denoted by the
symbol Kh which is given in units of watt-hours per revolution. The value 7.2 is
commonly seen. Using the value of Kh one can determine their power consumption at
any given time by timing the disc with a stopwatch.
P = {{3600 \cdot Kh } \over t}.
Where:
t = time in seconds taken by the disc to complete one revolution,
P = power in watts.
For example, if Kh = 7.2 as above, and one revolution took place in 14.4 seconds, the
power is 1800 watts. This method can be used to determine the power consumption of
household devices by switching them on one by one.

Most domestic electricity meters must be read manually, whether by a representative of


the power company or by the customer. Where the customer reads the meter, the

Robo India | www.roboindia.com

16

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

reading may be supplied to the power company by telephone, post or over the internet.
The electricity company will normally require a visit by a company representative at
least annually in order to verify customer-supplied readings and to make a basic safety
check of the meter.
In an induction type meter, creep is a phenomenon that can adversely affect accuracy,
that occurs when the meter disc rotates continuously with potential applied and the
load terminals open circuited. A test for error due to creep is called a creep test.

5.4 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 time-of-day billing, for example, recording the amount of
energy used during on-peak and off-peak hours.
Solid-state design: Solid state electricity meter used in a home in the Netherlands. Basic
block diagram of an electronic energy meter As in the block diagram, the meter has a
power supply, a metering engine, a processing and communication engine (i.e. a
microcontroller), and other add-on modules such as RTC, LCD display, communication
ports/modules and so on. The metering engine is given the voltage and current inputs
and has a voltage reference, samplers and quantisers followed by an ADC section to
yield the digitised equivalents of all the inputs. These inputs are then processed using a
digital signal processor to calculate the various metering parameters such as powers,
energies etc.
The largest source of long-term errors in the meter is drift in the preamp, followed by
the precision of the voltage reference. Both of these vary with temperature as well, and
vary wildly because most meters are outdoors. Characterising and compensating for
these is a major part of meter design.

Robo India | www.roboindia.com

17

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

The processing and communication section has the responsibility of calculating the
various derived quantities from the digital values generated by the metering engine.
This also has the responsibility of communication using various protocols and interface
with other addon modules connected as slaves to it.
RTC and other add-on modules are attached as slaves to the processing and
communication section for various input/output functions. On a modern meter most if
not all of this will be implemented inside the microprocessor, such as the real time clock
(RTC), LCD controller, temperature sensor, memory and analog to digital converters.

5.3 The controller


Robotic arm controller comprises several electronic components. Here we will discuss
the important parts of the circuit.

5.3.1 The microcontroller (Atmega 8)


The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced
RISC architecture. By executing powerful instructions in a single clock cycle, the
ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system
designer to optimize power consumption versus processing speed.

Robo India | www.roboindia.com

18

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig.| Atmega 16 Pinout diagram. | PDIP package

Robo India | www.roboindia.com

19

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig.| Atmega 16 Pinout diagram. | TQFP package

Robo India | www.roboindia.com

20

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig.| Atmega 16 Pinout diagram. | MLF package

Robo India | www.roboindia.com

21

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig.31 | Block diagram of Atmega 8

Robo India | www.roboindia.com

22

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

The AVR core combines a rich instruction set with 32 general purpose working
registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU),
allowing two independent registers to be accessed in one single instruction executed in
one clock cycle. The resulting architecture is more code efficient while achieving
throughputs up to ten times faster than conventional CISC microcontrollers. The
ATmega16 provides the following features: 16K bytes of In-System Programmable Flash
Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1K byte
SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG
interface for Boundary scan, On-chip Debugging support and programming, three
flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial
programmable USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit
ADC with optional differential input stage with programmable gain (TQFP package
only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and
six software selectable power saving modes. The Idle mode stops the CPU while
allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI
port, and interrupt system to continue functioning. The Power-down mode saves the
register contents but freezes the Oscillator, disabling all other chip functions until the
next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous
Timer continues to run, allowing the user to maintain a timer base while the rest of the
device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules
except Asynchronous Timer and ADC, to minimize switching noise during ADC
conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest
of the device is sleeping. This allows very fast start-up combined with low-power
consumption. In Extended Standby mode, both the main Oscillator and the
Asynchronous Timer continue to run. The device is manufactured using Atmels high
density non-volatile memory technology. The On chip ISP Flash allows the program
memory to be reprogrammed in-system through an SPI serial interface, by a
conventional non-volatile memory programmer, or by an On-chip Boot program
running on the AVR core. The boot program can use any interface to download the
application program in the Application Flash memory. Software in the Boot Flash
section will continue to run while the Application Flash section is updated, providing
true Re ad-While-Write operation. By combining an 8-bit RISC CPU with In-System SelfProgrammable Flash on a monolithic chip, the Atmel ATmega16 is a powerful

Robo India | www.roboindia.com

23

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

microcontroller that provides a highly-flexible and cost-effective solution to many


embedded control applications. The ATmega16 AVR is supported with a full suite of
program and system development tools including: C compilers, macro assemblers,
program debugger/simulators, in-circuit emulators, and evaluation kits.

5.3.1.1 Pin Description of ATmega 16.

VCC: Digital supply voltage.

GND: Ground.

Port A (PA7..PA0): Port A serves as the analog inputs to the A/D


Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D
Converter is not used. Port pins can provide internal pull-up resistors
(selected for each bit). The Port A output buffers have symmetrical drive
characteristics with both high sink and source capability. When pins PA0
to PA7 are used as inputs and are externally pulled low, they will source
current if the internal pull-up resistors are activated. The Port A pins are
tri-stated when a reset condition becomes active, even if the clock is not
running.

Port B (PB7..PB0): Port B is an 8-bit bi-directional I/O port with internal


pull-up resistors (selected for each bit). The Port B output buffers have
symmetrical drive characteristics with both high sink and source
capability. As inputs, Port B pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port B pins are tri-stated
when a reset condition becomes active, even if the clock is not running.

Port C (PC7..PC0): Port C is an 8-bit bi-directional I/O port with internal


pull-up resistors (selected for each bit). The Port C output buffers have
symmetrical drive characteristics with both high sink and source
capability. As inputs, Port C pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port C pins are tri-stated
when a reset condition becomes active, even if the clock is not running. If
the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI),
PC3(TMS) and PC2(TCK) will be activated even if a reset occurs.

Robo India | www.roboindia.com

24

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Port D (PD7..PD0): Port D is an 8-bit bi-directional I/O port with internal


pull-up resistors (selected for each bit). The Port D output buffers have
symmetrical drive characteristics with both high sink and source
capability. As inputs, Port D pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port D pins are tri-stated
when a reset condition becomes active, even if the clock is not running.

RESET: Reset Input. A low level on this pin for longer than the minimum
pulse length will generate a reset, even if the clock is not running.

XTAL1: Input to the inverting Oscillator amplifier and input to the


internal clock operating circuit.

XTAL2: Output from the inverting Oscillator amplifier.

AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It
should be externally connected to VCC, even if the ADC is not used. If the
ADC is used, it should be connected to VCC through a low-pass filter.

AREF: AREF is the analog reference pin for the A/D Converter.

5.3 Serial Communication:


Serial communication is a way enables different equipments to communicate with their
outside world. It is called serial because the data bits will be sent in a serial way over a
single line.
A personal computer has a serial port known as communication port or COM Port used
to connect a modem for example or any other device, there could be more than one COM
Port in a PC.
Serial ports are controlled by a special chip called UART (Universal Asynchronous
Receiver Transmitter). Different applications use different pins on the serial port and
this basically depend of the functions required. If we need to connect our PC for
example to some other device by serial port, then we have to read instruction manual
for that device to know how the pins on both sides must be connected and the setting
required.

Robo India | www.roboindia.com

25

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

5.3.1 Advantages of Serial Communication


Serial communication has some advantages over the parallel communication. One of the
advantages is transmission distance, serial link can send data to a remote device more
far then parallel link. Also the cable connection of serial link is simpler then parallel link
and uses less number of wires.
Serial link is used also for Infrared communication, now many devices such as laptops &
printers can communicate via inferred link.
5.3.2 Communication methods
There are two methods for serial communication, Synchronous & Asynchronous.
5.3.2.1 Synchronous serial communication:
In Synchronous serial communication the receiver must know when to read the next
bit coming from the sender, this can be achieved by sharing a clock between sender and
receiver.
In most forms of serial Synchronous communication, if there is no data available at a
given time to transmit, a fill character will be sent instead so that data is always being
transmitted. Synchronous communication is usually more efficient because only data
bits are transmitted between sender and receiver, however it will be more costly
because extra wiring and control circuits are required to share a clock signal between
the sender and receiver.

5.3.2.2 Asynchronous serial communication:


Asynchronous transmission allows data to be transmitted without the sender having to
send a clock signal to the receiver. Instead, special bits will be added to each word in
order to synchronize the sending and receiving of the data.
When a word is given to the UART for Asynchronous transmissions, a bit called the
Start Bit is added to the beginning of each word that is to be transmitted. The Start Bit

Robo India | www.roboindia.com

26

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

is used to alert the receiver that a word of data is about to be sent, and to force the clock
in the receiver into synchronization with the clock in the transmitter.

Fig.32 | Example of serial data transmission


After the Start Bit, the individual bits of the word of data are sent, each bit in the word is
transmitted for exactly the same amount of time as all of the other bits
When the entire data word has been sent, the transmitter may add a Parity Bit that the
transmitter generates. The Parity Bit may be used by the receiver to perform simple
error checking. Then at least one Stop Bit is sent by the transmitter.
If the Stop Bit does not appear when it is supposed to, the UART considers the entire
word to be garbled and will report a Framing Error.

5.4 USB to Serial Converter


Since latest computers and laptops dont come with serial ports. Because the popularity
of the USB. So we are using USB to serial converter. That makes our project ultraportable. A typical USB to serial converter creates a comport on the computer or laptop
and connects that comport to the external world.

Robo India | www.roboindia.com

27

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Fig.33 | USB to Serial Converter.

5.5 Software
The software we have got, is very easy to use. It requires the comport no. to
the project controller is attached. The complete operations of the project
can be controlled through the buttons provided in the software.
This software provide axis wise control.

Fig | The software Controller.

Robo India | www.roboindia.com

28

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Chapter 7
References
1. Atmega 16 data sheet.
2. USB to serial data sheet.
3. Serial communication manual of MS .net frame work
4. Serial communication manual of MATLAB.
5. Energy meter mannuals

Robo India | www.roboindia.com

29

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

Appendix 1
The codding
/*
* EM_dataLog.c
*
* Created: 19/Mar/2014 15:48:10
* Author: acer
*/

Robo India | www.roboindia.com

30

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
uint16_t E_data;
char digits[2];
/*Macros definition*/
#define BIT(x)

(1 << (x))

//Set a particular bit mask

#define CHECKBIT(x,b) x&b

//Checks bit status

#define SETBIT(x,b) x|=b;

//Sets the particular bit

#define CLEARBIT(x,b) x&=~b;

//Sets the particular bit

#define TOGGLEBIT(x,b) x^=b;

//Toggles the particular bit

void EEPROM_write(unsigned int uiAddress, unsigned char ucData);


unsigned char EEPROM_read(unsigned int uiAddress);
save_EEPROM(unsigned int add,unsigned int data);
read_EEPROM(unsigned int add);
void USART_SEND_INT(int data);
void USART_SEND_DEC(int num);
void USARTInit(uint16_t ubrr_value)
{
//Set Baud rate
UBRRL = ubrr_value;

Robo India | www.roboindia.com

31

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

UCSRC=(1<<URSEL)|(3<<UCSZ0);
//Enable The receiver and transmitter
UCSRB=(1<<RXEN)|(1<<TXEN);
}
//This function is used to read the available data
//from USART. This function will wait untill data is
//available.
char USARTReadChar()
{
//Wait untill a data is available
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}

//Now USART has got data from host


//and is available is buffer

return UDR;
}

Robo India | www.roboindia.com

32

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

//This fuction writes the given "data" to


//the USART which then transmit it via TX line
void USARTWriteChar(unsigned char data)
{
//Wait untill the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}

//Now write the data to USART buffer

UDR=data;
}

int main(void)
{
int unit_main;
char unit_decimal;
char check=0;
int counter=0;

Robo India | www.roboindia.com

33

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

InitLCD(LS_BLINK);
USARTInit(103);
LCDClear();
LCDWriteStringXY(0,0," ENERGY METER ");
LCDWriteStringXY(0,1,"USB DATA LOGGER ");
_delay_ms(1500);
SETBIT(DDRC,BIT(5));
CLEARBIT(DDRC,BIT(4));
SETBIT(PORTC,BIT(4));
LCDClear();
/**********************************/
//First Time Initialisation to erase memory block//
//keep the fuse EF C1 to avoid erasing memory block//
//save_EEPROM(20,0);
//EEPROM_write(30,0);
//EEPROM_write(40,0);
/*********************************/
int i = EEPROM_read(40);
unit_decimal = EEPROM_read(30);
unit_main = read_EEPROM(20);
LCDWriteStringXY(4,1,".");
LCDWriteStringXY(0,0," ENERGY METER ");

Robo India | www.roboindia.com

34

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

LCDWriteStringXY(8,1,"KWh");
while(1)
{
//TODO:: Please write your application code
if(

(PINC&(1<<4)) == 0 )

{
//LCDWriteStringXY(0,1,"if loop");
SETBIT(PORTC,BIT(5));
_delay_ms(200);
CLEARBIT(PORTC,BIT(5));
i++;
//LCDWriteIntXY(0,0,i,3);
EEPROM_write(40,i);
check=1;
}
if(i==32)
{
i=0;
unit_decimal ++;
EEPROM_write(30,unit_decimal);
}
if (unit_decimal == 100)

Robo India | www.roboindia.com

35

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

{
unit_decimal = 0;
unit_main ++;
save_EEPROM(20,unit_main);
}

}
}
void USART_SEND_INT(int num)
{
char i=0,j=0;
if(num>999) return;

if(num>=0)
{
while(num)
{
digits[i]=num%10;
i++;
num=num/10;
}

Robo India | www.roboindia.com

36

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

for(j=i;j<=2;j++)
{
digits[j]=0;
}
}
USARTWriteChar(digits[2]+48);
USARTWriteChar(digits[1]+48);
USARTWriteChar(digits[0]+48);
}

void USART_SEND_DEC(int num)


{
char i=0,j=0;
if(num>999) return;

if(num>=0)
{
while(num)
{
digits[i]=num%10;
i++;
num=num/10;

Robo India | www.roboindia.com

37

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

for(j=i;j<=1;j++)
{
digits[j]=0;
}
}
//USARTWriteChar(digits[2]+48);
USARTWriteChar(digits[1]+48);
USARTWriteChar(digits[0]+48);
}
save_EEPROM(unsigned int add,unsigned int data)
{
uint16_t data_l,data_h,data_f;
data_f = data;
data_l = data_f & 0x00FF;
data_h = data_f >> 8;
EEPROM_write(add,data_h);
add++;
EEPROM_write(add,data_l);
}

Robo India | www.roboindia.com

38

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

read_EEPROM(unsigned int add)


{
//use E_data to store the full value
uint16_t data_l,data_h;
data_h = EEPROM_read(add);
add++;
data_l = EEPROM_read(add);
E_data = ((data_h<<8)|data_l);
return E_data;

void EEPROM_write(unsigned int uiAddress, unsigned char ucData)


{
//

sei();

/* Wait for completion of previous write */


while(EECR & (1<<EEWE))
;
/* Set up address and data registers */
EEAR = uiAddress;
EEDR = ucData;
/* Write logical one to EEMWE */

Robo India | www.roboindia.com

39

A project report on Energy Meter data logging and online monitoring using Matlab and Visual Basic.

EECR |= (1<<EEMWE);
/* Start eeprom write by setting EEWE */
EECR |= (1<<EEWE);
//

sei();

unsigned char EEPROM_read(unsigned int uiAddress)


{
//CLEARBIT(SREG,BIT(7));
/* Wait for completion of previous write */
while(EECR & (1<<EEWE))
;
/* Set up address register */
EEAR = uiAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
//SETBIT(SREG,BIT(7));
}

Robo India | www.roboindia.com

40

You might also like