in
Group Members:
Supervisor:
P.G.H.M.C.K Herath
Dr. Jayathu Samarawickrama
T.M.D.N Karunarathna
Dr. Udayanga Hemapala
A.U Liyanamana
………………………………………………………………………
Telecommunication Engineering
This is to certify that we have read this project and that in our opinion it is fully adequate, in cope
and quality, as an Undergraduate Graduation Project.
Signature : …………………………………
Date : …………………………………
Signature : …………………………………
Date : …………………………………
DECLARATION
We declare that the dissertation entitled Smart Energy Meter and work presented in it are our own.
We confirm that:
this work was done wholly or mainly in candidature for a B.Sc. Engineering degree at this
university,
where any part of this dissertation has previously been submitted for a degree or any other
qualification at this university or any other institute, has been clearly stated,
where we have consulted the published work of others, is always clearly attributed,
Where we have quoted from the work of others, the source is always given. With the
exception of such quotations, this dissertation is entirely our own work,
we have acknowledged all main sources of help,
………………………………………….. ………………………………………………..
………………………………………………..
………………………………………………..
A. U. Liyanamana (SEU/IS/11/EG/093)
Declaration by Supervisor
I/We have supervised and accepted this dissertation for the submission of the degree.
…………………………………… ……………………………………
………………………………
A.U Liyanamana
Electrical Power Monitoring and Optimization is essential for energy management solutions,
allowing them to obtain appliance-specific energy consumption statistics that can further be used to
devise load scheduling strategies for optimal energy utilization. Sri Lankan government has
announced its ambitions of introducing smart meters to Sri Lanka within a short time span. Current
world wide initiatives show that smart meter deployments demands careful analysis and planning.
Functionalities of smart meters are not clearly defined and there are many attempts in defining them.
Most of the countries are doing pilot studies to ascertain the cost and the benefits. The reasons of
smart meter deployment are different from country to country. Though in principle smart meters
could increase power system operational efficiency and support power system control, easy to
communicate with consumers and monitor their energy consumption in real time. Smart meters are
devised to serve these purposes and are able to increase power system operational efficiency and
support power system control, easy to communicate with consumers and monitor their energy
consumption in real time and it motivating consumers to cut usage wherever possible. It is estimated
that the average consumer could save two to three percent in energy use each year using smart meter
technology. Multiply that by hundreds of millions of households, and the impact can be significant.
To Department of Electrical and Telecommunication Engineering,
First, we would like to convey our sincere gratitude to Dr. Jayathu Samarawickrama and Dr.
Udayanga Hemapala, Senior Lecturers, Department of Electrical and Telecomuniction Engineering,
South Eastern University of Sri Lanka for being the supervisor of the project and for his valuable
thoughts and guidance in carrying out this project.
Next, we would like to extend our gratitude to Eng. M.B. Murshid, Academic Coordinator of the
department for the allocation of required equipment and for his guidance on documentation and other
paper work. Finally, we thank all the academic and non-academic staff of the Department of
Electrical and Telecommunication Engineering for their kind collaboration. And Last but not least,
we would like to thank all who helped us in making this project a success.
TABLE OF CONTENTS
CHAPTER 1 .......................................................................................................................................... 4
INTRODUCTION ................................................................................................................................. 4
CHAPTER 2 ........................................................................................................................................ 10
LITERATURE REVIEW................................................................................................................. 10
2.1 Introduction ............................................................................................................................ 10
2.2 Evolution of Electricity Meters from the Past ....................................................................... 10
2.2 Traditional Electricity Meters and its types ........................................................................... 10
2.2.2 Smart Meters ....................................................................................................................... 14
2.3 Power Consumption ............................................................................................................... 14
2.4 Study of People's Behavior .................................................................................................... 15
CHAPTER 3 ........................................................................................................................................ 18
METHODOLOGY .............................................................................................................................. 18
CHAPTER 4 ........................................................................................................................................ 26
RESULTS ............................................................................................................................................ 26
CHAPTER 5 ........................................................................................................................................ 29
REFERENCES .................................................................................................................................... 31
LIST OF FIGURES
1
LIST OF TABLES
Table 2.1: Various Electricity Meters……………………………………………………...13
Table 2.2: Test Results……………………………………………………………………..27
2
ACRONYMS AND ABBREVIATIONS
µc: microcontroller
3
Chapter 1
Introduction
Although electricity was considered a luxury in the past, today it has become an essential basic
necessity with the enhanced living standards of people and growth of the technology and industrial
sector. Therefore the electricity demand in most of countries of the world is growing day by day. To
meet this demand most of the developing countries have added more fossil fuel generation to their
systems as they are the low risk proven technologies in large scale despite the environmental impact
caused by them. Current trends in power generation and use are patently unsustainable economically,
environmentally and socially. Without decisive action, increased fossil fuel demand will heighten
concerns over the security of supplies and energy related emissions of carbon dioxide (CO2). In
today’s world most of the developing countries are already swamped with power crisis due to
inadequacy of generation to meet the demand.
Therefore there is a pressing need to implement mechanisms to manage the growing demand and
improve the efficiency while reducing the energy losses, accelerating the development of low carbon
energy technologies such as renewable power generation, in order to address the global challenges of
energy security, climate change and economic growth.
One promising means of reducing the transmission and distribution losses is through the distributed
generation of electricity closer to the end user such as net metering schemes. And the other approach is
managing customer consumption of electricity in response to supply conditions, for example,
stimulating electricity customers to reduce their consumption at critical times or in response to
market prices, thereby reducing the peak demand for electricity. In order to assist consumers to make
informed decisions on how to manage and control their electricity consumption, consumers should
have a system to monitor their real- time electricity consumption as well as a communication network
with the service provider. But traditional electricity meters only record energy consumption
progressively over time, normally in monthly basis and provide no information of when the energy
was consumed. Therefore the necessity of Advanced Metering Infrastructure (AMI) has been
emerged to address the above matters.
Nowadays most of the nations are looking to rollout into Smart Meters enabling faster automated
communication of information to consumers on their real time electricity consumption, and to
service providers. And in traditional meter there is difficulties to meter reader to reach meter in
plat area best solution for this is use device which can access meter far from meter.
4
1.1 Necessity of introducing Smart Meters to Sri Lanka
During the first half of year 2012, 64% out of total electricity generation in Sri Lanka has been
catered by expensive fossil fuel oil power plants. Most of these plants have been operated only to
meet the steep night peak. Sri Lanka has a daily load curve with a steep peak in the night, where
starting from about 6.30 pm the load grows to about 2,000 MW by 7.30 pm and starts falling off
after about 10.30 pm. Therefore the system must be comprised a substantial additional generation
capacity only to meet that abrupt sharp night peak which is a huge burden for Ceylon Electricity
Board (CEB).
Therefore requirement has been aroused to control the demand by paying attention to demand side
management (DSM) while exploring the possibilities of developing sustainable energy resources.
CEB has already implemented number of energy conservation drives to curtail the overall electricity
demand. Also to pull down the steep night peak by pushing some industrial activities to low demand
hours, CEB has introduced a three tier tariff plan for the industrial electricity consumers in 2011 with
low off peak rates and penal peak rates. But in order to introduce this time-of-day tariff scheme for
the domestic consumers it is necessary to replace the existing electricity meters with advanced smart
meters since the existing electricity meter does not support both demand side management and
decentralized power generation. By introducing smart meters to all electricity consumers both
consumers and suppliers (CEB and LECO) can be benefited in many ways.
Initiating pre-paid electricity service, creating efficient electricity consumption patterns, establishing
an efficient electricity consumption system and power and energy management are some of the
special benefits anticipated by smart meter installation.
Also smart meter can provide collect monthly electricity consumption easily. Then it can reduce
wasting time of meter readers.
1.2 Anticipated Benefits from Development of Smart Metering Technology in Sri Lanka
Following benefits can be enjoyed once smart meters are implemented. Some of these benefits will
be felt immediately, others will build up over time and as the technology evolves.
Currently in Sri Lanka, electricity consumption of customers is recorded manually by sending meter
readers to the customer sites on monthly basis. But there are some issues with this stand-alone meter
5
reading such as meter reading errors, poor accessibility of meters in rural, take readings easily at plat
houses and urban areas, estimated bills and inability to monitor and control real-time usage.
The above issues can be avoided by replacing with advanced smart meters, where both supplier and
consumer can be benefited in many ways. One of the advantages of enabling AMR facility is,
allowing field operations such as meter reading and service disconnection without sending utility
personnel to the customer site. And it ensures accurate bills based on the actual consumption, rather
than estimated bills which are major source of complaints by many customers. This will result in
physical privacy to the consumers and also a high reduction in the operational cost of the utility
which will ultimately benefit the consumers with low energy charges. Similarly, many maintenance
and customer service issues such as voltage drop downs can be resolved more quickly and cost-
effectively through the use of remote diagnostics.
Currently with the mechanical energy meters, the detection of an outage and restoration of power are
not possible, therefore supplier largely rely on the consumer calls to take an idea of how large a
power outage might be and where the power outage is occurring. Smart meters provide faster outage
detection once an outage occurs and make it easier and quicker to locate and fix the problem. It helps
to identify location and extent of outages remotely via meter signals. With the aid of this ability
electricity suppliers also can keep records of power quality performance measures at each individual
by recording the number and duration of power interruptions. Similarly, smart meters equipped with
power quality monitoring capabilities enable more rapid detection, diagnosis and resolution of power
quality problems.
After replacing the existing mechanical energy meters with smart meters, prepayment facility can be
introduced to the customers facilitating shifting from credit mode to prepayment mode, and vice
versa, without the need to physically change the meter. When facilitating the prepayment mode,
energy suppliers should offer more convenient ways to top up, for example cash payments, online or
over the phone. Normally prepaid meters are programmed to issues warnings when the credit reaches
a threshold or zero. Service gets automatically disconnected. Then customer needs to recharge the
meter and eventually the prepaid meter to avail the services again. Prepaid consumption is generally
6
a very good commercial option for electricity consumers since they can preplan the budget required
for paying the electricity bill, and no additional charges are imposed on the customer upon reconnect,
hence no need to keep even security deposit to avail the service. Prepaid system is also advantageous
for the electricity suppliers since it reduces paper work, enhances the reduction of customer energy
consumption, reduces financial risks and improves operational efficiencies.
The most common method of tampering the mechanical meter is attaching magnets to the outside of
the meter to prevent forming eddy currents in the rotor by magnetically saturating the coils of current
transformer. And in Sri Lanka, events of tapping electricity from energized power lines are reported
often. Not only do energy thieves risk their own lives, but also the lives of those nearby. Deployment
of smart meters is useful to stop this energy theft using its ability of detection of tampering and
discovering energy theft. This allows the company, fast detection of any abnormal consumption due
to tampering or by-passing of a meter and enables the company to take corrective action. Moreover,
by using smart meters the supplier will be able to get detailed information about their region, which
means they can examine any suspicious areas where energy usage is higher than expected, and thus
smart metering will provide the supplier with a tool to detect fraud. In addition to that since these
devices remove the human factor from the equation, customers can no longer collude with dishonest
meter readers to cheat the power company.
Currently, electricity customers are informed of their energy usage via a bill that arrives months after
they’ve used the electricity. The existing meters do not provide details of the real time energy usage,
which could help consumers to understand their energy consumption in order to make intelligent
decisions about it. However, Smart meters comprise the option of displaying the real time
consumption including the energy usage in a previous period, hence consumers can keep track of
their energy usage with a better understanding and make informed decisions on how to manage and
control their electricity consumption according to the budget. Smart meters also provide detailed
information and historical comparison reports to help the consumers to identify when they are using
more or less energy during the day, the week or the month, which ultimately will help them to make
changes that let them take control of their energy bills by changing their habits.
7
Promoting TOU Tariff
As in most countries, even in Sri Lanka, low voltage customers pay a flat, time-independent
electricity tariff, which does not incentivize the customers to reduce demand at peak times and it
leads to inefficient use of network assets. Once the smart meters are deployed, electricity suppliers
will get the opportunity to offer and communicate time-dependent rates to the consumers through the
meter, which eventually facilitate enabling Time of Use (TOU) based tariff system for the customers,
rewarding low rates for energy usage at off peak times of day. Through the meter, customers can see
how their consumption varies during the day and respond to the TOU based tariffs that encourage
them to use cheaper energy. These price differences will help to encourage consumers to reduce their
consumption in peaks times by pushing some heavy power activities to low demand hours and is
known as load shifting or peak lopping. If this pricing method is applied in Sri Lanka, especially for
domestic consumers, it will be a great support to pull down the steep night peak and flatten the
demand curve, which, in turn, reduce the generation cost by shifting to low cost base load
generation, as well as reduce the need for additional expensive, carbon-polluting peaking power
plants to cater the night peak. Ultimately the electricity customers become an integral and active part
of the overall electric power system by helping to balance electrical demand with supply, easing the
stress on the distribution network.
1.3 Objectives
Smart meter consist with power consumption measuring module, Arduino nano, Circuit board,
Resistors, capacitor, NRF module, display etc. The smart meter should have two energy measuring
systems and display facility and communication facility to hand device. The usage is calculated in
8
KWh.
The data will be collected by hand device and the web server is updated each month. By this method,
the cost of communication can also be reduced.
9
Chapter 2
LITERATURE REVIEW
2.1 Introduction
This chapter will describe details about literature review on the meter evolution and power
consumption in Sri Lanka.
There are many types of smart meters used in world. These are mainly based on electromechanical
induction. Therefore types of smart meter designs and using technologies are reviewed in this chapter
and through those designs some ideas have been obtained to how the development of technology
focused for our design configuration.
In early years, electricity is available only to a specific section of affluent society. The advancement
in technology over time encouraged meeting the demands of common people in all parts of the
world. The general usage of electricity in the early 1870`s is only confined to telegraphs and arc
lamps. With the invention of the electric bulb by Thomas Elva Edison, the power energy market
became widely opened to the public in the year 1879. Oliver B. Shallenberger introduced his AC
ampere hour meter in the year 1888. Eventually, the progressive development in metering
technology leads in enlightening the lives of many common people.
The electrical devices that can detect and display energy in the form of readings are termed as
electricity meter. Traditional meters are used since the late 19th century. They exchange data
between electronic devices in a computerized environment for both electricity production and
distribution. In most of the traditional electricity meter aluminum discs are used to find the usage of
power. Today`s electricity meter is digitally operated but still has some limitations. A simple 1 phase
2 wire electricity meter is shown in the below figure 2.1.
10
Figure 2.1: Traditional meter
Some of the limitations faced by the traditional electricity meter are as follows:
Meters are unreliable in nature as consumer has to anticipate for the monthly electricity
bill.
The process of measurement is supported by a specific mechanical structure and hence
they are called as electromechanical meters.
In order to perform meter readings, a great number of inspectors have to be employed.
Payment processing is expensive and time consuming.
New type of tariffs on hourly basis cannot be introduced with the corresponding meters for
encouraging the consumer.
Development of meter software applications and supportive network infrastructure is complicated.
Besides the above mentioned limitations, there are also several other elements creating a huge gap
between the consumer and distributor because of installation of traditional meters. Meters are of
distinct types. Even though timely development of electricity meters helps the consumer to gain
knowledge with respect to electricity consumption, statistics of the consumption couldn`t be
changed. Table 2.1 illustrates the some of the basic types of electricity meters.
11
Table 2.1: Various Electricity Meters
12
Interaction effects, calibration and increase in the
effects of shunt loss are the greatest drawback of
this model.
13
2.2.1 Smart Meters
Smart Meter is an environmentally friendly energy meter that is used for measuring the electrical
energy in terms of Kilowatt - hours. It is simply a device that affords a direct benefit to the consumers
who want to save money on their electricity bill. They belong to a division of Advanced Meter
Infrastructure and are responsible for sending meter readings automatically to the energy supplier.
Accurate meter reading will be provided with the inclusion of ram benefits from the smart meter. A
smart meter has non-volatile data storage, remote connect or disconnect capability, tamper detection
and two-way communication facilities. They perform remote reporting of the collected data to the
central meter. This central meter monitors the functionality of the smart meter. From an operational
perspective, use of smart metering allows an improved management and control over the electricity
grid. Some of the benefits of smart meters are as follows:
Smart Meter senses all the consumption generated inside the residents. Meter readings give a broader
understanding to the energy utilities so that overall energy usage customs of the habitants can be
altered. Finally, all the information that is generated by smart meter will increase help in noble
generation.
The total amount of power consumed in an individual household is referred as power consumption.
The consumption of power is an important aspect of electricity supply. People should be aware of
preserving energy for future use. With daily usage of electricity, the energy patterns have been
14
slowly varying. This variation of consumption patterns can be caused by weather conditions or
unnecessary utilization of power by inhabitants such as increase of appliances in respective
households and careless attitude in utilization for example not switching OFF the lights or television
when not watching it. These factors may show greater impacts on the end user. As the power
supplied by energy companies is vast, most of the people are neglecting energy and its savings. The
importance of consumption is declining in the mindset of utilities. The energy utilities should play a
major role in advancing the smart meter technology and should make people participate in reducing
energy consequences by creating awareness about the impact of their current level of consumption.
These factors play an important role in influencing the behavior of the customer. The better
understanding of the people`s behavior is only achieved through analyzing how they use their
energy. The consumers should be influenced in a smart way while accessing their appliances.
Domestic sector plays a major role in the electricity demand in Sri Lanka as shown in figure
Due to the improved lifestyle and the increased income level, consumers tend to use more and more
electrical appliances which will ease their day-to-day activities. During the last decade, the domestic
electricity consumption experienced a steady growth
15
Figure 2.2: Sectorial consumption of electricity in 2016
The average size of a house has increased and the number of people in a house has decreased.
Therefore, the number of houses per equal population has increased. Then it is obvious that the
number of customer accounts in the domestic sector is significantly higher than the customer
accounts in the other sectors as shown in figure2.3.
16
So, it is clear that the domestic sector has more electricity demand than other sectors. The
consumption of electricity is increasing rapidly. But CEB hasn't provided a time base tariff system
to domestic sectors. To Calculate electricity bill of consumers, we hope to use time base tariff
system.
17
Chapter 3
Methodology
3.1 Overall Concept
First of all we had some basic concept about our project. Our project go through this concept it is,
make a smart meter to measure energy consumption and all the Smart meter has their unique ID.
When we enter the meter ID to master device it recognize the meter and send the data to the master
device. After collecting data it will upload to the base station.
18
3.2 Block Diagram of Smart Meter
Above figure shows about our first method which use to measure energy consumption. In this
method we use AD7751 as power measuring module but we had to face some difficulties in this
module. These are
19
Figure 3.3: Present Block Diagram
20
3.3 Hardware component use in smart meter
Based on HLW8012, single phase energy monitor IC. SOP8 package and
simple perpherial circuits.
Need to invasive to AC main power. VBe very careful when use it because of
the HIGH AC voltage.
Output power, or current or voltage directly by frequency, which can be read by
MCU like arduino.
Current sense by sample resistor
voltage sense by resistors net.
Board dimension is 40 x 23 mm..
Demo code (check in wiki page) support ESP8266 remote debug via telnet, safe
to read data when mains AC power connected.
According to application note, the power supply of hlw8012 must be not
isolated, read more information on wiki page.
21
NRF module
Features:
• Low cost: integrated with high-speed signal processing parts associated with RF
22
protocol, such as: automatically re-send lost packets and generate acknowledge signal;
The high-performance Microchip picoPower 8-bit AVR RISC-based microcontroller combines 32KB
ISP flash memory with read-while-write capabilities, 1024B EEPROM, 2KB SRAM, 23 general
purpose I/O lines, 32 general purpose working registers, three flexible timer/counters with compare
modes, internal and external interrupts, serial programmable USART, a byte-oriented 2-wire serial
interface, SPI serial port, a 6-channel 10-bit A/D converter (8-channels in TQFP and QFN/MLF
packages), programmable watchdog timer with internal oscillator, and five software selectable power
saving modes. The device operates between 1.8-5.5 volts.
23
By executing powerful instructions in a single clock cycle, the device achieves throughputs
approaching 1 MIPS per MHz, balancing power consumption and processing speed.
24
Master device is a device which we can carry on hand and it can take readings remotely from it.
It communicates with smart meter using NRF24l01 (Duplex) communication module. The meter
ID and total energy consumption will be displayed and it will be recorded in a log.
25
Chapter 4
RESULTS
26
Calculation
= 0.210Kw × 1 h
= 0.210KWh
= 0.210Kwh - 0.216Kwh
= 0.005 Kwh
= 2.38%
Error Graph(%)
3.5
2.5
2
Eror
1.5
0.5
0
0 200 400 600 800 1000 1200 1400 1600
Power(W)
27
Power meter vs Smart Meter
1800
1600
1400
1200
Power(W)
1000
800 Theory
600 practicle
400
200
0
30 100 200 300 1500
Rated Power(W)
28
Chapter 5
The aim of this project to implement a reliable energy monitoring system, which can
measure current and voltage values to calculate useful parameters in order to produce
useful outcomes or to carry out certain functionalities like device identification pattern
recognition, cost prediction etc.
Most consumers do not know energy consumption levels of the appliances they use and
how to manage their energy consumption levels effectively. These factors play an
important role in influencing the behavior of the customer. The better understanding of
the consumer’s behavior is only achieved through analyzing how they use their energy.
The consumers should be influenced in a smart way while accessing their appliances.
When consider about the cost of the smart metering system, it is low. But the cost of
smart meters that is in the world market is higher. So our product is a low cost one.
Therefore this electrical power monitoring and optimization system is a low expensive
solution for the power sector.
29
5.2 Further Improvements
Smart meter and smart power consumption module are still at its basic development
level as number of improvements can be done to the system to increase the accuracy of
the readings and identify usage patterns of the consumers very accurately. With more
developments this network can be used for variety of applications which will be
discussed in this chapter. Possible improvements for each system element can be
summarized as in the followings.
Smart Meter
For commercial use this cloud be improved with a tariff basis for billing
purpose and for being in a effective communication method, it could be
use in a long range data transmission.
Web Server
To pay bills online we can prepare payment gateway. A payment gateway
facilitates a payment transaction by the transfer of information between a payment
portal (such as a website, mobile phone) and the front end processor or acquiring
bank.
Master Device
Introducing payment gateway using STS algorithm for prepaid billing.
30
REFERENCES
[1] CEB Statistical Digest 2016
[2] Uteley J., Shorrock L. Domestic Energy Fact File 2008. Technical Report for
[3] http://www.watthourmeters.com/history.html
[5] http://tonyhodgson.blogspot.se/2010/12/energy-electricity-pictures.html
[6] ] L. O. AlAbdulkarim and Z. Lukszo, Smart Metering for the future energy
2519-2523
31
Appendix A
#include <Arduino.h>
#include "HLW8012.h"
#include "U8glib.h"
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <EEPROM.h>
const uint64_t pipeOut = 00001; //This same code should be in the receiver as well
RF24 radio(9, 10); //select CE and CSN pins
// GPIOs
#define SEL_PIN 3
#define CF1_PIN 2
#define CF_PIN 4
// These are the nominal values for the resistors in the circuit
#define CURRENT_RESISTOR 0.0014
#define VOLTAGE_RESISTOR_UPSTREAM ( 5*470000) // Real: 2280k
#define VOLTAGE_RESISTOR_DOWNSTREAM ( 1000) // Real 1.009k
float TOTAL_ENERGY;
int eeAddress = 0;
float myvalue;
float averageActivePower;
HLW8012 hlw8012;
unsigned long time;
32
void unblockingDelay(unsigned long mseconds) {
unsigned long timeout = millis();
while ((millis() - timeout) < mseconds) delay(1);
}
void calibrate() {
int x = hlw8012.getActivePower();
hlw8012.setMode(MODE_CURRENT);
unblockingDelay(2000);
hlw8012.getCurrent();
hlw8012.setMode(MODE_VOLTAGE);
unblockingDelay(2000);
hlw8012.getVoltage();
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print( "Read float from EEPROM: " );
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
33
Serial.begin(SERIAL_BAUDRATE);
// Initialize HLW8012
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, 500000);
hlw8012.setResistors(CURRENT_RESISTOR, VOLTAGE_RESISTOR_UPSTREAM,
VOLTAGE_RESISTOR_DOWNSTREAM);
calibrate();
/*******************NRF24L01****************/
radio.begin();
radio.setAutoAck(false);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipeOut);
radio.stopListening();
}
void loop() {
static unsigned long start = millis();
static unsigned long endTime = millis();
float averageActivePower;
endTime = millis();
hlw8012.toggleMode();
34
TOTAL_ENERGY = EEPROM.get( eeAddress, TOTAL_ENERGY );
TOTAL_ENERGY = TOTAL_ENERGY + ((energy) / 360000);
EEPROM.put(eeAddress, TOTAL_ENERGY);
// picture loop
u8g.firstPage();
do {
draw();
} while ( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
Appendix B
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
35
#include "Keypad.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeIn = 00001; //Remember that this code is the same as in the transmitter
char keymap[Rows][Cols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
void setup() {
36
Serial.begin(115200); // set up the LCD's number of columns and rows:
lcd.begin(20, 4);
/*******************Wireless communication******************/
Serial.begin(115200);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, pipeIn);
radio.startListening();
/************optional item****************************/
void displayMenu()
{
lcd.setCursor(0, 0);
lcd.print("'A'-Enter the MID");
lcd.setCursor(0, 2);
lcd.print("'B'-Reset");
}
void loop()
37
{
k = 0;
int number = 0;
char key = keypad.getKey();
String meaterID = "";
float RS;
char meterID;
/*************key specification*******************/
switch (key)
{
case 'A':
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Meter ID");
lcd.setCursor(0, 1);
while (k < 5 )
{
char key1 = keypad.getKey();
if (key1 >= '0' && key1 <= '9' )
{
ID[k] = key1;
if (k == 4) {
Serial.print("keypad ID:");
for ( int i = 0 ; i < 5 ; i++)
{
meaterID += ID[i];
}
}
Serial.println(meaterID);
lcd.print(key1);
k++;
}
if (key1 == 'B')
{
lcd.clear();
lcd.setCursor(0, 0);
return displayMenu();
}
}
lcd.noCursor();
delay(1000);
lcd.clear();
38
lcd.setCursor(0, 1);
lcd.print("'D'-Get Readings");
lcd.noCursor();
break;
case 'B':
lcd.clear();
displayMenu();
break;
case 'C':
break;
case 'D':
if (radio.available()) {
EEPROM.put(eeAddress, myvalue);
TOTAL_ENERGY = EEPROM.get( eeAddress, TOTAL_ENERGY );
Serial.println(TOTAL_ENERGY);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(".......Wating.......");
lcd.noCursor();
lcd.clear();
lcd.print("Meter ID: ");
lcd.print(meterID);
lcd.setCursor(0, 1);
lcd.print("Total Unit: ");
lcd.print(TOTAL_ENERGY);
lcd.setCursor(0, 4);
lcd.print("#-calculate Bill");
39
}
break;
case '#':
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Monthly Bill:");
RS = TOTAL_ENERGY * 30;
lcd.setCursor(0, 2);
lcd.print("Rs:");
lcd.print(RS);
lcd.print("/=");
lcd.setCursor(0, 4);
lcd.print("*-Send Data");
break;
case '*':
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Sending Data To the");
lcd.setCursor(0, 2);
lcd.print("Server-----------");
lcd.setCursor(0, 4);
lcd.print("B- Reset");
break;
}
}
40