Smart Metering
Smart Metering
Project Report
2019
Soniya Raju
This is to certify that the report entitled ‘Smart Metering System’ is a bonafide record
of the project done by Christina George, of 8th semester Electrical and Electronics
Engineering in partial fulfillment of the requirements for the award of Degree of Bach-
elor of Technology in Electrical & Electronics Engineering of the A.P.J Abdul Kalam
Technological University, Kerala during the academic year 2018 − 2019.
Soniya Raju
(Guide)
Designation
Dept. of Electrical & Electronics Engineering
Prof. Unnikrishnan P. C
Place:Kakkanad HOD
Date:10-05-2019 Dept. of Electrical & Electronics Engineering
DEPARTMENT OF ELECTRICAL AND ELECTRONICS
ENGINEERING
2
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research based knowledge
and research methods including design of experiments, analysis and interpretation
of data, and synthesis of the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
Engineering activities with an understanding of the limitations.
6. The Engineer and society: Apply reasoning informed by the contextual knowl-
edge to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional Engineering practice.
7. Environment and sustainability: Understand the impact of the professional
Engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and the need for sustainable developments.
8. Ethics: Apply ethical principles and commit to professional ethics and responsi-
bilities and norms of the Engineering practice.
9. Individual and team work: Function effectively as an individual, and as a
member or leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex Engineering activities
with the Engineering Community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding
of the Engineering and management principles and apply these to one’s own work,
as a member and leader in a team, to manage projects and in multi disciplinary
environments.
12. Life-long learning: Recognize the need for, and have the preparation and abil-
ity to engage in independent and life- long learning in the broadest context of
technological change.
Programme-Specific Outcomes (PSOs)
Engineering graduates will be able to:
PSO1: Apply the knowledge of Power electronics and electric drives for the anal-
ysis design and application of innovative, dynamic and challenging industrial en-
vironment.
PSO2: Explore the technical knowledge and development of professional method-
ologies in grid interconnected systems for the implementation of micro grid tech-
nology in the area of distributed power system.
PSO3: Understand the technologies like Bio inspired algorithms in collabora-
tion with control system tools for the professional development and gain sufficient
competence to solve present problems in the area of intelligent machine control.
3
Acknowledgement
We wish to express our deep sense of gratitude to our project guide Ms. Soniya
Raju for guiding from the inception till the completion of the project .We sincerely
acknowledge for giving her valuable guidance ,critical reviews and comments for giving
the final shape of the project. Words are inadequate in offering our thanks to our
assistant guide Mr Thomas K.P and our HOD Mr Unnikrishnan P.C for consistent
encouragement and support for shaping our project in the presentable form We wish to
put on record the appreciative original work of all the authors of various technical papers
which we have referred in our project without whom it was very difficult to achieve
successful completion of the project. Finally, we would like to express our heartfelt
thanks to all supporting staff members and friends who have been a constant source of
encouragement for successful completion of the project .
Christina George
4
Abstract
The adoption of smart grid technologies will allow for more distributed generation
of energy and for residential and commercial users of electricity to make intelligent
decisions about energy usage.A stochastic dynamic programming problem is formulated
for a micro-scale smart grid system. A mathematical model of energy usage is developed
where the goal is to optimize a finite horizon cost function reflecting both the cost of
electricity and comfort/lifestyle. This project extends this work by assuming key models
and forecasts are unknown.
The objectives of this project are:
5. to make the consumer aware of his useage pattens and understanding of faults.
It is an irresistible trend of the electric power improvement for developing the smart
grid, which applies a large amount of new technologies in power generation, transmission,
distribution and utilization to achieve optimization of the power configuration and energy
saving. As one of the key links to make a grid smarter, load forecast plays a significant
role in planning and operation in power system. Many ways such as Expert Systems,
Grey System Theory, and Artificial Neural Network (ANN) and so on are employed into
load forecast to do the simulation. This project intends to illustrate the representation
of the ANN applied in load forecast based on practical situation in Kerala,India.
Energy fraud detection is a critical aspect of smart grid security and privacy preser-
vation. Machine learning and data mining have been widely used by researchers for
extensive intelligent analysis of data to recognize normal patterns of behavior such that
deviations can be detected as anomalies. This paper discusses a novel application of a
machine learning technique for examining the energy consumption data to report energy
fraud using artificial neural networks and smart meter fine-grained data.
Contents
1 Introduction 1
1.1 Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Problem Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Project Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Proposed Idea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.6 Smart meter and smart scheduling . . . . . . . . . . . . . . . . . . . . . . 2
1.7 Market Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.8 Smart Homes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Literature Survey 5
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Smart Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Previous Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Need for Advance Metering Interface . . . . . . . . . . . . . . . . . . . . . 7
2.5 Smart Scheduling and Billing . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.6 Load Forecasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Dynamic Pricing 10
3.1 Our Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Our results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
13 Load Forecasting 74
13.1 Load aggregation using clustering . . . . . . . . . . . . . . . . . . . . . . . 75
13.2 Load modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
14 Conclusion 77
14.1 Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
14.2 Drawbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
15 Future Scope 79
15.1 Automatic pf correction with the help of capacitor bank . . . . . . . . . . 79
15.2 Identification of loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
15.3 Detect the presence of residence . . . . . . . . . . . . . . . . . . . . . . . . 80
15.4 Real-Time Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
15.5 Formula Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
15.6 Trend Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
15.7 Tariff Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
15.8 Alarms Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
15.9 Data Import/Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
9.1 measuring mains voltage and current measuring mains voltage and current 41
9.2 Measuring AC Voltage with an AC to AC power adapter . . . . . . . . . 42
9.3 circuit diagram and the voltage waveforms . . . . . . . . . . . . . . . . . 43
9.4 Buffered Voltage Bias circuit diagram . . . . . . . . . . . . . . . . . . . . 45
9.5 Simulation of Buffered Voltage Bias Proteus . . . . . . . . . . . . . . . . 45
9.6 Simulation Results(voltage waveforms) of Buffered Voltage Bias Proteus . 46
9.7 Simulation of complete circuit in direct loading . . . . . . . . . . . . . . . 46
9.8 CT Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
9.9 CT Waveform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
9.10 Choice of cable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.11 3.5 mm jack plug from your c.t. . . . . . . . . . . . . . . . . . . . . . . . . 49
9.12 3.5 mm jack plug from your c.t. wiring diagram . . . . . . . . . . . . . . . 49
9.13 schematics of CT bias voltage divider . . . . . . . . . . . . . . . . . . . . 50
9.14 Sample 1 -Waveform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
9.15 Sample 2 -Waveform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
9.16 schematic on EasyEDA editor . . . . . . . . . . . . . . . . . . . . . . . . . 52
9.17 PCB Front side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
9.18 PCB Back side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2. C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Current
5. V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Volt
8. DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Digital Circuits
Introduction
In Smart Grid, the smart meters have versatile roles, with intelligent capabilities in order
to meet the consumer’s demands and their each objective. Smart meter can measure and
communicate detailed real time electricity usage, facilitate remote real time monitoring
and control power consumption and consumers are provided with real time pricing and
analyzed usage information, which is a technical data to be transmitted to the grid, who
are utility providers. In this connection Demand-side management (DSM) programs
implemented by utility companies to control the energy consumption in residences ap-
pliances which are interfacing the digital meter with many DSM technical properties
and Home energy management system is also implemented for the same cause. A sim-
ulation framework that can model a house equipped with various home appliances and
the simulator can predict the power dissipation profiles of individual appliances as well
as the cumulative energy consumption of the house in a realistic manner.Smart meter-
ing systems rely on the network comprising of smart meters and can be characterized
with the following features: bidirectional interaction with meters, automated processing
and storage of large amounts of information, flexible and user friendly interface, active
involvement of consumers in the management of energy resources.
1
1.3 Motivation
the project is a simple means of reducing the electricity ,its cheap it consist of mainly
a programmable software and its modifications are also simple also there is a possibility
for the addition of new components in the future to the same system. The product can
also help drastically reduce the expense on electricity bills for an average user who could
not afford solar pannels.
2
suppliers and large consumers.Standard system structure includes measurement and in-
formation systems of metering points, electric energy facilities data-processing systems
and system control level data-processing system .Measurement and information systems
of metering points include metering devices of different suppliers, current and voltage
transformers, which are properly certified and meet all the technical requirements of
wholesale energy market.
3
consumption and stress on the grid and lower energy bills end-user side are reduced by
10 to 20 percent.
4
Chapter 2
Literature Survey
2.1 Introduction
Global energy demand is increasing rapidly in comparison to the steady growth of energy
generation and transmission setups. Consequently, widening the demand and supply
gap. In traditional grids, utilities cater this situation by increasing the total genera-
tion capacity as a function of peak demand. However, the resulted system (generation
and distribution) by a large part is unutilized . Recently, two parallel approaches are
developed to handle such situations:
1. using and promoting energy efficient technologies to reduce the aggregated power
consumption.
United States household electricity usage data show that 42 percent of energy is con-
sumed by household appliances . Major forces are creating a new paradigm on residential
electricity markets as energy optimization becomes an increasingly important challenge
in our society. New technologies are being deployed, including advanced meters, control-
lable appliances , distributed energy generation and storage systems, i.e., plug-in hybrid
electric vehicle batteries, stand-alone storage systems, and communications capabilities.
New laws are being proposed to allow electricity consumers to access pricing informa-
tion. New dynamic pricing policies are likely to be implemented at the retail level over
the next years .
Energy management controllers are primarily designed to control load within a single
home. They often take into account the utility data like load forecasts or ToU pricing
for scheduling the household appliances. On the customer side, customers have the
incentive to shift their electricity usage from high peak hours to low peak hours so that
their electricity bills can be reduced .
5
communicates this information to the utility for monitoring and billing purposes. It
allows a two-way communication channel between the Central System (SC) and the
meter itself.[3] The use of the smart metering is desirable at all levels of the electrical
power network. From the powerhouse down to the individual housing unit we can talk
of the high scalable system of information: with a very low cost you can evaluate energy
consumption and you could efficiently schedule activation of different loads and energy
sources (photovoltaic plants, etc.). Thanks to ICT capabilities, the SM can at the
same time monitor complex energy systems exchanging information about their energy
consumption and operation, thus offering the opportunity of real time fault detection[4].
The hardware of the Smart Meter consists of the following blocks:
1. Faster outage detection, response, and restoration by providing data to the field
operations timely.
6
2. Keeping customers better informed about the status of power grid. Utilities can
communicate relevant information, e.g., cause of outage, field-estimated restoration
time, and public safety notice[8].
7
2.6 Load Forecasting
mart grids have introduced new technological elements like electric vehicles, prosumers,
renewable energy sources (RES), advanced metering infrastructure (AMI), demand side
management (DSM) , etc., in a power system. These elements are gradually changing the
dynamics of the power system towards making it more efficient however, they enhance
the challenges of the system uncertainties and complexities. One such challenge that
has attracted large attention of researchers recently is load forecasting which is evident
from increase in number of publications related to load forecasting . Load forecasting
has been part and parcel of the power system from the inception of a power system. It is
crucial for planning of system expansions through examining the implications of system
expansion by predicting the stress on the system components[12]. Further, it also helps
in determining the likelihood of an event which ensures correct operational planning and
efficient utilization of generation resources or helping in ensuring economic load dispatch.
Prior to 1970’s the demand of electricity could be anticipated easily and thus forecasting
electricity demand was a simplistic process[13]. However, the economic conditions in
early 1970’s forced the energy demand to change drastically which enhanced energy
demand forecasting uncertainties and complexities . The traditional load forecasting
was limited to traditional loads whereas; the smart grids have changed the behaviour of
loads[14]. The consumers have turned into prosumers with RES and the smart homes and
vehicle to grid technology have changed the load patterns (frequency, magnitude, and
duration) which ultimately modified the concept of conventional loads and resultantly
load modelling.
The loads are more dynamic in nature and their interaction with system and inter-
mittent RES is particularly multifaceted which requires different approach to forecast
the loads. Although smart grids have changed the behaviour of the loads by making
them more stochastic in nature however, introduction of AMI has enabled the utility
to have an insight of the consumers load behaviour[15]. The AMI typically records
energy consumption (for consumers) and/or generation (for prosumers) at 15 or 30 min-
utes intervals and has enabled the utility to access details of individual consumers’ load
behaviour. The AMI has facilitated the utility by providing the details of individual
consumers’ load however, it has posed another challenge in the form of the big data col-
lected by the AMI requiring data exploitation for extraction of specific knowledge[16].
This data can potentially enable load forecasting at different horizons with significantly
high accuracy at individual and system levels. Therefore, exploitation of the AMI data
is of prime importance for load forecasting particularly with the consideration of the
stochastic components of the load to enable a higher accuracy of a prediction[17].
Some of the previous studies incorporated smart meter data for load forecasting at
system level. For example authors in used smart meter data to forecast load based on
consumer behaviour to improve the intra-day forecast accuracy. The authors used k-
means clustering to cluster the data and artificial neural networks to forecast the load.
However, the level of data aggregation used in the study does not help in maintaining the
uniqueness of consumer patterns. With higher level of aggregation, the volatility of smart
meter data is overlooked thus; impact of the individual consumers is not incorporated
in reality[8].The prediction of load using high level aggregation of smart meter data
was easier, however at a lower level, the volatility of the data becomes too high and
forecasting becomes difficult. It is suggested that the variability in consumption patterns
8
at lower level is higher and the variability of these pseudo-measurements should be
understood. From the aforementioned, the key challenges that emerge from use of smart
meter data for load forecasting is to determine the right level of aggregation and dealing
with the volatility of the smart meter data.
9
Chapter 3
Dynamic Pricing
Dynamic pricing is a way to flat peak demand. The consumers are encouraged to lower
their energy consumption during peak period. This lowers wholesale market price in
short run, and customers can reduce their electricity bill by shifting their use to off
peak hour. There are three types of dynamic pricing scheme: 1. Time-of-use pricing
(TOU), 2.Critical peak pricing (CPP), and 3. Real-time pricing (RTP) . Time of use
rates means different energy rate during different period of the day or different days of
a week or different seasons of a year depending on the peak demand during that period.
For example, electricity price changes (rise and fall) throughout the day, and tends to
drop overnight and on weekends, based on available supply and consumers’ demand.
Smart meters record total electricity consumption along with the time of consumption.
As a result, different prices can be applied to calculate the bill. Consumers can be able
to manage their electricity consumption habit according to the time-of-use rates and
hence manage their bills. With this pricing, electricity prices will vary based on the
time when it is used which affect the total bill.
Dynamic pricing is one of the emerging areas of research in the retail electricity
industry. It is a demand-side management technique that can reduce peak load by
charging different prices at different times according to demand. Peaks in load profiles
are the result of unregulated demand, and huge capacity addition is required to meet
peak load. This peak load capacity stays idle during off-peak periods resulting in a loss
of opportunity cost and system efficiency. Dynamic pricing can shift the demand from
peak to off-peak and help avoid large capital investments.
Retail electricity markets generally offer flat pricing or block pricing. Prices remain
unchanged irrespective of demand in the first case, while in the second, the per unit rate
of electricity either increases or decreases with increasing slabs of electricity consumption.
However, the costs of generation to meet peak demands are high as compared to those
for off-peak demand, since most peak time generating units have higher operating costs
than base load units. Thus, the above-mentioned electricity prices do not reflect the true
costs of generation and distribution. Although flat rates offer uncertainty-free electricity
bills to customers, these lead to costly capacity additions. In addition to the reduction in
peak demand, dynamic prices also provide each consumer with an opportunity to reduce
his/her electricity bill at a constant consumption level, just by changing the consumption
pattern by shifting the load.
Intelligence from grid to in-home appliances:
1. Automated Demand Response algorithms to match supply and demand
10
2. Electric home appliances/(renewable) generators with embedded intelligence
11
Figure 3.2: Initial Price versus Final Price
12
Chapter 4
13
method, even though makes the users realize their unhealthy trend of energy utilization,
will not suggest any proper method for them to follow so that they could rectify the
issue. Therefore, the best way to ensure the solution is to adopt the technique of De-
mand Response. The implementation of Demand Response could be carried out through
different methods among which valley filling and peak load shaving is the ones, which
directly affect the peak demand reduction. In order to accomplish this load shaping,
the loads have to be scheduled properly by the user so that heavily rated loads are not
turned on unnecessarily during peak hours. The loads are to be scheduled keeping in
mind that the user’s comfort is not hindered.
Meanwhile, those loads which do not directly affect the basic comfort concern of
the user or the loads which could be run at any time of the day may be scheduled
considering the energy availability and wastage constraints. It is essential for some
of the key electrical design activities .The scheduling scheme in the project works on
the basis of dynamic pricing which is provided on the internet.The pricing is provided
from an online development platform Firebase where the pricing data is stored.Also
the units consumed is provided from the website www.smartpepper.io.The objective of
the program is to collect data from both of the provided websites and use the data for
various functions .These functions can be used to reduce the overall expenditure that a
consumer has to pay on a monthly basis.A few of the functions include:
14
When the price is above second stage the mains are switched off followed by discharge
of inverter and switching of non priority loads.The program is allowed to loop itself after
every one hour interval .Another feature of the program is its pricing.The program consist
of a function which collects data from the provided database on Firebase website.
These data collected is multiplied to the units data provided in our website and
necessary calculations are done this helps receive the pricing from the start of the day
and continuously added up till the end of the day where the complete pricing is provided.
Firebase
The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON
and synchronized in realtime to every connected client. When you build cross-platform
apps with our iOS, Android, and JavaScript SDKs, all of your clients share one Realtime
Database instance and automatically receive updates with the newest data.
its key capibilities include
• Realtime:Instead of typical HTTP requests, the Firebase Realtime Database uses
data synchronization—every time data changes, any connected device receives that
update within milliseconds. Provide collaborative and immersive experiences with-
out thinking about networking code.
15
• Offline:Firebase apps remain responsive even when offline because the Firebase
Realtime Database SDK persists your data to disk. Once connectivity is reestab-
lished, the client device receives any changes it missed, synchronizing it with the
current server state.
the smart scheduling program uses the firebase for storing the pricing data and the easy
comparability makes it an ideal option for the program to work .
16
Chapter 5
17
5.5 Alarms Events
Create alerts and be notified as soon as cost or consumption deviates from the expected
pattern. You can choose between alerts based on percentage increases/decreases, alerts
based on thresholds comparison, and alerts based on power activity between time win-
dows.
18
Chapter 6
A key component of the smart grid is the ability to enable dynamic residential pricing
to incentivize the customer and the overall community to utilize energy more uniformly.
However, the complications involved require that automated strategies be provided to
the customer to achieve this goal. This paper presents a solution to the problem of
optimally scheduling a set of residential appliances under day-ahead variable peak pricing
in order to minimize the customer’s energy bill (and also, simultaneously spread out
energy usage). We map the problem to a well known problem in computer science
– the multiple knapsack problem – which enables cheap and efficient solutions to the
scheduling problem. Results show that this method is effective in meeting its goals.
With ever-increasing and imbalanced electrical demands, there is a clear realization
that further efficiencies can and must be achieved by embedding intelligence into the
power grid. Since 1982, the growth in peak demand has exceeded the transmission
growth by almost 25 percentage every year. This growing demand for electricity and
the steep increase in the power consumption of a household arising as a result of various
technological improvements pose a stiff challenge to the future electricity distribution
systems. The smart grid has emerged as a solution that provides benefits to all parties
involved: to the utilities because it provides better demand management, to the customer
because of its potential for economy, and to the environment because of the ability to
reduce greenhouse gas emissions.
The idea of dynamic pricing is a key component of the residential smart grid, where
the utility creates a time-varying rate structure over time. The user is given more respon-
sibility wherein s/he determines and controls when s/he needs a particular appliance in
his household. Moreover, as locally- generated power at the residential level proliferates
(e.g., through home solar panels), the residential user is provided with an opportunity
to supply excess electricity back to the grid, with monetary compensation. This local
generation and use of power through renewable sources of energy helps reduce the overall
carbon footprint and greenhouse gas emissions.
Strategies for reducing the cost of residential power of include reducing the power
consumption or shifting the temporal profile of power consumption to consumption at
cheaper times, where possible . Within the framework of this project, we do not aim
19
to reduce the power consumption of a household, but instead study how the power
consumption of a household can be shifted to off-peak hours so that the user benefit
financially, and the load on the system is better balanced through the day. This behavior
is incentivized through pricing strategies: incentives are provided to the users who are
willing to move in their appliances to off-peak hours though dynamic pricing. Shifting
consumption in this way is a powerful strategy There are several variants of dynamic
pricing :
• Time of use pricing establishes a variable price structure for peak, shoulder,
and off-peak hours. These prices are typically established well in advance, e.g., a
year ahead.
• Variable peak pricing is a hybrid of the two, and establishes variable pricing in
the day, defined a day ahead.
Various pilot projects have tested the notion of dynamic pricing based on real-time
pricing and variable peak pricing, and it has been concluded that customers show exhibit
price responses within this environment that provides mutual benefit to all . We focus,
in particular, on the model of day-ahead variable peak pricing. Under this model, the
benefit to the smart grid depends on how effectively it is able to shift the appliances
to the off-peak hours. In the context of near-future power consumption patterns, smart
scheduling approaches are becoming particularly significant. For example, the advent of
plug-in hybrid electric vehicles (PHEVs) is anticipated to place a significant and large
load on the grid; however, in many cases, customers will need the vehicle to be charged
during some period between a customer-specified start and end time (e.g., between 9pm
and 9am). Smart scheduling algorithms can reduce the impact on the global grid by
distributing this charging period and/or charging the vehicle during noncontiguous time
slots.
Several algorithms and techniques have been proposed in the context of scheduling
under dynamic residential pricing.
20
6.0.2 Optimal and Autonomous Incentive-based Energy Consumption
Scheduling Algorithm for Smart Grid
Mohsenian-Rad et al. present a game-theoretic approach to solving this problem. As
outlined earlier, smart scheduling has the potential to benefit all players. Through
their analysis, referred to as energy consumption scheduling (ECS), devices work with
current pricing policies to choose a schedule, while the prices are set by the cumulative
demand at any time of the day. The consumers within the community aim to reach
an equilibrium condition, the Nash Equilibrium, which provides the globally optimal
solution to the scheduling problem, while providing considerable cost savings to the
community as a whole. However, this work does not consider dynamic effects, such as
rates of response for the pricing structure and for consumption. If the pricing structure
changes too rapidly, the settling time for achieving the Nash equilibrium may be an
issue; if it changes too slowly, it may not predict the demand on a specific day. [12]
In other work, Hatami et al. introduce a quasi-dynamic pricing function and build
a scheduler that can work with interruptible tasks, i.e., tasks that need not be run
in contiguous intervals of time. Sianaki et al. introduce a single knapsack problem-
based approach to achieve energy efficient consumption in smart grids by mapping the
scheduling problem to a standard dynamic programming model, the knapsack problem.
The authors take into account the preference of the consumers within a community before
determining the schedule. The appliances are prioritized by the respective consumers
and this priority function of an appliance plays an important role when scheduling
during peak-load hours. However, under this framework, appliances are chosen based
on a priority ranking, and completion times for tasks cannot be trivially captured or
guaranteed. [13] [14]
In this project, we develop a formulation that can be used to schedule appliances
using the multiple knapsack problem (MKP) approach. Our schedule has several impor-
tant features:
• We consider the effect of must-run services (such as lights, refrigerators, etc.) that
must always be on and cannot be scheduled, as well as tasks that can be flexibly
scheduled in time.
• We incorporate the effects of local power generation sources in the objective func-
tion
• We consider the case where task deadlines must be imposed and permit tasks to
occupy noncontiguous time slots.
6.0.3 Preliminaries
In this section, we first formally state the parameters of the residential scheduling prob-
lem, followed by a definition of the terminology used within the paper. We then consider
the multiple knapsack problem (MKP) and discuss the mapping between our scheduling
problem and an instance of the MKP
Problem Statement
This section describes the problem statement, stating the requirements on the design of
the scheduler.
21
The consumers within a smart grid community are charged depending upon the net
power consumed from the smart grid based on a variable peak pricing model. The energy
prices for a specific period of time is set in advance (e.g., a day ahead). Consumers with
smart appliances may define allowable periods when their appliances are to be used.
Models for the specifications include:
its key capibilities include
• Must-run schedules for appliances that must be operational at all times, such as
lights, refrigerators, and winter heating in cold climates.
• Fixed schedules that apply to appliances that must run at specific fixed times
• Flexible schedules that apply to appliances that must run for a specified amount
of time, anytime within a flexible interval.
The goal of the approach is to optimally schedule the operating times of all appliances so
that they meet the constraints imposed by the list above, while minimizing the electricity
bill for the household. The household may contain a mix of smart appliances that can
be scheduled and appliances without inbuilt intelligence, which are manually operated.
For the purposes of this work, we consider only the scheduling of smart appliances. The
schedules for manually operated appliances, if available, can be provided as limited time
fixed must-run applications.
Thus the goal of the scheduler is to schedule the appliances within the household to
minimize the electricity bill, while contending with constraints such as the preferences of
the user, the price model, and the requirement that all the appliances must be scheduled
within the given time frame.
22
Figure 6.1: an example cost function,corresponding to the cost data
• The weight of each object is the energy Ei consumed by appliances Ai in each time
slot. Note that Ei is independent of t.
23
• The value of the object in a specific time slot is the cost of power consumption of
the appliance in that time slot, defined by the Costij function.
• The bin capacity, or the capacity of the knapsack j, capacity, is the maximum
energy that can be drawn from the grid in any time slot j. For the customer,
this can help ensure that the electricity bill can be controlled, and for the utility,
enforcing this limit ensures that the grid is not over stressed; in the absence of
this, the customer may well always choose the least expensive time slot! For
our purposes, we consider this limit on a per-household basis. A variation of
the problem formulation applies this on a per-community basis, but this requires
simultaneous scheduling of all devices in all households in a community, which is
onerous and probably not worthwhile. Such constraints can be enforced at other
points of the smart grid.
Initial Scheduling
Let us consider n appliances within a smart grid that has to be scheduled in m time slots.
Recall that the cost function, Cost(t), is a piece wise constant function that reflects the
cost of power consumption at a time slot t, and that capacity(t) is the maximum power
capacity in time slot t. Let Treq,i be the time that is required by an appliance Ai to
complete its task: this is specified in units of of the number of time intervals. This
value of Treq,i will be the same across all time slots for an appliance i since the power
consumed by the appliance is a constant.
We now present the optimization formulation as a discrete linear program that has
the form of the MKP. We introduce the Boolean integer variable, Xi(t), defined as The
objective function can now be formulated as Here, Xij is an indicator variable that states
whether the Costj term in slot j should contribute to the cost function or not. If so,
this term, which represents the unit cost in that slot, is multiplied by the energy usage
during that period.
which states that an appliance i must be provided with enough time slots to com-
plete its function. Clearly, this constraint support non contiguous time slots for various
appliances as long as the total Treq,i constraint is met.
24
Capacity constraints may be used to control the total energy usage of a home and
help incentives energy usage that is more distributed in time and uniform. For each time
slot j, these are stated as There are several constraints that must be obeyed. Specifically:
Completion constraints are designed to ensure that each task is completed during the
time period in question (e.g., one day). For each appliance i, these can be formulated
as:
1. The total cost of energy goes up by Emj Costj which should affect the objective
function; however, since this adds a constant quantity to the objective function,
the function to be minimized is unchanged from (2).
2. The capacity constraint is altered since an amount Emj of the capacity is utilized in
time slot j by must-run services. This implies that the capacity constraint changes
to:
Clearly, for a meaningful solution, it is necessary to ensure that i.e., that the must-run
services use energy that is under the capacity at any time slot j.
i.e., that the must-run services use energy that is under the capacity at any time slot
j. The role of locally-generated power is dual to the role of must-run services. If Pgj
represents the power that is generated by the local power source at time slot j, then this
amount subtracts from the total cost of energy, and using the same argument as above,
the objective function is left unchanged. An interesting case is the situation where the
value of the locally-generated power, Pmj, exceeds the demand (equation (2)) in slot j.
In this case, the power is sold back to the utility, and the goal of minimizing the objective
function still achieves the goal of maximizing the dollar gains to the homeowner of selling
electricity back to the grid. In addition to the above, locally-generted power alters the
capacity constraint, which now becomes The overall optimization problem can be stated
using the objective in (2), and constraints corresponding to (1), (3), and (6).
25
AN EXAMPLE
We test our formulation initially for a small case study with a small number of appliances
and time grids and then enlarge the case study to schedule a larger set of appliances
within an entire day. The specifics of the small example are as follows: Appliances: Two
appliances, A1, A2 Time discretization: 4 time slots, T1. T2, T3, T4 Energy usage: E1
= 10 units, E2 = 20 units Task time requirements: Treq,1 = 3, Treq,2 = 2 Capacity of
each time slot: capacity1 = capacity2 = 30 units
Cost during each time slot:
(6.1)
(6.2)
subject to:
(6.3)
The optimal solution for this problem is shown in Figure 2: appliance A1 operates
in slots 1, 2, and 4, while appliance A2 operates in slots 1 and 2. Clearly, it meets the
requirements Treq,1 and Treq,2 as well as the capacity constraints. It can be seen that
the schedule evades any consumption in the most expensive slot, slot 3, and fully uses
the least expensive slot, slot 1, and that the tasks are scheduled in interruptible fashions.
26
Figure 6.2: Results for the simple example
We apply our solution to a test case with 18 appliances and 16 time slots. The
parameters for the appliances are described in Table I, and the characteristics of the
time slots are described in Table II. The capacity constraint at each of the 16 time slots
is uniform and is set to 500 units.
The results of the optimization are shown in Figure 3. The figure at left is a stacked
bar chart, where the x-axis lists the time slots from 1 to 16, and the y-axis lists the
energy usage. The small bars below the x-axis correspond to locally-generated power.
The energy usage of all appliances is added up to create the height of the stack: it is
easily seen that the capacity constraint of 500 units is met at each time slot, and that
electricity usage is uniform, except for a few time slots. This achieves the goal of forcing
the customer to make energy usage more uniform across the day.
We explore the low-usage time slots in the right part of Figure 3. The x-axis repre-
sents time and shows the 16 time slots. The two plots show the cost (blue) and the total
energy usage (red) in each time slot. We focus on the four time slots (3, 6, 12, and 16)
with nonmaximal usage: it can be see from the blue bars and from Table II that these
correspond to the highest Costi values. Since the goal of the optimization is to minimize
customer cost, these slots are left ununsed or underused.
27
Table 6.2: Description of the time slots
Conculsion
We have presented an approach to enable residential energy scheduling under a dynamic
pricing paradigm. Our experiments show that the method is effective in encouraging
28
Figure 6.4: the stacked bar chart at left shows the energy useage of the appliances,and
the figure at right shows the cost per unit (blue) and the total usage per time slot.
29
Chapter 7
7.1 Introduction
The 0-1 Multiple Knapsack Problem(MKP) is: given a set of n items and a set of m
knapsacks (m ¡ n), with
(7.1)
select m disjoint subsets of items so that the total profit of the selected items is a
maximum, and each subset can be assigned to a different knapsack whose capacity is no
30
less than the total weight of items in the subset. Formally,
(7.2)
where
(7.3)
When m = 1, MKP reducesto the 0-1 (single) knapsack problem. We will suppose,
as is usual, that the weights wj are positive integers.Hence, without loss of generality,
we will also assume that
(7.4)
(7.5)
(7.6)
31
7.2 Solving the Multi-Dimensional Knapsack Problem with
Python
Here in our smart pepper project we are using Algorithms for solving the Multiple 0-
1 Knapsack Problem by jmyrberg (https://github.com/jmyrberg/mkp) Algorithms for
solving the Multiple 0-1 Knapsack Problem (MKP).The MTM algorithm by S. Martello
and P. Toth (1981) is implemented, which guarantees an exact solution. The repository
above mentioned contains a Python interface to C++ implementation of the algorithm.
Example usage Given ten items with the following profits and weights:
(7.7)
(7.8)
(7.9)
32
Chapter 8
Smart energy meter is proposed and simulated by using PROTEUS software. The system
was designed by using ATmega2560 as a microcontroller wchich would be later ported
to STM32 microcontroller. This chapter evaluates the accuracy of voltage and current
measurement produced by the model. The simulations show that our proposed smart
energy meter produces minimum error compared to the actual volt and actual ampere
meter.[?]
33
Figure 8.1: Design of Voltage Sensor
the modules that have been integrated. Type of microcontroller used in the design of
our digital meter is ATmega2546 and ESP8266.
34
Figure 8.3: Block diagram of proposed energy meter
8.2 Simulations 2
The experiment of this simulation study uses microcontroller ATmega2546. For moni-
toring the work of the sensor, there is an LCD that displays the data processing results.
From the test results, the following data were obtained. The experiment runs multiple
times to obtain the average error of volt and current calculation. Fig. and Fig. show the
simulation result of voltage and sensor, respectively. These figures are generated from
Table I and Table II.
35
Figure 8.4: Design of Microcontroller
Based on Table 3.1, the results obtained from the simulation, the performance of
the voltage sensor is quite effective. The model produces small error of the voltage
measurement. Linear presentation of the result is shown in Fig. . This result indicates
that the model was able to calculate the energy used by customers accurately. Table 3.2
shows the test result of current sensor. The simulation show that our model can worked
well in reading the current changes that occur from the load varied. The results of the
current sensor measurement can also be seen on the Fig. . Our experiments show that
the proposed prepaid energy meter produces small error of current and voltage sensor.
Fig. and Fig. show the simulation of the sensors.
36
Figure 8.6: Design of Keypad
37
Figure 8.8: Design of LCD
Data Volt AC Volt o/p Sensor VVolt o/p Sensor Data ADC Calculated
1 224 2.55 521 224.16 0.16
2 223 2.54 519 223.30 0.30
3 222 2.52 516 222.01 0.01
4 221 2.51 514 221.15 0.15
5 220 2.50 512 220.29 0.29
6 219 2.49 509 218.99 0.01
7 218 2.47 507 218.13 0.13
8 217 2.47 505 217.27 0.27
9 216 2.45 502 215.98 0.02
10 215 2.44 500 215.12 0.12
Average 2.49 510.50 219.64 0.15
racy of the sensors,energy meter can calculate the energy consumption correctly. For
the future work, the prototype of this design can be built and developed an application
to connect between the prototype and smartphone. Therefore, it can be implemented
to the customers in order to manage their energy consumption.
38
Figure 8.9: The Simulation of Voltage Sensor
39
Table 8.2: Test results for current sensor
40
Chapter 9
Figure 9.1: measuring mains voltage and current measuring mains voltage and current
This details how the smart pepper is build a simple electricity energy monitor on that
can be used to measure how much electrical energy you use in your home. It measures
voltage with an AC to AC power adapter and current with a clip on CT sensor, making
the setup quite safe as no high voltage work is needed.
The smart pepper energy monitor can calculate real power, apparent power, power
41
factor, rms voltage, rms current. All the calculations are done in the digital domain on
an Arduino.
9.1.1 Components
• 1x Arduino
• 2x 470kOhm (for voltage divider, any matching value resistor pair down to 10K)
• 1x 10uF capacitor
• 1x CT sensor SCT-013-000
• 2x 470kOhm (for voltage divider, any matching value resistor pair down to 10K)
• 1x 10uF capacitor
As in the case of current measurement with a CT sensor, the main objective for
the signal conditioning electronics detailed below, is to condition the output of the AC
power adapter so it meets the requirements of the Arduino analog inputs: a positive
voltage between 0V and the ADC reference voltage (Usually 5V(adruino) or 3.3V -
ADC ADS7115).
42
AC to AC power adapters are available in many voltage ratings. The first thing
important to know is the voltage rating of your adapter. We have made a reference list
of the main AC voltage adapters that we have used (we have standardised on a 9V RMS
adapter).
The output signal from the AC voltage adapter is a near-sinusoidal waveform. If you
have a 9V (RMS) power adapter the positive voltage peak be 12.7V, the negative peak
-12.7V. However, due to the poor voltage regulation with this type of adapter, when
the adapter is un-loaded (as in this case), the output is often 10-12V (RMS) giving a
peak voltage of 14-17V. The voltage output of the transformer is proportional to the AC
input voltage, see below for notes on UK mains voltage.
The waveform can be scaled down using a voltage divider connected across the
adapter’s terminals, and the offset (bias) can be added using a voltage source created by
another voltage divider connected across the Arduino’s power supply (in the same way
we added a bias for the current sensing circuit).
Here’s the circuit diagram and the voltage waveforms:
Resistors R1 and R2 form a voltage divider that scales down the power adapter AC
voltage. Resistors R3 and R4 provide the voltage bias. Capacitor C1 provides a low
impedance path to ground for the AC signal. The value is not critical, between 1 F and
10 F will be satisfactory.
R1 and R2 need to be chosen to give a peak-voltage-output of 1V. For an AC-AC
adapter with an 9V RMS output, a resistor combination of 10k for R1 and 100k for R2
would be suitable:
1 {
2 p e a k v o l t a g e o u t p u t = R1 / (R1 + R2) x p e a k v o l t a g e i n p u t =
3 10 k / ( 1 0 k + 100 k ) x 1 2 . 7V = 1 . 1 5V
4 }
5
43
The voltage bias provided by R3 and R4 should be half of the Arduino supply voltage.
As such, R3 and R4 need to be of equal resistance. Higher resistance lowers energy con-
sumption. For a battery powered emonTx, where low power consumption is important,
we use 470k resistors for R3 and R4.
If the Arduino is running at 5V the resultant waveform has a positive peak of 2.5V +
1.15V = 3.65V and negative peak of 1.35V satisfying the Arduino analog input voltage
requirements. This also leaves some ”headroom” to minimize the risk of over or under
voltage.
The 10k and 100k R1 and R2 combination works fine for an ADC ACS 7115 powered
at 3.3V, with a positive peak of 2.8V and a negative peak of 0.5V.
• Any pair of equal resistors up to 100 k may be used for R3 R4, and C1 can be
reduced to 100 nF for resistor values at the high end of the range.
44
Figure 9.4: Buffered Voltage Bias circuit diagram
45
Figure 9.6: Simulation Results(voltage waveforms) of Buffered Voltage Bias Proteus
46
Figure 9.8: CT Sensors
35 is not a common resistor value. The nearest values either side of 35 are 39 and
33 . Always choose the smaller value, or the maximum load current will create a voltage
higher than AREF. We recommend a 33 1% burden. In some cases, using 2 resistors in
47
series will be closer to the ideal burden value. The further from ideal the value is, the
lower the accuracy will be.
Here are the same calculations as above in a more compact form:
Here’s the circuit diagram and the voltage waveforms:
1 Burden R e s i s t o r ( ohms ) = (AREF ∗ CT TURNS) / ( 2 2 ∗ max primary c u r r e n t )
2
9.5.1 Materials
• A length of twin screened “microphone” cable.
48
9.5.3 Wiring
Remove the 3.5 mm jack plug from your c.t. (If it is moulded on, you must cut it off.
If you do not wish to cut the plug off, obtain an “in-line” socket.) Install the cable and
prepare the ends.
Decide at which end of the cable you have a good earth connection. You must
connect the cable screen to earth at one end only. If you have a choice, connect the
earth at the SmartPepper(EnergyMeter) end. If you do not have an earth connection,
then you may connect to the SmartPepper(EnergyMeter)’s GND.
At both ends, strip back the outer sheath. At the end that will be earthed, comb
out (or unwind) the cable screen. Join the earth wire to the screen, and connect to the
earth connection. At the end that will not be earthed, cut back and insulate the cable
screen.
At the c.t. end, join the two cores of the c.t’s cable onto the two inner cores of the
new cable. Do not connect the screen of the c.t’s cable (if it is screened).
At the SmartPepper(EnergyMeter) end, connect the two cores of the extension cable
to the plug tip and sleeve. To maintain the phase relationship, connect the red core of
the c.t’s cable via the extension cable to the plug tip, and the white core of the c.t’s
cable to the plug sleeve. If you have an American c.t. with white and black twisted
wires, connect the white wire through the extension cable to the plug tip and the black
wire to the sleeve. There is no connection to the plug ring.
Figure 9.12: 3.5 mm jack plug from your c.t. wiring diagram
49
theory
There are two routes by which interference can get into the cable, and so be measured
along with the wanted signal – as a magnetic field or as an electric field. The magnetic
field is counteracted by twisting the cores inside the cable. Alternate half-twists will
pick up the field in the opposite sense, so the induced currents will cancel. The cable
screen will have little or no effect.
The electric field will be intercepted by the cable screen, and conducted to earth
through the earth connection. It is important not to earth the screen at both ends, as
this could give rise to a current that circulates in the loop formed by the cable screen,
earth and the two earth connections.
Imagine a very small current flowing, and the bias voltage divider resistors in the
current input stage circuit above, make the average voltage sit exactly in the middle of
the Arduino ADC input range. At this point, you need to know that each number out
of the analogue to digital converter represents not a voltage but a band of voltages. The
analogue to digital converter will measure the waveform at many points – about 50 in
practice – and if the amplitude of the wave is small enough, each sample of the wave
(sample 1) will have the value 511.
The high pass filter in the software will shift the wave so that the average value is
zero. This is equivalent to subtracting the average value from each sample. The average
is 511, so each filtered sample will now be 0.
50
Figure 9.14: Sample 1 -Waveform
Let’s see what happens if the bias voltage drifts a little. Now the average value is
just above the change from 511 to 512. This time, when the analogue to digital converter
measures the wave, the samples in the first half cycle (and maybe one or two more) will
take the value 512, and the remainder will have the value 511. The sampling process
has turned our sine wave into a square wave.
The high pass filter in the software will again shift the wave, so the average value
is zero, and again this is equivalent to subtracting the average value from each sample.
But this time, the average is 511.6 (remember, now we’re using floating point decimal
values in the software), so each sample in the first half will be 512 - 511.6 = 0.4, and
each sample in the second half will be 511 - 511.6 = -0.6 .
Now the important part comes when the software calculates the power and the RMS
value of the wave.
To calculate power, the current and voltage for corresponding samples are multiplied
together, and the average of that is the power. To calculate the rms current, each current
sample is multiplied by itself, the average is calculated and the rms current is the square
root of that number.
Clearly in the first case, because each current sample is zero, power and rms current
are both zero.
In the second case, and assuming voltage and current waveforms are exactly in phase,
the average power will be the average of [each positive half cycle voltage sample x 0.4]
and [each negative half cycle voltage sample x -0.6], or about 0.45 units. The rms current
51
will be the square root of the average of 0.42 + (-0.6)2, or about 0.72 units. We shall
define the units next.
To see what numbers you might expect in practice, say the voltage is 240, and the
current sensor is the standard 100 A CT with the standard 18 burden resistor. 100 A
RMS represents a peak-to-peak count of about 800, so our wave with a peak-to-peak
amplitude of 1 count has an RMS value of about 0.125 A. This represents a true power
of 30 W. Therefore, in the second case we might read 13.5 W and 0.09 A, and even
though we have unity power factor, we read an apparent power of 21.6 VA and a power
factor of 0.625.
But you will get exactly the same result if the current is the smallest imaginable whilst
still being just sufficient to flip the analog to digital converter between two adjacent
values. So in practice, you might read anything from zero power and current, to a power
of 13.5 W and a current of 0.09 A.
On the other hand, you might read zero power and zero current for any load up to
30 W.
Up to this point, we’ve assumed the Arduino ADC input comes from the current
sensor. It may also come from digital noise generated by the Arduino itself, or outside
noise picked up by the PCB or the wiring.
Placing the components : Drag and drop the components to the spots where you
52
want them to be. If you want your PCB to look as clean as possible I suggest placing all
components with the same function next to each other, like resistors for example. Also
make sure to leave some extra space between components, especially capacitors since
the size may vary. Apart from the fact that the size may vary leaving some space will
make the soldering a lot easier.
Finalizing the PCB; The finished result by clicking on the “Photo View” button:
Downloaded the Gerber Files and sent to fabricator(JLPCB,China since it’s 2 layer
PCB).
53
Chapter 10
Hardware
54
In addition to the split-core type, solid-core, (aka ring-core) CTs are available. Here’s
an example of a Magnelab solid-core CT:
Current transformers are sensors that measure alternating current . They are par-
ticularly useful for measuring whole building electricity consumption or generation.The
split core type, can be clipped onto either the live or neutral wire coming into the build-
ing, without the need to do any high voltage electrical work.A current transformer has a
primary winding, a magnetic core, and a secondary winding.In the case of whole building
monitoring, the primary winding is the live or neutral wire coming into the building,
that is passed through the opening in the Current Transformer. The secondary winding
is made of many turns of fine wire housed within the transformer case.The alternating
current flowing in the primary produces a magnetic field in the core, which induces
a current in the secondary winding circuit .The current in the secondary winding is
proportional to the current flowing in the primary winding:
I secondary = CT turns Ratio I primary
CT turns Ratio = Turns primary / Turns secondary
The core is solid, and the cable you wish to put it on, needs to be disconnected
in order to install the CT. Therefore, it’s used only where it’s practical, safe and
legal to disconnect the circuit. Its advantage is higher accuracy.
The core is in two parts held together by clips or screws. The two parts are simply
placed around the cable and assembled. There is no need to disconnect anything.
55
Provided the current transformer has a burden connected, it can be installed on a
live, insulated, current-carrying cable.
1. You have a small current and it is difficult to get an accurate reading. In this case,
the wire diameter is small. It’s possible to wind it into a coil and the C.T. can be
fastened to the coil, or the wire can be passed though the CT opening several times
in the same direction, effectively multiplying the current by the number of turns
passing through the core. You can correct the reading by changing the calibration
of that input.
2. You have many small loads on different circuits, and you want to measure the
total current used by those circuits. All the circuits must be on the same phase,
and all the wires must pass through the CT in the same direction. If one wire
passes through the CT in the opposite direction, the current in that wire will be
subtracted from the total.
10.1.3 Warnings
If an unburdened CT (i.e. one without a burden resistor) is attached to a current-
carrying conductor, the CT will generate an unsafe voltage at its leads which could
break down the insulation and destroy the C.T.
The YHDC transformer sold in the Shop has internal Zener diodes to limit the
maximum unburdened voltage output to a safe level. CTs with internal burden resistors
(‘the voltage output’ type) are also protected against developing dangerous voltages.
Always connect the C.T. leads before clipping it round a current-carrying conductor,
and always un-clip the C.T. from the current-carrying conductor before disconnecting
its leads.
Never open-circuit a C.T. whilst it is on a current-carrying conductor. It is always
safe to short-circuit a C.T.
Never attempt to fit a C.T. to a bare conductor unless you are absolutely certain it is
designed for that. Apart from the obvious danger of electric shock, there are two factors
to be considered: the strength of the C.T.’s insulation, and its ability to withstand the
higher temperatures at which bare conductors normally operate.
A split-core CT, especially one that has a ferrite core (such as the ones made by
YHDC) should never be ”clamped” to the cable using any sort of packing material,
because the brittle nature of the ferrite core means that it might easily be broken, thus
destroying the CT. You should only clamp the CT to the cable or busbar if the housing
56
is specifically designed to do so. Similarly, a ring-core CT should never be forced onto
a cable that is too large to pass freely through the centre. The position and orientation
of the cable within the CT aperture makes no practical difference to the output.
Potential transformers are used to measure voltage . The secondary voltage is sub-
stantially proportional to the primary voltage and differs from it in phase by an angle
that is approximately zero. Voltage and potential transformers that are designed for
monitoring single-phase and three-phase line voltages in power-metering applications
are used mainly as step-down devices. They are designed for connecting line-to-line
or line-to-neutral in the same way as ordinary voltmeters. The secondary voltage has a
fixed relationship to the primary voltage so that a change in potential within the primary
circuit is monitored accurately by meters connected across the secondary terminals.
57
Figure 10.5: Rogowski Coil
integrator, in its simplest form, with an input resistor Rsh and feedback capacitor C
has an output Vout=(1/CR) Edt. The overall transducer gain is therefore given by,
Vout=RshI, where Rsh= H/CR is the transducer sensitivity (V/A). The relationship
Vout proportional to I is valid throughout the transducer bandwidth. The bandwidth
is defined as the range of frequencies from fL to fH for which sinusoidal currents can
be measured to within 3dB of the specified sensitivity Rsh. At low frequencies the
integrator gain increases and in theory will become infinite as the frequency approaches
zero. This would result in unacceptable dc drift and low frequency noise; hence the
integrator gain has to be limited at low frequencies. This limitation is achieved by
placing a low pass filter in parallel with the integrating capacitor. The low pass filter
sets the low frequency bandwidth fL, typically this is less than 1Hz.Furthermore, due to
the distributed inductance and capacitance of the Rogowski coil there is a high frequency
bandwidth fH, (generally 1MHz or greater) above which the measurement is attenuated
and significant phase delay occurs. The bandwidth of the electronic integrator and
the length of cable connecting the integrator to the coil also influence this limit. Over
many years, PEM has developed mathematical models of the Rogowski coil, cable and
integrator allowing us to develop reliable, accurate current transducers in a variety of
sizes for an ever growing market.
58
Figure 10.6: Arduino Mega 2560
to power the board. Some version of Arduino board lacks this feature like Arduino Pro
Mini doesn’t come with DC power jack.ICSP header is a remarkable addition to Arduino
Mega which is used for programming the Arduino and uploading the code from the com-
puter.This board comes with two voltage regulator i.e. 5V and 3.3V which provides the
flexibility to regulate the voltage as per requirements as compared to Arduino Pro Mini
which comes with only one voltage regulator.There is no much difference between Ar-
duino Uno and Arduino Mega except later comes with more memory space, bigger size
and more I/O pins.Arduino software called Arduino IDE is used to program the board
which is a common software used for all boards belonged to Arduino family.Availability
of Atmega16 on the board makes it different than Arduino Pro Mini which uses USB to
serial converter to program the board.There is a reset button and 4 hardware serial port
called USART which produces a maximum speed for setting up communication.Arduino
Mega is specially designed for the projects requiring complex circuitry and more memory
space. Most of the electronic projects can be done pretty well by other boards avail-
able in the market which make Arduino Mega uncommon for regular projects. However,
there are some projects that are solely done by Arduino Mega like making of 3D printers
or controlling more than one motors, because of its ability to store more instructions in
the code memory and a number of I/O digital and analog pins.
10.5 NodeMCU
NodeMCU is an open source IoT platform.It includes firmware which runs on the
ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-
12 module.NodeMCU Development board is featured with wifi capability, analog pin,
digital pins and serial communication protocols. The term ”NodeMCU” by default refers
to the firmware rather than the development kits. The firmware uses the Lua scripting
language.NodeMCU provides access to the GPIO (General Purpose Input/Output) and
for developing purposes pin mapping table should be referenced. It is an highly inte-
grated chip designed to provide full internet connectivity in a small package. It can be
programmed directly through USB port using LUA programming or Arduino IDE.
59
Figure 10.7: NodeMCU
60
Figure 10.9: serial
2. StaticJsonBuffer
DynamicJsonBuffer updates the memory automatically according to the requirement.
Where StaticJsonBuffer allocates fixed memory and will not change according to the
requirement. Here we have created a StaticJsonBuffer with a size 200. JsonObject is
where the key-value pairs are stored. The memory of the JsonObject is located in the
buffer. The key-value pairs are generated as shown below
1 J s o n O b j e c t& r o o t = j s o n B u f f e r . c r e a t e O b j e c t ( ) ;
2 r o o t [ ” data1 ” ] = 1 0 0 ;
To print the JsonObject to the serial port the following command is used
1 root . printTo ( s ) ;
61
10.6 Raspberry Pi
Now let’s set pin 7 as output and turn it off, then on and then off again:
1 g p i o mode 7 out
2 gpio write 7 0
62
Figure 10.12: Connecting the circuit
Figure 10.13: Control the Raspberry Pi GPIO pins and turn an LED on
3 gpio write 7 1
4 gpio write 7 0
63
Figure 10.14: Relay Module
10.7.1 Principle
From the picture below, you can see that when the signal port is at low level, the signal
light will light up and the optocoupler 817c (it transforms electrical signals by light and
can isolate input and output electrical signals) will conduct, and then the transistor will
conduct, the relay coil will be electrified, and the normally open contact of the relay will
be closed. When the signal port is at high level, the normally closed contact of the relay
will be closed. So you can connect and disconnect the load by controlling the level of
the control signal
Pin Description Input: VCC: Positive supply voltage GND: Ground IN1–IN4: Relay
64
v+
2. There are four fixed screw holes at each corner of the board, easy for install and
fix. The diameter of the hole is 3.1mm
3. Relay is used with single pole double throw, a common terminal, a normally open
terminal, and a normally closed terminal
5. Closed at low level with indicator on, released at high level with indicator off
65
Chapter 11
66
Figure 11.1: IoT systems
In the middle, we have the cloud where data from many sources is aggregated and
analyzed in real time, often by an IoT analytics platform designed for this purpose.
The right side of the diagram depicts the algorithm development associated with the
IoT application. Here an engineer or data scientist tries to gain insight into the collected
data by performing historical analysis on the data. In this case, the data is pulled from
the IoT platform into a desktop software environment to enable the engineer or scientist
to prototype algorithms that may eventually execute in the cloud or on the smart device
itself.
An IoT system includes all these elements. ThingSpeak fits in the cloud part of
the diagram and provides a platform to quickly collect and analyze data from internet
connected sensors.
• Easily configure devices to send data to ThingSpeak using popular IoT protocols.
• Prototype and build IoT systems without setting up servers or developing web
software.
• Automatically act on your data and communicate using third-party services like
Twilio
R or Twitter
.
R
67
Figure 11.2: Real-Time Analysis : Dashboard
11.3.2 IdealUsage
When the power utilization is below the ideal limit
68
11.4 Formula Composer
With the recently released Formula Composer tool you can create formula-based meter-
s/graphs by doing operations and conditions across real meters, data points, constants
and any numeric value. All created formula-points can be added to the dashboard and
used for reports, charts and alerts. UPD: Added X-axis to find a correlation factor and
linear regression formula in 2 clicks.
11.8 Reporting
Analyse and compare your consumption and associated costs to identify where your
money is spent within your organisation and where energy saving efforts must focus on.
You can discover increase/decrease trends over periods and calculate your savings. You
can also enter adjustment values.
69
11.11 Performance Metrics
Power usage effectiveness (PUE) is a measure of how efficiently a data center uses energy.
Wattics dashboard provides you the tools to monitor in real-time your data centre PUE
and be alerted whenever inefficiency is detected.
70
Chapter 12
71
12.2 Calculating Real Power on an Arduino
Real power is the average of instantaneous power. The calculation is relatively straight-
forward.First we calculate the instantaneous power by multiplying the instantaneous
voltage measurement by the instantaneous current measurement. We sum the instanta-
neous power measurement over a given number of samples and divide by that number
of samples:
1 f o r ( n=0; n// i n s t v o l t a g e and i n s t c u r r e n t c a l c u l a t i o n from raw ADC i n p u t
goes here
2
3 inst power = inst voltage ∗ inst current ;
4
5 s u m i n s t p o w e r += i n s t p o w e r ;
6 }
7 real power = sum inst power / number of sample
1 Same a s t h e RMS v o l t a g e c a l c u l a t i o n :
2 f o r ( n=0; n// i n s t c u r r e n t c a l c u l a t i o n from raw ADC i n p u t g o e s h e r e .
3
4 squared current = inst current ∗ inst current ;
5
6 s u m s q u a r e d c u r r e n t += s q u a r e d c u r r e n t ;
7 }
8
9 mean square current = sum squared current / number of samples ;
10 root mean square current = sqrt ( mean square current ) ;
As RMS voltage is generally a fixed value such as: 230V (+10 percent-6 percent in
the INDIA). It’s possible to approximate apparent power without making a voltage
measurement by setting the RMS voltage to 230V. This is a common practice used by
commercially available energy monitors.
72
1
2 power factor = real power / apparent power ;
73
Chapter 13
Load Forecasting
Accurate models for electric power load forecasting are essential to the operation and
planning of a utility company. Load forecasting helps an electric utility to make im-
portant decisions including decisions on purchasing and generating electric power, load
switching, and infrastructure development. Load forecasts are extremely important for
energy suppliers, ISOs, financial institutions, and other participants in electric energy
generation, transmission, distribution, and markets.
Load forecasts can be divided into three categories: shortterm forecasts which are
usually from one hour (increasingly shorter durations are now common) to one week,
medium forecasts which are usually from a week to one year, and long-term forecasts
which are longer than a year. The forecasts for different time horizons are important for
different operations within a utility company. The natures of these forecasts are different
as well. For example, for a particular region, it may be possible to predict the next day
load with an accuracy of approximately 1-3 percent. However, it may be impossible
to predict the next year peak load with the similar accuracy since accurate long-term
weather forecasts are unavailable.
For the next year peak forecast, it is possible to provide the probability distribution
of the load based on historical weather observations. It is also possible, according to
the industry practice, to predict the so-called weather nornalized load, which would take
place for average annual peak weather conditions or worse than average peak weather
conditions for a given area. Weather normalized load is the load calculated for the so-
called normal weather conditions which are the average of the weather characteristics
for the peak historical loads over a certain period of time. The duration of this period
varies from one utility to another. Most companies take the last 25-30 years of data.
Load forecasting has always been important for planning and operational decision
conducted by utility companies. However, with the deregulation of the energy industries,
load forecasting is even more important. With supply and demand fluctuating and
the changes of weather conditions and energy prices increasing by a factor of ten or
more during peak situations, load forecasting is vitally important for utilities. Short-
term load forecasting can help to estimate load flows and to make decisions that can
prevent overloading. Timely implementations of such decisions lead to the improvement
of network reliability and to the reduced occurrences of equipment failures and blackouts.
Load forecasting is also important for contract evaluations and evaluations of various
sophisticated financial products on energy pricing offered by the market.
In the deregulated economy, decisions on capital expenditures based on long-term
74
forecasting are also more important than in a non-deregulated economy when rate in-
creases could be justified by capital expenditure projects. Most forecasting methods
use statistical techniques or artificial intelligence algorithms such as regression, neural
networks, fuzzy logic, and expert systems. Two of the methods, so-called end-use and
econometric approach are broadly used for medium- and long-term forecasting. A va-
riety of methods, which include the so-called similar day approach, various regression
models, time series, neural networks, statistical learning algorithms, fuzzy logic, and
expert systems, have been developed for short-term forecasting.
75
ant colony optimization by combining the clustering algorithm with the optimal theory.
The literature presents an effective application of support vector clustering to electrical
load profiles clustering analysis study. Hierarchical clustering has high accuracy and
low efficiency, and partitioning clustering has high efficiency and low accuracy, which is
proved by literature, then an ensemble clustering algorithm is proposed through combin-
ing hierarchical clustering with partitioning clustering. However, load shape variability
is essential in load profiling which exhibits the customers’ different behaviors and char-
acteristics. Traditional clustering methods based on Euclidean distance measure have
the disadvantages that: 1) do not have the ability of shape pattern recognition because
they only considers the distance between points to points lacking of piecewise trend
information . In other words, they assume that the order of the data points is not
important.
They give us the same result when we permute the time points. They may lose some
important information about the profile shape pattern. 2the clustering of load profiles
needs to consider all dimensions in the dataset that focus on the global properties. With
the increasing number of dataset dimensions, the meaning of distance similarity metrics
becomes less and less.
The results of clustering depend on both the algorithm and the resolution of the
data . However, few clustering methods consider the effects of data granularity on
the performance for analyzing power demand profiles. It is not an efficient method
to process the raw data directly since the data may be very large and contain many
redundant details. Traditionally, the approximation of time-series load profile data has
a fixed temporal resolution that is usually 15, 30 or 60 minutes according to the clustering
experiments. It is essential to determine a resolution that is a tradeoff between the level
of details that represent the characteristics of the load profiles, and the necessities to
process data.
76
Chapter 14
Conclusion
A low cost solution for the real-time energy management in a smart grid is presented.
It provides several power meters, that continuously monitor connected loads . This
network can be easily installed in a home and in an industrial grid with the possibility
to monitor the various loads through friendly user interfaces both local as well as remote.
The progress in technology about electrical distribution network is a non-stop pro-
cess. In the present work wireless meter reading system is designed to continuously
monitor the meter reading and to shut down the power supply remotely whenever the
consumer fails to pay the bill. It avoids the human intervention, provides efficient meter
reading, avoids the billing error and reduces the maintenance cost. It displays the corre-
sponding information on LCD for user notification. The Smart energy metering system
requires less manpower, there is no need to chase payments, power theft detection is pos-
sible, bill is sent to the consumer with due date, can minimize the power consumption
in a house.Energy management at the consumer end by controlling the loads will help
the consumer also to participate and share the responsibility in proper management of
energy. Among the various methods through which this could be done, smart scheduling
from the consumer end is an excellent option.We proposed an Off-line Load Scheduling
Algorithm that aims at maximizing the energy savings along with the reduction in cost
of energy consumption.
This algorithm tries to shift loads to off-peak hours and hours with lower electric-
ity cost thus relieving the utility grid from peak demand at the same time providing
economic benefit to the consumer.
14.1 Benefits
• Far greater (and more detailed) feedback regarding energy use.
77
• Provides real-time data that is useful for balancing electric loads while reducing
power outages (i.e., blackouts).
• Enables dynamic pricing, which raises or lowers the cost of electricity based on
demand.
• Prevents the need for new power plants that produce greenhouse gases that sub-
stantially creates pollution that creates health risks.
• Helps curb existing greenhouse gas emissions from existing power plants.
14.2 Drawbacks
• The cost in terms of personnel training and equipment development and production
to transition to a new technology and new set of processes.
• Managing negative public reaction and acquiring customer acceptance of the new
meters.
• Making a long-term financial commitment to the new metering technology and the
related software involved.
78
Chapter 15
Future Scope
79
15.3 Detect the presence of residence
The loads like TV, lights etc can be switched off when the device detects the absence of
user in the house.
80
Bibliography
[1] Javaid, N., Ullah, I., Akbar, M., Iqbal, Z., Khan, F. A., Alrajeh, N., Alabed, M. S.
(2017). An Intelligent Load Management System With Renewable Energy Integration
for Smart Homes. IEEE Access, 5, 13587–13600.
[2] Sukumaran, S., Sudhakar, K. (2017). Fully solar powered airport: A case study of
Cochin International airport. Journal of Air Transport Management, 62, 176–188.
[3] Clarizia, F., Gallo, D., Landi, C., Luiso, M., Rinaldi, R. (2016). Smart meter
systems for smart grid management. 2016 IEEE International Instrumentation and
Measurement Technology Conference Proceedings.
[4] Smart Metering and Functionalities of Smart Meters in Smart Grid - A Review Gouri
R. Barai, Sridhar Krishnan, and Bala Venkatesh,, IEEE Department of Electrical
Computer Engineering, Ryerson University, Toronto, Ontario, M5B 2K3, Canada.
EPEC 2015 London, ON, Canada 978-1-4799-7664-5/15/
[5] Micro-scale Smart Grid Optimization Nathan Kowahl, and Anthony Kuh, Member
.IEEE.
[6] Approach for forecasting smart customer demand with significant energy demand
variability Zafar A. Khan*, Student Member IEEE, Dilan Jayaweera, Senior Mem-
ber IEEE School of Electronic, Electrical and Systems Engineering, University of
Birmingham (U.K)
[7] G. Aurilio, D. Gallo, C. Landi, M. Luiso and G. Graditi, ”A low cost smart meter
network for a smart utility,” 2014 IEEE International Instrumentation and Measure-
ment Technology Conference (I2MTC) Proceedings, Montevideo, 2014, pp. 380-385.
[8] V. Preethi and G. Harish, ”Design and implementation of smart energy meter,” 2016
International Conference on Inventive Computation Technologies (ICICT) Coimbat-
ore, 2016, pp. 1-5.IEEE 31st International Conference on Data Engineering, Seoul,
2015, pp. 1476-1479.
[9] W. Luan, D. Sharp, and S. Lancashire, “Smart grid communication capacity plan-
ning for power utilities,” in Proc. IEEE Power Energy Soc.Transmiss. Distrib. Conf.
Expo., New Orleans, LA, USA, Apr. 2010, pp. 1–4.
[10] Ž. Popović and V. Čačković, ”Advanced Metering Infrastructure in the context of
Smart Grids,” 2014 IEEE International Energy Conference (ENERGYCON), Cavtat,
2014, pp. 1509-1514
81
[11] Pedrasa, M. A. A., Spooner, T. D., MacGill, I. F. (2010). Coordinated Scheduling of
Residential Distributed Energy Resources to Optimize Smart Home Energy Services.
IEEE Transactions on Smart Grid, 1(2), 134–143. doi:10.1109/tsg.2010.2053053.
[13] S. Hatami and M. Pedram, “Minimizing the Electricity Bill of Cooperative Users
under a Quasi-Dynamic Pricing Model,” in IEEE International Conference on Smart
Grid Communications (SmartGridComm), 2010, pp. 421–426.
[14] O. A. Sianaki, O. Hussain, A.R Tabesh “ A knapsack problem approach for achiev-
ing efficient energy consumption in smart grid for end-users’ life style,” IEEE Con-
ference on Innovative Technologies for an Efficient and Reliable Electricity Supply
(CITRES), 2010, pp. 159– 164.
[16] C. Chekuri and S. Khanna “A PTAS for the multiple knapsack problem,” Proceed-
ings of the 11th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA),
2000, p213.
[18] Kaystha, Sarsij, and Suneeta Agarwal. ”Greedy genetic algorithm to Bounded
Knapsack Problem.” Computer Science and Information Technology (ICCSIT), 2010
3rd IEEE International Conference on. Vol. 6. IEEE, 2010.
[20] Xi Fang, Satyajayant Mishra, Guoliang Xue and Dejun Yang, “Smart Grid- the
new and improved powergrid: a Survey”, IEEE communication surveys tutorials,
vol- 14, no.- 4, fourth quarter, 2012.
[21] I.S.Jha, Y.K.Sehgal, Subir Sen, Rajesh Kumar, “Smart Grid in Indian Power Sys-
tem”,NPSC, 2012.
[22] M. Popa, H. Ciocarlie, A. S. Popa, and M. B. Racz, “Smart metering for monitor-
ing domestic utilities,” in 14th International Conference on Intelligent Engineering
Systems (INES), 2010, pp. 55–60.
82
Appendix A
Work Division
5. Fabrication and simulation of logic circuit and analog circuit and design of PCB
layout using easyeda.
He expand his expertise through taking Operations Research (Elective) under KTU. He
over-looked metering algorithm, Iot platfrom and creation of web interface(www.smartpepper.tk).
He has been a ernest mentee under Rahul Sivan(CEO ATWIC Research Development
Pvt Ltd).https://in.linkedin.com/in/rahul-sivan-691aa729
5. PCB designing
83
A.3 Christina George
1. simulated the pf measurement unit on proteus.
4. PCB soldering
84
Appendix B
Reference paper
85
Residential Task Scheduling Under Dynamic
Pricing Using the Multiple Knapsack Method
Kumaraguruparan N., Sivaramakrishnan H., and Sachin S. Sapatnekar
ECE Department, University of Minnesota–Twin Cities, Minneapolis, MN 55455
Abstract— A key component of the smart grid is the ability to The idea of dynamic pricing is a key component of the
enable dynamic residential pricing to incentivize the customer residential smart grid, where the utility creates a time-varying
and the overall community to utilize energy more uniformly. rate structure over time. The user is given more responsibility
However, the complications involved require that automated
wherein s/he determines and controls when s/he needs a
strategies be provided to the customer to achieve this goal. This
paper presents a solution to the problem of optimally scheduling particular appliance in his household. Moreover, as locally-
a set of residential appliances under day-ahead variable peak generated power at the residential level proliferates (e.g.,
pricing in order to minimize the customer’s energy bill (and also, through home solar panels), the residential user is provided
simultaneously spread out energy usage). We map the problem with an opportunity to supply excess electricity back to the
to a well known problem in computer science – the multiple grid, with monetary compensation. This local generation and
knapsack problem – which enables cheap and efficient solutions
use of power through renewable sources of energy helps
to the scheduling problem. Results show that this method is
effective in meeting its goals. reduce the overall carbon footprint and greenhouse gas
Index Terms—Cost Function, Dynamic Scheduling, Multiple emissions.
Knapsack Problem (MKP), Optimization, Smart Grids. Strategies for reducing the cost of residential power of
include reducing the power consumption or shifting the
temporal profile of power consumption to consumption at
I. INTRODUCTION cheaper times, where possible [3]. Within the framework of
With ever-increasing and imbalanced electrical demands, there this paper, we do not aim to reduce the power consumption of
is a clear realization that further efficiencies can and must be a household, but instead study how the power consumption of
achieved by embedding intelligence into the power grid. Since a household can be shifted to off-peak hours so that the user
1982, the growth in peak demand has exceeded transmission benefit financially, and the load on the system is better
growth by almost 25% every year [1]. This growing demand balanced through the day. This behavior is incentivized
for electricity and the steep increase in the power consumption through pricing strategies: incentives are provided to the users
of a household arising as a result of various technological who are willing to move in their appliances to off-peak hours
improvements, pose a stiff challenge to the future electricity though dynamic pricing. Shifting consumption in this way is a
distribution systems. The smart grid has emerged as a solution powerful strategy: the Pacific Northwest National Laboratory
that provides benefits to all parties involved: to the utilities states that existing U.S. power plants could meet the electricity
because it provides better demand management, to the needs of 73% of the nation’s light vehicles (i.e., cars and small
customer because of its potential for economy, and to the trucks) if the vehicles were replaced by plug-ins that recharged
environment because of the ability to reduce greenhouse gas at night. Such a shift would reduce oil consumption by 6.2
emissions. million barrels per day [1].
The European Technology Platform Smart Grids (ETP There are several variants of dynamic pricing [16]:
Smart Grids) defines smart grids as “electricity networks that • Time of use pricing establishes a variable price structure
can intelligently integrate the behavior and actions of all users for peak, shoulder, and off-peak hours. These prices are
connected to it – generators, consumers and those that do both typically established well in advance, e.g., a year ahead.
– in order to efficiently deliver sustainable, economic and • Real-time pricing allows the prices to change on an
secure electricity supplies” [2]. The smartness in the design of hourly basis, based on market demand.
the infrastructure of a smart grid is attributed to allowing the • Variable peak pricing is a hybrid of the two, and
users to play a significantly larger role in optimizing and establishes variable pricing in the day, defined a day
reducing their power consumption thereby increasing the ahead.
efficiency of the system. Estimates show that smart electricity Various pilot projects have tested the notion of dynamic
grids should reduce CO2 emissions in the EU by 9% and the pricing based on real-time pricing and variable peak pricing,
annual household energy consumption by 10% [2]. and it has been concluded that customers show exhibit price
There are numerous technical issues involved in enabling responses within this environment that provides mutual benefit
smart grid infrastructure, and this paper will focus on the to all [17].
problem of managing and scheduling residential power We focus, in particular, on the model of day-ahead variable
demand under a dynamic pricing system. peak pricing. Under this model, the benefit to the smart grid
86
depends on how effectively it is able to shift the appliances to based on a priority ranking, and completion times for tasks
the off-peak hours. In the context of near-future power cannot be trivially captured or guaranteed.
consumption patterns, smart scheduling approaches are In this paper, we develop a formulation that can be used to
becoming particularly significant. For example, the advent of schedule appliances using the multiple knapsack problem
plug-in hybrid electric vehicles (PHEVs) is anticipated to (MKP) approach. Our schedule has several important features:
place a significant and large load on the grid; however, in • We consider the effect of must-run services (such as
many cases, customers will need the vehicle to be charged lights, refrigerators, etc.) that must always be on and
during some period between a customer-specified start and cannot be scheduled, as well as tasks that can be flexibly
end time (e.g., between 9pm and 9am). Smart scheduling scheduled in time.
algorithms can reduce the impact on the global grid by • We incorporate the effects of local power generation
distributing this charging period and/or charging the vehicle sources in the objective function
during noncontiguous time slots. • We consider the case where task deadlines must be
Several algorithms and techniques have been proposed in imposed and permit tasks to occupy noncontiguous time
the context of scheduling under dynamic residential pricing. slots.
Pedrasa et al. [4] use a modified form of coevolutionary The rest of the paper is organized as follows: Section II
particle swarm optimization (CPSO) with stochastic repulsion formally presents the problem statement, the definition of the
amongst particles, referred to as CPSO-R, for their scheduler. terminology used in the paper, and shows the mapping from
The scheduler determines when various devices in the the scheduling problem to an instance of the MKP problem.
household need to co-ordinate with each other to increase the The formulation of the deterministic model of our problem is
benefits (during the peak-load hours) and when they can explained in section III. The experimental results of are
operate independently (at times when coordinating with each discussed in section IV, and the paper is then concluded in
other does not add significant value). However, stochastic section V.
optimization techniques can be computationally expensive. If
performed locally within the home, they may require II. PRELIMINARIES
significant computational resources; if performed offline, the
In this section, we first formally state the parameters of the
combined computation associated with a large number of
residential scheduling problem, followed by a definition of the
homes may be very significant.
terminology used within the paper. We then consider the
Mohsenian-Rad et al. [5] present a game-theoretic approach
multiple knapsack problem (MKP) and discuss the mapping
to solving this problem. As outlined earlier, smart scheduling
between our scheduling problem and an instance of the MKP.
has the potential to benefit all players. Through their analysis,
referred to as energy consumption scheduling (ECS), devices A. Problem Statement
work with current pricing policies to choose a schedule, while This section describes the problem statement, stating the
the prices are set by the cumulative demand at any time of the requirements on the design of the scheduler.
day. The consumers within the community aim to reach an The consumers within a smart grid community are charged
equilibrium condition, the Nash Equilibrium, which provides depending upon the net power consumed from the smart grid
the globally optimal solution to the scheduling problem, while based on a variable peak pricing model. The energy prices for
providing considerable cost savings to the community as a a specific period of time is set in advance (e.g., a day ahead).
whole. However, this work does not consider dynamic Consumers with smart appliances may define allowable
effects, such as rates of response for the pricing structure and periods when their appliances are to be used. Models for the
for consumption. If the pricing structure changes too rapidly, specifications include:
the settling time for achieving the Nash equilibrium may be an • Must-run schedules for appliances that must be
issue; if it changes too slowly, it may not predict the demand operational at all times, such as lights, refrigerators, and
on a specific day. winter heating in cold climates.
In other work, Hatami et al. [6] introduce a quasi-dynamic • Fixed schedules that apply to appliances that must run at
pricing function and build a scheduler that can work with specific fixed times
interruptible tasks, i.e., tasks that need not be run in • Flexible schedules that apply to appliances that must run
contiguous intervals of time. Sianaki et al. [7] introduce a for a specified amount of time, anytime within a flexible
single knapsack problem based approach to achieve energy interval.
efficient consumption in smart grids by mapping the The goal of the approach is to optimally schedule the
scheduling problem to a standard dynamic programming operating times of all appliances so that they meet the
model, the knapsack problem. The authors take into account constraints imposed by the list above, while minimizing the
the preference of the consumers within a community before electricity bill for the household. The household may contain
determining the schedule. The appliances are prioritized by the a mix of smart appliances that can be scheduled and
respective consumers and this priority function of an appliance appliances without inbuilt intelligence, which are manually
plays an important role when scheduling during peak-load operated. For the purposes of this work, we consider only the
hours. However, under this framework, appliances are chosen scheduling of smart appliances. The schedules for manually
87
operated appliances, if available, can be provided as limited maximized. Single knapsack problems are a standard problem
time fixed must-run applications. template in computer science, and numerous practical
Thus the goal of the scheduler is to schedule the appliances problems have been mapped on to this problem. The fractional
within the household to minimize the electricity bill, while version of the knapsack problem can be solved using dynamic
contending with constraints such as the preferences of the programming techniques in polynomial time. The integer
user, the price model, and the requirement that all the problem is NP-complete, but a number of efficient
appliances must be scheduled within the given time frame. polynomial-time approximation algorithms are available to
provide near-optimal solutions [8].
B. Key terms and Notation
The multiple knapsack problem (MKP) [8–12] is a
Cost function: The cost function Cost(t) represents the cost of generalization of the single knapsack problem. In essence, the
consumption of a certain amount of energy at a time instant t. MKP is a resource allocation problem wherein there is a set of
It is assumed that variable peak pricing is followed where the m resources (i.e., m knapsacks) and a set of n objects. As in
cost function varies with the time in the day. Generally the the single knapsack problem, each object i in this set of n
cost of power consumption is high during the peak-hours objects has two important attributes associated with it: the
(evenings and mornings) and is considerably low during value of the object and its weight. Every resource (knapsack) j
periods of low power usage (afternoons and late nights); has a capacity constraint Cj, which represents the maximum
exceptions to these scenarios correspond to examples such as weight that the resource can support. The objective of the
heat waves, where energy consumptions in the afternoon may MKP is to find a subset of the objects that can be packed
be large. Day-ahead pricing, combined with weather within the bins such that the net value of all objects within all
forecasts, provides utilities with the tools to vary these prices knapsacks is maximized. Although the integer MKP problem
in a quasi-dynamic way. is NP-complete, in practice optimal or near-optimal solutions
Practically speaking, the cost function is implemented as a are available in polynomial time or for very reasonable
discrete piecewise-constant cost function, Costij, as illustrated runtimes [9,14].
in Figure 1. The per-unit price is altered to discrete values at
discrete time steps, e.g., at the top of every hour. In our D. Mapping the Scheduling Problem to the MKP
exposition, we assume that the time slots are of equal length, The mapping between our scheduling problem and the MKP is
but it is rather simple to extend this approach to the case now outlined:
where the time slot lengths are not the same. • The m knapsacks correspond to m time intervals where
FIGURE 1: AN EXAMPLE COST FUNCTION, CORRESPONDING TO the energy price is fixed.
THE COST DATA THAT WILL BE SHOWN IN TABLE II. • The n appliances correspond to n objects that must be
Locally-generated power: This term may include any packed.
renewable sources of energy such as wind energy or solar • The weight of each object is the energy Ei consumed by
energy, that is generated on-site. These sources of energy are appliances Ai in each time slot. Note that Ei is
not deterministic but may be reflected by their expected independent of t.
values. Again, weather forecasts may be used to predict these • The value of the object in a specific time slot is the cost of
power consumption of the appliance in that time slot,
defined by the Costij function described in Section IIB.
• The bin capacity, or the capacity of the knapsack j,
capacityj, is the maximum energy that can be drawn from
the grid in any time slot j. For the customer, this can help
ensure that the electricity bill can be controlled, and for
the utility, enforcing this limit ensures that the grid is not
overstressed; in the absence of this, the customer may
well always choose the least expensive time slot! For our
purposes, we consider this limit on a per-household basis.
A variation of the problem formulation applies this on a
per-community basis, but this requires simultaneous
values on a day-ahead basis. scheduling of all devices in all households in a
community, which is onerous and probably not
C. The Multiple Knapsack Problem
worthwhile. Such constraints can be enforced at other
In this paper, we map the scheduling problem to a multiple points of the smart grid.
knapsack problem. We begin by providing a brief overview of
knapsack problems. III. MODELING THE OBJECTIVE FUNCTON AND CONSTRAINTS
The (single) knapsack problem is a combinatorial problem
The description of the problem formulation is divided into two
where a number of objects, each associated with a value and a
subphases: initially we describe a formulation that schedules
weight, must be packed into a knapsack of a specific capacity,
only the smart appliances, as specified by the consumer. Next,
such that the value of the objects within the knapsack is
we extend to formulation to account for must-run services and
88
locally-generated power. adds a constant quantity to the objective function, the
function to be minimized is unchanged from (2).
A. Initial Scheduling
• The capacity constraint is altered since an amount Emj of
Let us consider n appliances within a smart grid that has to be the capacity is utilized in time slot j by must-run services.
scheduled in m time slots. Recall that the cost function, This implies that the capacity constraint changes to:
Cost(t), is a piecewise constant function that reflects the cost n
of power consumption at a time slot t, and that capacity(t) is "E X ! capacity j # Emj (5)
i ij
the maximum power capacity in time slot t. Let Treq,i be the i=1
time that is required by an appliance Ai to complete its task: Clearly, for a meaningful solution, it is necessary to ensure
this is specified in units of of the number of time intervals. that
This value of Treq,i will be the same across all time slots for an capacity j ! Emj " 0
appliance i since the power consumed by the appliance is a i.e., that the must-run services use energy that is under the
constant. capacity at any time slot j.
We now present the optimization formulation as a discrete The role of locally-generated power is dual to the role of must-
linear program that has the form of the MKP. We introduce run services. If Pgj represents the power that is generated by
the Boolean integer variable, Xi(t), defined as the local power source at time slot j, then this amount
!# 1 if the appliance is on in time slot j subtracts from the total cost of energy, and using the same
Xij = " (1) argument as above, the objective function is left unchanged.
$# 0 if the appliance is off in time slot j An interesting case is the situation where the value of the
The objective function can now be formulated as locally-generated power, Pmj, exceeds the demand (equation
n #m & (2)) in slot j. In this case, the power is sold back to the utility,
min " Ei %%" Xij ! Cost j (( (2)
and the goal of minimizing the objective function still
i=1 $ j=1 ' achieves the goal of maximizing the dollar gains to the
homeowner of selling electricity back to the grid.
Here, Xij is an indicator variable that states whether the Costj In addition to the above, locally-generted power alters the
term in slot j should contribute to the cost function or not. If capacity constraint, which now becomes
so, this term, which represents the unit cost in that slot, is n
multiplied by the energy usage during that period. "E X i ij ! capacity j # Emj + Pgj (6)
i=1
There are several constraints that must be obeyed. The overall optimization problem can be stated using the
Specifically: objective in (2), and constraints corresponding to (1), (3), and
Completion constraints are designed to ensure that each task is (6).
completed during the time period in question (e.g., one day).
For each appliance i, these can be formulated as: 35!
m
(3) 30!
!X ij = Treq,i 25!
j=1
20! X2j (t)!
which states that an appliance i must be provided with enough 15! X1j (t)!
time slots to complete its function. Clearly, this constraint 10!
support noncontiguous time slots for various appliances as 5!
0!
long as the total Treq,i constraint is met. 1! 2! 3! 4!
Capacity constraints may be used to control the total energy X2j (t)! 20! 20! 0! 0!
usage of a home and help incentivize energy usage that is
X1j (t)! 10! 10! 0! 10!
more distributed in time and uniform. For each time slot j,
these are stated as
n
(4) FIGURE 2: RESULTS FOR THE SIMPLE EXAMPLE
"E X i ij ! capacity j
i=1
IV. AN EXAMPLE
B. Incorporating Must-run Services and Locally-Generated
We test our formulation initially for a small case study with
Power
a small number of appliances and time grids and then enlarge
The formulation is now extended to include the power the case study to schedule a larger set of appliances within an
consumed by the must-run services and locally-generated entire day. The specifics of the small example are as follows:
power. Let us consider Emj to be the power that is consumed Appliances: Two appliances, A1, A2
by the must-run services at a time slot j. As a result, the energy Time discretization: 4 time slots, T1. T2, T3, T4
consumption in slot j must be incremented by Emj for all slots Energy usage: E1 = 10 units, E2 = 20 units
j. The effects of this change are: Task time requirements: Treq,1 = 3, Treq,2 = 2
• The total cost of energy goes up by Emj Costj which Capacity of each time slot: capacity1 = capacity2 = 30 units
should affect the objective function; however, since this
89
Cost during each time slot:
Cost1 = 10 Time slot Costj capacityj Emj Egj
Cost2 = 20 j
Cost3 = 30 1 100 500 50 20
Cost4 = 20 2 200 500 0 10
For simplicity, we set 3 300 500 50 20
Must-run usage = Locally-generated power = 0 in all slots 4 200 500 0 0
As seen earlier, these parameters simply affect the right-hand 5 100 500 100 0
side of the capacity constraints, and can be considered as 6 400 500 50 0
alterations to the capacity. 7 200 500 50 0
The optimization problem can then be formulated as: 8 300 500 0 0
min E1 ( X11 ! Cost1 + X12 ! Cost2 + X13 ! Cost3 + X14 ! Cost4 ) + 9 100 500 50 0
E2 ( X 21 ! Cost1 + X 22 ! Cost2 + X 23 ! Cost3 + X 24 ! Cost4 ) 10 200 500 0 30
subject to: 11 200 500 0 30
E1 X11 + E2 X12 + E3 X13 + E4 X14 ! capacity1 " Em1 + Eg1 12 300 500 0 30
13 200 500 0 20
E1 X 21 + E2 X 22 + E3 X 23 + E3 X 24 ! capacity2 " Em2 + Eg2
14 200 500 50 20
X11 + X12 + X13 + X14 = Treq,1 15 200 500 50 10
X 21 + X 22 + X 23 + X 24 = Treq,2 16 300 500 0 10
X 21, X 22 , X 23, X 24 # {0,1} TABLE II: DESCRIPTION OF THE TIME SLOTS
We apply our solution to a testcase with 18 appliances and
The optimal solution for this problem is shown in Figure 2:
16 time slots. The parameters for the appliances are described
appliance A1 operates in slots 1, 2, and 4, while appliance A2
in Table I, and the characteristics of the time slots are
operates in slots 1 and 2. Clearly, it meets the requirements
described in Table II. The capacity constraint at each of the
Treq,1 and Treq,2 as well as the capacity constraints. It can be
16 time slots is uniform and is set to 500 units.
seen that the schedule evades any consumption in the most
The results of the optimization are shown in Figure 3. The
expensive slot, slot 3, and fully uses the least expensive slot,
figure at left is a stacked bar chart, where the x-axis lists the
slot 1, and that the tasks are scheduled in interruptible
time slots from 1 to 16, and the y-axis lists the energy usage.
fashions.
The small bars below the x-axis correspond to locally-
generated power. The energy usage of all appliances is added
V. SIMULATION AND RESULTS
up to create the height of the stack: it is easily seen that the
The optimization problem formulated above was solved using capacity constraint of 500 units is met at each time slot, and
the What’sBest solver [14]. What’sBest is an add-on to that electricity usage is uniform, except for a few time slots.
Microsoft Excel and allows building large linear, non-linear, This achieves the goal of forcing the customer to make energy
integer, or stochastic optimization models within a usage more uniform across the day.
spreadsheet.
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18
Treq,i 3 2 1 2 3 2 1 2 3 1 2 3 3 1 2 3 1 2
Ei 100 200 150 250 50 100 200 150 250 50 200 300 100 300 200 150 200 150
TABLE I: APPLIANCE PARAMETERS
FIGURE 3: RESULTS FROM AN 18-APPLIANCE, 16-TIME-SOLOT PROBLEM. THE STACKED BAR CHART AT LEFT SHOWS THE ENERGY
USAGE OF THE APPLIANCES, AND THE FIGURE AT RIGHT SHOWS THE COST PER UNIT (BLUE) AND THE TOTAL USAGE PER TIME SLOT.
90
We explore the low-usage time slots in the right part of Conference on Innovative Technologies for an Efficient
Figure 3. The x-axis represents time and shows the 16 time and Reliable Electricity Supply (CITRES), 2010, pp. 159–
slots. The two plots show the cost (blue) and the total energy 164.
usage (red) in each time slot. We focus on the four time slots [8] H. Kellerer, U. Pferschy, and D. Pisinger, Knapsack
(#3, #6, #12, and #16) with nonmaximal usage: it can be see Problems, Springer, 2004.
from the blue bars and from Table II that these correspond to [9] C. Chekuri and S. Khanna “A PTAS for the multiple
the highest Costi values. Since the goal of the optimization is knapsack problem,” Proceedings of the 11th Annual
to minimize customer cost, these slots are left ununsed or ACM-SIAM Symposium on Discrete Algorithms
underused. (SODA), 2000, p213.
[10] S. Fidanova, "Evolutionary algorithm for
multidimensional knapsack problem", PPSNVII-
VI. CONCLUSION
Workshop, 2002.
We have presented an approach to enable residential energy [11] F. Diedrich and K. Jansen, “Improved approximation
scheduling under a dynamic pricing paradigm. Our algorithms for scheduling with fixed jobs”. Proceedings
experiments show that the method is effective in encouraging of the 20th ACM-SIAM Symposium on Discrete
uniformity in the energy profile in the home. Algorithms, p675, 2009.
Further constraints can easily be built into this system: [12] F. Diedrich, K. Jansen, F. Pascual, and D. Trystram.
although these have not been shown here. One example is “Approximation algorithms for scheduling with
when a customer wishes to constrain the time range in which a reservations,” in S. Aluru, M. Parashar, R. Badrinath, and
specific task is scheduled by specifying a preference. This is K. Prasanna, editors, HiPC, volume 4873 of LNCS, pages
quite simple to incorporate into the current system by reducing 297-307, Springer, 2007.
the number of Xij variables: if an appliance is not to be [13] LINDO API 6.0 User Manual, LINDO Systems Inc.
scheduled in a specified slot, the corresponding Boolean [14] “What’sBest” LINDO Systems Inc.,
variable is set to zero (and is therefore not a variable). This, in http://www.lindo.com/index.php?option=com_content&vi
ew=article&id=3&Itemid=11
fact, makes the optimization simpler since it reduces the
[15] M. Grant , S. Boyd and Y. Ye cvx: Matlab Software for
number of variables. Another example: we have enabled
Disciplined Convex
scheduling with interruptible tasks and sufficiently large time
Programming, http://www.stanford.edu/~boyd/cvx/
slots, but a customer may wish for some appliances to be [16] T. Flaim, R. Levy, and C. Goldman, “Dynamic Pricing in
scheduled in contiguous time slots (e.g., laundry tasks). In a Smart Grid World,” NARUC webinar, 2010,
this connection, for finer-grained scheduling, fractional time http://www.naruc.org/FERC/LBNL-Webinar3-
slots with contiguous scheduling may be desirable. We expect Dynamic%20Pricing%20in%20a%20Smart%20Grid%20
to include this in future work World.pdf
[17] B. Neenan and J. Eom, “Price Elasticity of Demand for
REFERENCES Electricity: A Primer and Synthesis.” Electric Power
[1] U.S. Department of Energy, The Smart Grid: An Research Institute, Palo Alto, CA, 2007. Available at:
Introduction, 2009. www.epri.com
[2] “What is a smart grid?” SmartGrids, European
Technology platform for the Electricity Networks of the
Future. http://www.smartgrids.eu/
[3] Energy Conservation Committee Report and
Recommendations, Reducing Electricity Consumption in
Houses. Ontario Home Builders’ Association, May 2006.
[4] M. Pedrasa, T. Spooner, and I. MacGill, “Coordinated
scheduling of residential distributed energy resources to
optimize ‘smart’ home energy services,” IEEE
Transactions on Smart Grids, Vol 1, p134-143, 2010.
[5] A. H. Mohsenian-Rad , V. W. S. Wong , J. Jatskevich and
R. Schober “Optimal and autonomous incentive-based
energy consumption scheduling algorithm for smart
grid,” IEEE PES Conf. Innovative Smart Grid
Technology, 2010.
[6] S. Hatami and M. Pedram, “Minimizing the Electricity
Bill of Cooperative Users under a Quasi-Dynamic Pricing
Model,” in IEEE International Conference on Smart Grid
Communications (SmartGridComm), 2010, pp. 421–426.
[7] O. A. Sianaki, O. Hussain, A.R Tabesh “ A knapsack
problem approach for achieving efficient energy
consumption in smart grid for end-users’ life style,” IEEE
91
Appendix C
1 import f i r e b a s e a d m i n
2 \ par
3 from f i r e b a s e a d m i n import c r e d e n t i a l s
4 \ par from f i r e b a s e a d m i n import db
5 \ par
6 import RPi . GPIO a s GPIO
7 \ par import time
8 \ par import u r l l i b . r e q u e s t
9 \ par import r e q u e s t s
10 \ par import t h r e a d i n g
11 \ par import j s o n
12
13 \ par import random
14 \ par import p i c k l e
15 \ par import time
16 \ par power = 0 . 0 0
17 # pip i n s t a l l fi reb ase ad min
18
19 # Fetch t h e s e r v i c e a c c o u n t key JSON f i l e c o n t e n t s
20 c r e d = c r e d e n t i a l s . C e r t i f i c a t e ( ’ . / key . j s o n ’ )
21
22 # I n i t i a l i z e t h e app with a s e r v i c e account , g r a n t i n g admin p r i v i l e g e s
23 f i r e b a s e a d m i n . i n i t i a l i z e a p p ( cred , {
24 ’ databaseURL ’ : ’ h t t p s : / / energy−m o n i t o r i n g −8ba45 . f i r e b a s e i o . com/ ’
25 })
26 r e f = db . r e f e r e n c e ( ’ / p r i c e P e r U n i t ’ )
27
28 HIGH =20
29 MEDIUM = 10
30 LOW = 5
31 totalPrice = 0
32 totaldayPrice = 0
33
34 GPIO . setmode (GPIO .BOARD)
35
36 # Status v a r i a b l e s
37 BATTERY PERCENTAGE = 22
38
39 # Relay p i n s
40 RELAY PIN 1 = 38
92
41 RELAY PIN 2 = 40
42 RELAY PIN 3 = 36
43 RELAY PIN 4 = 32
44
45 # GPIO s e t u p
46 GPIO . s e t u p ( RELAY PIN 1 , GPIO .OUT, i n i t i a l = 1 )
47 GPIO . s e t u p ( RELAY PIN 2 , GPIO .OUT, i n i t i a l = 1 )
48 GPIO . s e t u p ( RELAY PIN 3 , GPIO .OUT, i n i t i a l = 1 )
49 GPIO . s e t u p ( RELAY PIN 4 , GPIO .OUT, i n i t i a l = 1 )
50 def dischargeBattery ( battery percentage ) :
51 i f ( b a t t e r y p e r c e n t a g e > 10) :
52 print ( ” Discharging battery . . . ” )
53 p r i n t ( ” Mains OFF” )
54 MainsOFF ( )
55 else :
56 p r i n t ( ” B a t t e r y low , S w i t c h i n g t o mains ! ! ! ” )
57 MainsON ( )
58
59 def StopNonPriorityLoads ( ) :
60 p r i n t ( ” s t o p p e d non p r i o r i t y l o a d s . . . ” )
61
62 GPIO . output ( RELAY PIN 2 , GPIO . HIGH)
63 def runPriorityLoads () :
64 p r i n t ( ” Running p r i o r i t y l o a d s . . . ” )
65
66 d e f MainsON ( ) :
67 p r i n t ( ” s w i t c h i n g t o mains ” )
68 GPIO . output ( RELAY PIN 2 , GPIO .LOW)
69
70 d e f MainsOFF ( ) :
71 p r i n t ( ” s w i t c h i n g t o mains ” )
72 GPIO . output ( RELAY PIN 2 , GPIO . HIGH)
73
74
75 def runNonPriorityLoads ( ) :
76 p r i n t ( ” Running non−p r i o r i t y l o a d s . . . ” )
77 GPIO . output ( RELAY PIN 2 , GPIO .LOW)
78
79 def stopChargingBattery () :
80 p r i n t ( ” B a t t e r y c h a r g i n g OFF! ” )
81 GPIO . output ( RELAY PIN 3 , GPIO . HIGH)
82
83 def startChargingBattery () :
84 p r i n t ( ” Battery charging s t a r t e d . . . ” )
85 GPIO . output ( RELAY PIN 3 , GPIO .LOW)
86 def read data thingspeak () :
87 URL= ’ h t t p s : / / a p i . t h i n g s p e a k . com/ c h a n n e l s /359593/ f i e l d s / 1 . j s o n ? a p i k e y= ’
88 KEY= ’ 9F2TNAWBYZYRSDWA ’
89 HEADER= ’&r e s u l t s =1 ’
90 NEW URL=URL+KEY+HEADER
91 g e t d a t a=r e q u e s t s . g e t (NEW URL) . j s o n ( )
92 c h a n n e l i d=g e t d a t a [ ’ c h a n n e l ’ ] [ ’ i d ’ ]
93
94 f e i l d 1=g e t d a t a [ ’ f e e d s ’ ]
95 t =[]
96 for x in f e i l d 1 :
97 #p r i n t ( x [ ’ f i e l d 1 ’ ] )
98 power = x [ ’ f i e l d 1 ’ ]
93
99
100 r e t u r n power
101
102 numberOfHours = 0
103 i = 0
104 w h i l e ( True ) :
105 # F e t c h i n g c u r r e n t p r i c e from f i r e b a s e r e a l t i m e d a t a b a s e
106 rate = r e f . get ()
107 p r i n t ( ” Current r a t e : ” , r a t e )
108
109 # Fetch power h e r e
110 read data thingspeak ()
111 power = r e a d d a t a t h i n g s p e a k ( )
112 p r i n t ( ” power consumption : ” , power )
113 i f ( power == None ) :
114 power = 0
115 p r i n t ( ” t h e r e seems t o be no data b e i n g uploaded t o t h e n e t a s o f now
. . \n check i f t h e nodeMCU i s c o n n e c t e d t o t h e n e t ” )
116 power = f l o a t ( power )
117
118 # Calculating total price
119
120 t o t a l P r i c e += ( power ∗ r a t e )
121 t o t a l d a y P r i c e += ( power ∗ r a t e )
122 p r i n t ( ” Total p r i c e : ” , t o t a l P r i c e )
123 p r i n t ( ” T o t a l p r i c e f o r t h e day : ” , t o t a l d a y P r i c e )
124 i f ( r a t e > HIGH) :
125 d i s c h a r g e B a t t e r y (BATTERY PERCENTAGE)
126 runPriorityLoads ()
127 StopNonPriorityLoads ( )
128 e l i f ( r a t e > MEDIUM) :
129 stopChargingBattery ()
130 runPriorityLoads ()
131 runNonPriorityLoads ( )
132 else :
133 startChargingBattery ()
134 runPriorityLoads ()
135 runNonPriorityLoads ( )
136 i f ( i ==2) :
137 pw = t o t a l d a y P r i c e
138 sp = ” ”
139 e n t = ” \n”
140 p r i n t ( ” c u r r e n t p r i c e f o r t h e day : ” , pw)
141 p r i n t ( ” p r e d i c t i v e v a l u e f o r t h e month : ” , pw ∗ 30 )
142 f = open ( ’ output1 . t x t ’ , ’ a ’ ) # w : w r i t i n g mode / r : r e a d i n g
mode / a : appending mode
143 tstamp = ( time . s t r f t i m e ( ”%Y %d %b %H.%M.%S” ) )
144 f . w r i t e ( ’ {} ’ . format (pw) )
145 f . w r i t e ( ’ {} ’ . format ( sp ) )
146 f . w r i t e ( ’ {} ’ . format ( tstamp ) )
147 f . w r i t e ( ’ {} ’ . format ( e n t ) )
148 f . close ()
149
150 totaldayPrice = 0
151 i = 0
152 i = i + 1
153
154 time . s l e e p ( 1 0 )
94
C.0.2 Metering Algorithm using Emon Library running on Arduino
Mega
1 #i n c l u d e <S o f t w a r e S e r i a l . h>
2 #i n c l u d e <ArduinoJson . h>
3 #i n c l u d e ”EmonLib . h”
4 EnergyMonitor emon1 ;
5 EnergyMonitor emon2 ;
6 EnergyMonitor emon3 ;
7 SoftwareSerial s (3 ,4) ;
8 f l o a t realPower [ 3 ] = {0 ,0 ,0};
9 f l o a t apparentPower [ 3 ] = { 0 , 0 , 0 } ;
10 f l o a t powerFactor [ 3 ] = { 0 , 0 , 0 } ;
11 f l o a t supplyVoltage [ 3 ] = {0 ,0 ,0};
12 f l o a t irms [ 3 ] = { 0 , 0 , 0 } ;
13
14 void setup ( )
15 {
16 S e r i a l . begin (9600) ;
17 s . begin (115200) ;
18 emon1 . v o l t a g e ( 2 , 2 3 4 . 2 6 ∗ 1 . 6 4 ∗ 1 . 0 9 4 2 1 , 1 . 7 ) ; // V o l t a g e : i n p u t pin ,
calibration , phase shift
19 emon1 . c u r r e n t ( 1 , 1 1 1 . 1 ∗ 0 . 1 0 3 ∗ 2 . 5 0 7 5 ) ; // Current : i n p u t pin ,
calibration .
20 emon2 . v o l t a g e ( 4 , 2 3 4 . 2 6 ∗ 1 . 6 4 8 ∗ 0 . 8 0 4 3 , 1 . 7 ) ; // V o l t a g e : i n p u t pin ,
calibration , phase shift
21 emon2 . c u r r e n t ( 3 , 1 1 1 . 1 ∗ 0 . 1 0 3 8 ∗ 2 . 1 2 9 6 ) ; // Current : i n p u t pin ,
calibration .
22 emon3 . v o l t a g e ( 6 , 2 3 4 . 2 6 ∗ 1 . 6 4 8 ∗ 1 . 0 1 8 0 8 , 1 . 7 ) ; // V o l t a g e : i n p u t pin ,
calibration , phase shift
23 emon3 . c u r r e n t ( 5 , 1 1 1 . 1 ∗ 0 . 1 0 3 ∗ 2 . 4 4 8 9 ) ; // Current : i n p u t pin ,
calibrationn .
24 }
25 S t a t i c J s o n B u f f e r <1000> j s o n B u f f e r ;
26 J s o n O b j e c t& r o o t = j s o n B u f f e r . c r e a t e O b j e c t ( ) ;
27 void loop ( )
28 {
29 emon1 . c a l c V I ( 2 0 , 2 0 0 0 ) ; // C a l c u l a t e a l l . No . o f h a l f w a v e l e n g t h s (
c r o s s i n g s ) , time−out
30 S e r i a l . p r i n t l n ( ”R phase ” ) ;
31 emon1 . s e r i a l p r i n t ( ) ; // P r i n t out a l l v a r i a b l e s ( r e a l p o w e r ,
a p p a r e n t power , Vrms , Irms , power f a c t o r )
32 emon2 . c a l c V I ( 2 0 , 2 0 0 0 ) ; // C a l c u l a t e a l l . No . o f h a l f w a v e l e n g t h s (
c r o s s i n g s ) , time−out
33 S e r i a l . p r i n t l n ( ”Y phase ” ) ;
34 emon2 . s e r i a l p r i n t ( ) ; // P r i n t out a l l v a r i a b l e s ( r e a l p o w e r ,
a p p a r e n t power , Vrms , Irms , power f a c t o r )
35 emon3 . c a l c V I ( 2 0 , 2 0 0 0 ) ; // C a l c u l a t e a l l . No . o f h a l f w a v e l e n g t h s (
c r o s s i n g s ) , time−out
36 S e r i a l . p r i n t l n ( ”B phase ” ) ;
37 emon3 . s e r i a l p r i n t ( ) ; // P r i n t out a l l v a r i a b l e s ( r e a l p o w e r ,
a p p a r e n t power , Vrms , Irms , power f a c t o r )
38 realPower [ 0 ] = emon1 . r e a l P o w e r ; // e x t r a c t Real Power i n t o
variable
39 apparentPower [ 0 ] = emon1 . apparentPower ; // e x t r a c t Apparent Power
into variable
40 powerFactor [ 0 ] = emon1 . powerFactor ; // e x t r a c t Power F a c t o r i n t o
Variable
95
41 supplyVoltage [ 0 ] = emon1 . Vrms ; // e x t r a c t Vrms i n t o
Variable
42 irms [ 0 ] = emon1 . Irms ; // e x t r a c t Irms i n t o V a r i a b l e
43 realPower [ 1 ] = emon2 . r e a l P o w e r ; // e x t r a c t Real Power i n t o
variable
44 apparentPower [ 1 ] = emon2 . apparentPower ; // e x t r a c t Apparent Power
into variable
45 powerFactor [ 1 ] = emon2 . powerFactor ; // e x t r a c t Power F a c t o r i n t o
Variable
46 supplyVoltage [ 1 ] = emon2 . Vrms ; // e x t r a c t Vrms i n t o
Variable
47 irms [ 1 ] = emon2 . Irms ; // e x t r a c t Irms i n t o
Variable
48 realPower [ 2 ] = emon3 . r e a l P o w e r ; // e x t r a c t Real Power i n t o
variable
49 apparentPower [ 2 ] = emon3 . apparentPower ; // e x t r a c t Apparent Power
into variable
50 powerFactor [ 2 ] = emon3 . powerFactor ; // e x t r a c t Power F a c t o r i n t o
Variable
51 supplyVoltage [ 2 ] = emon3 . Vrms ; // e x t r a c t Vrms i n t o
Variable
52 irms [ 2 ] = emon3 . Irms ; // e x t r a c t Irms i n t o
Variable
53 r o o t [ ” rp1 ” ] = r e a l P o w e r [ 0 ] ;
54 r o o t [ ” ap1 ” ] = apparentPower [ 0 ] ;
55 r o o t [ ” p f 1 ” ] = powerFactor [ 0 ] ;
56 r o o t [ ” vrms1 ” ]= s u p p l y V o l t a g e [ 0 ] ;
57 r o o t [ ” i r m s 1 ” ]= s u p p l y V o l t a g e [ 0 ] ;
58 r o o t [ ” rp2 ” ] = r e a l P o w e r [ 0 ] ;
59 r o o t [ ” ap2 ” ] = apparentPower [ 0 ] ;
60 r o o t [ ” p f 2 ” ] = powerFactor [ 0 ] ;
61 r o o t [ ” vrms2 ” ]= s u p p l y V o l t a g e [ 0 ] ;
62 r o o t [ ” i r m s 2 ” ]= s u p p l y V o l t a g e [ 0 ] ;
63 r o o t [ ” rp3 ” ] = r e a l P o w e r [ 0 ] ;
64 r o o t [ ” ap3 ” ] = apparentPower [ 0 ] ;
65 r o o t [ ” p f 3 ” ] = powerFactor [ 0 ] ;
66 r o o t [ ” vrms3 ” ]= s u p p l y V o l t a g e [ 0 ] ;
67 r o o t [ ” i r m s 3 ” ]= s u p p l y V o l t a g e [ 0 ] ;
68
69
70 // i f ( s . a v a i l a b l e ( ) >0)
71 // {
72 root . printTo ( s ) ;
73 // }
74
75 }
1 #i n c l u d e <S o f t w a r e S e r i a l . h>
2 S o f t w a r e S e r i a l s (D4 , D3) ;
3 #i n c l u d e <ArduinoJson . h>
4 #i n c l u d e <Wire . h>
5 #i n c l u d e <SPI . h>
6 #i n c l u d e <ESP8266WiFi . h>
7 #i n c l u d e <W i F i C l i e n t . h>
8 #i n c l u d e <ThingSpeak . h>
96
9 #i n c l u d e ”SH1106 . h”
10 #i n c l u d e ” SH1106Ui . h”
11 c o n s t c h a r ∗ s s i d = ” Kunnathucherry −2” ;
12 c o n s t c h a r ∗ password = ” 43658382 ” ;
13 WiFiClient c l i e n t ;
14 u n s i g n e d l o n g myChannelNumber = 3 5 9 5 9 3 ;
15 c o n s t c h a r ∗ myWriteAPIKey = ”X4G7UOIVL2JV3BAD” ;
16
17
18 /∗ Hardware Wemos D1 mini SPI p i n s
19 D5 GPIO14 CLK − D0 p i n OLED d i s p l a y
20 D6 GPIO12 MISO (DIN) − not c o n n e c t e d
21 D7 GPIO13 MOSI (DOUT) − D1 p i n OLED d i s p l a y
22 D1 GPIO5 RST o r RES − RST p i n OLED d i s p l a y
23 D2 GPIO4 DC − DC p i n OLED
24 D8 GPIO15 CS / SS − CS p i n OLED d i s p l a y
25 ∗/
26 i n t s e n s o r V a l u e = 0 ; // Analoge b a t t e r y A0
27 char Str6 [ 1 5 ] ;
28 c h a r StrPWR [ 1 5 ] ;
29 char Status [15]= {” [ x ] ” } ;
30 char StatusWifi [64]= {” www. smartpepper . ga ” } ;
31 i n t wakeSensor =0; // Wake IR s e n s o r D0
32 i n t wakeSatus =0;
33 i n t Phase1V =0;
34 i n t Phase2V =0;
35 i n t Phase3V=0 ;
36 i n t Phase1I =0;
37 i n t Phase2I =0;
38 i n t Phase3I=0 ;
39 i n t Phase1P = 0 ;
40 i n t Phase2P= 0 ;
41 i n t Phase3P= 0 ;
42 f l o a t pwrTotal ;
43 i n t n=0;
44 i n t i =0;
45 unsigned long p r e v i o u s M i l l i s = 0 ;
46 const long i n t e r v a l = 15000; // i n t e r v a l a t which t o upload (
milliseconds )
47
48
49
50 // Pin d e f i n i t i o n s f o r SPI
51
52 // Node MCU
53 #d e f i n e OLED RESET D1 // RESET
54 #d e f i n e OLED DC D2 // Data /Command
55 #d e f i n e OLED CS D8 // Chip s e l e c t
56
57 SH1106 d i s p l a y ( t r u e , OLED RESET, OLED DC, OLED CS) ; // FOR SPI
58
59 SH1106Ui u i ( &d i s p l a y ) ;
60
61 b o o l msOverlay ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e ) {
62
63
64
65 d i s p l a y −>s e t T e x t A l i g n m e n t (TEXT ALIGN LEFT) ;
97
66 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 0 ) ;
67 // b a t t e r y v o l t a g e
68 s e n s o r V a l u e = analogRead (A0) ;
69 d i s p l a y −>f i l l R e c t ( 1 , 3 , 3 , 3 ) ;
70 d i s p l a y −>drawRect ( 3 , 0 , 1 8 , 9 ) ;
71 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
72 i n t t em p s en s o r Va l u e = s e n s o r V a l u e ∗ 0 . 0 2 8 7 1 6 4 ;
73 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
74 d i s p l a y −>f i l l R e c t ( 3 , 1 , tempsensorValue , 8 ) ;
75 sensorValue = sensorValue ∗5.5555555;
76 String str ;
77 s t r=S t r i n g ( s e n s o r V a l u e ) ;
78 s t r . c o n c a t ( ’%’ ) ;
79 s t r . toCharArray ( Str6 , 1 5 ) ;
80 d i s p l a y −>d r a w S t r i n g ( 2 4 , 0 , S t r 6 ) ;
81
82 s t r=S t r i n g ( pwrTotal ) ;
83 s t r . c o n c a t ( ’W’ ) ;
84 s t r . toCharArray (StrPWR , 1 5 ) ;
85 d i s p l a y −>d r a w S t r i n g ( 5 0 , 0 ,StrPWR) ; // CurrentPowerHeaded
86 d i s p l a y −>s e t T e x t A l i g n m e n t (TEXT ALIGN RIGHT) ;
87 d i s p l a y −>d r a w S t r i n g ( 1 2 8 , 0 , S t a t u s ) ; // s t a t u s
88
89
90
91
92 return true ;
93 }
94
95
96 b o o l drawFrame1 ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e , i n t x , i n t y ) {
97 d i s p l a y −>s e t T e x t A l i g n m e n t (TEXT ALIGN LEFT) ;
98 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 0 ) ;
99 d i s p l a y −>d r a w S t r i n g ( 0 +x , 10 + y , ” ” ) ;
100
101 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 6 ) ;
102 d i s p l a y −>d r a w S t r i n g ( 0 +x , 20 + y , ” Pepper 1 . 0 ” ) ;
103
104 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 0 ) ;
105 d i s p l a y −>d r a w S t r i n g ( 0 +x , 44 + y , S t a t u s W i f i ) ;
106 return f a l s e ;
107 }
108
109 b o o l drawFrame2 ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e , i n t x , i n t y ) {
110
111
112 d i s p l a y −>s e t T e x t A l i g n m e n t (TEXT ALIGN LEFT) ;
113 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 0 ) ;
114 // v o l t a g e 1
115 d i s p l a y −>drawRect ( 5 0 +x , 13+y , 7 5 , 8 ) ;
116 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
117 // Phase1V = Phase1V ∗ 0 . 0 2 8 7 1 6 4 ;
118 // S e r i a l . p r i n t l n ( Phase1V ) ;
119 String str1 ;
120 s t r 1=S t r i n g ( Phase1V ) ;
121 s t r 1 . c o n c a t ( ” V” ) ;
122 s t r 1 . toCharArray ( Str6 , 1 7 ) ;
123 d i s p l a y −>d r a w S t r i n g ( 0 +x , 11 + y , ”P1 : ” ) ;
98
124 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 11 + y , S t r 6 ) ;
125 i n t tempPhase1V = Phase1V ∗ 0 . 3 ;
126 d i s p l a y −>f i l l R e c t ( 5 0 +x , 14 + y , tempPhase1V , 7 ) ;
127 // v o l t a g e 2
128 d i s p l a y −>drawRect ( 5 0 +x , 24+y , 7 5 , 8 ) ;
129 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
130 // Phase1V = Phase1V ∗ 0 . 0 2 8 7 1 6 4 ;
131 // S e r i a l . p r i n t l n ( Phase1V ) ;
132 String str2 ;
133 s t r 2=S t r i n g ( Phase2V ) ;
134 s t r 2 . c o n c a t ( ” V” ) ;
135 s t r 2 . toCharArray ( Str6 , 1 7 ) ;
136 d i s p l a y −>d r a w S t r i n g ( 0 +x , 22 + y , ”P2 : ” ) ;
137 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 22 + y , S t r 6 ) ;
138 i n t tempPhase2V = Phase2V ∗ 0 . 3 ;
139 d i s p l a y −>f i l l R e c t ( 5 0 +x , 25 + y , tempPhase2V , 7 ) ;
140 // v o l t a g e 3
141 d i s p l a y −>drawRect ( 5 0 +x , 35+y , 7 5 , 8 ) ;
142 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
143 // Phase3V = Phase3V ∗ 0 . 0 2 8 7 1 6 4 ;
144 // S e r i a l . p r i n t l n ( Phase1V ) ;
145 String str3 ;
146 s t r 3=S t r i n g ( Phase3V ) ;
147 s t r 3 . c o n c a t ( ” V” ) ;
148 s t r 3 . toCharArray ( Str6 , 1 7 ) ;
149 d i s p l a y −>d r a w S t r i n g ( 0 +x , 33 + y , ”P3 : ” ) ;
150 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 33 + y , S t r 6 ) ;
151 i n t tempPhase3V = Phase3V ∗ 0 . 3 ;
152 d i s p l a y −>f i l l R e c t ( 5 0 +x , 36 + y , tempPhase3V , 7 ) ;
153 d i s p l a y −>d r a w S t r i n g ( 0 +x , 44+ y , ” Spannung ( V o l t a g e / Phase ) ” ) ;
154 return f a l s e ;
155 }
156
157 b o o l drawFrame3 ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e , i n t x , i n t y ) {
158 d i s p l a y −>s e t T e x t A l i g n m e n t (TEXT ALIGN LEFT) ;
159 d i s p l a y −>s e t F o n t ( A r i a l M T P l a i n 1 0 ) ;
160 // v o l t a g e 1
161 d i s p l a y −>drawRect ( 5 0 +x , 13+y , 7 5 , 8 ) ;
162 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
163 // Phase1V = Phase1V ∗ 0 . 0 2 8 7 1 6 4 ;
164 // S e r i a l . p r i n t l n ( Phase1V ) ;
165 String str1 ;
166 s t r 1=S t r i n g ( Phase1I ) ;
167 s t r 1 . c o n c a t ( ” A” ) ;
168 s t r 1 . toCharArray ( Str6 , 1 7 ) ;
169 d i s p l a y −>d r a w S t r i n g ( 0 +x , 11 + y , ”P1 : ” ) ;
170 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 11 + y , S t r 6 ) ;
171 i n t tempPhase1I = Phase1I ∗ 3 . 7 5 ;
172 d i s p l a y −>f i l l R e c t ( 5 0 +x , 14 + y , tempPhase1I , 7 ) ;
173 // v o l t a g e 2
174 d i s p l a y −>drawRect ( 5 0 +x , 24+y , 7 5 , 8 ) ;
175 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
176 // Phase1V = Phase1V ∗ 0 . 0 2 8 7 1 6 4 ;
177 // S e r i a l . p r i n t l n ( Phase1V ) ;
178 String str2 ;
179 s t r 2=S t r i n g ( Phase2I ) ;
180 s t r 2 . c o n c a t ( ” A” ) ;
181 s t r 2 . toCharArray ( Str6 , 1 7 ) ;
99
182 d i s p l a y −>d r a w S t r i n g ( 0 +x , 22 + y , ”P2 : ” ) ;
183 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 22 + y , S t r 6 ) ;
184 i n t tempPhase2I = Phase2I ∗ 3 . 7 5 ;
185 d i s p l a y −>f i l l R e c t ( 5 0 +x , 25 + y , tempPhase2I , 7 ) ;
186 // v o l t a g e 3
187 d i s p l a y −>drawRect ( 5 0 +x , 35+y , 7 5 , 8 ) ;
188 // S e r i a l . p r i n t l n ( s e n s o r V a l u e ) ;
189 // Phase3V = Phase3V ∗ 0 . 0 2 8 7 1 6 4 ;
190 // S e r i a l . p r i n t l n ( Phase1V ) ;
191 String str3 ;
192 s t r 3=S t r i n g ( Phase3I ) ;
193 s t r 3 . c o n c a t ( ” A” ) ;
194 s t r 3 . toCharArray ( Str6 , 1 7 ) ;
195 d i s p l a y −>d r a w S t r i n g ( 0 +x , 33 + y , ”P3 : ” ) ;
196 d i s p l a y −>d r a w S t r i n g ( 1 9 + x , 33 + y , S t r 6 ) ;
197 i n t tempPhase3I = Phase3I ∗ 3 . 7 5 ;
198 d i s p l a y −>f i l l R e c t ( 5 0 +x , 36 + y , tempPhase3I , 7 ) ;
199 d i s p l a y −>d r a w S t r i n g ( 0 +x , 44+ y , ” Strom ( Current / Phase ) ” ) ;
200 return f a l s e ;
201 }
202 i n t frameCount = 3 ;
203 b o o l ( ∗ f r a m e s [ ] ) ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e , i n t x , i n t y ) = {
drawFrame1 , drawFrame2 , drawFrame3 } ;
204
205 b o o l ( ∗ o v e r l a y s [ ] ) ( SH1106 ∗ d i s p l a y , SH1106UiState ∗ s t a t e ) = {
msOverlay } ;
206 i n t overlaysCount = 1 ;
207
208 void setup ( ) {
209 S e r i a l . begin (9600) ;
210 s . begin (115200) ;
211 while ( ! S e r i a l ) continue ;
212 u i . setTargetFPS ( 3 0 ) ;
213 u i . s e t I n d i c a t o r P o s i t i o n (BOTTOM) ;
214 u i . s e t I n d i c a t o r D i r e c t i o n (LEFT RIGHT) ;
215 u i . setFrameAnimation ( SLIDE LEFT ) ;
216 u i . setFrames ( frames , frameCount ) ;
217 ui . setOverlays ( overlays , overlaysCount ) ;
218 ui . i n i t () ;
219 // d i s p l a y . f l i p S c r e e n V e r t i c a l l y ( ) ;
220 u i . update ( ) ;
221 delay (10) ;
222 // Connect t o WiFi network
223 Serial . println () ;
224 Serial . println () ;
225 S e r i a l . p r i n t ( ” Connecting t o ” ) ;
226 Serial . println ( ssid ) ;
227 WiFi . b e g i n ( s s i d , password ) ;
228 u i . update ( ) ;
229 w h i l e ( WiFi . s t a t u s ( ) != WL CONNECTED)
230 {
231 delay (500) ;
232 Serial . print (” . ”) ;
233 }
234 S e r i a l . p r i n t l n ( ”” ) ;
235 S e r i a l . p r i n t l n ( ”WiFi c o n n e c t e d ” ) ;
236 Status [0]= ’ [ ’ ;
237 S t a t u s [ 1 ] = ’w ’ ;
100
238 Status [2]= ’ i ’ ;
239 Status [3]= ’ f ’ ;
240 Status [4]= ’ i ’ ;
241 Status [5]= ’ ] ’ ;
242 S t a t u s [ 6 ] = ’ \0 ’ ;
243 // P r i n t t h e IP a d d r e s s
244 S e r i a l . p r i n t l n ( WiFi . l o c a l I P ( ) ) ;
245 ThingSpeak . b e g i n ( c l i e n t ) ;
246 }
247
248 void loop ( ) {
249 S t a t i c J s o n B u f f e r <1000> j s o n B u f f e r ;
250 J s o n O b j e c t& r o o t = j s o n B u f f e r . p a r s e O b j e c t ( s ) ;
251 i f ( r o o t == J s o n O b j e c t : : i n v a l i d ( ) ) {
252 return ;
253 }
254 S e r i a l . p r i n t l n ( ”JSON r e c e i v e d and p a r s e d ” ) ;
255 root . prettyPrintTo ( S e r i a l ) ;
256 S e r i a l . p r i n t ( ” realPower ” ) ;
257 S e r i a l . p r i n t l n ( ”” ) ;
258 f l o a t r e a l P o w e r 1=r o o t [ ” rp1 ” ] ;
259 S e r i a l . p r i n t ( realPower1 ) ;
260 S e r i a l . p r i n t ( ” apparentPower ” ) ;
261 f l o a t apparentPower1=r o o t [ ” ap1 ” ] ;
262 S e r i a l . p r i n t ( apparentPower1 ) ;
263 S e r i a l . p r i n t ( ” powerFactor ” ) ;
264 f l o a t powerFactor1=r o o t [ ” p f 1 ” ] ;
265 S e r i a l . p r i n t ( powerFactor1 ) ;
266 S e r i a l . print ( ” supplyVoltage ” ) ;
267 f l o a t s u p p l y V o l t a g e 1=r o o t [ ” vrms1 ” ] ;
268 S e r i a l . print ( supplyVoltage1 ) ;
269 Serial . print (” Irms ” ) ;
270 f l o a t Irms1=r o o t [ ” i r m s 1 ” ] ;
271 S e r i a l . p r i n t ( Irms1 ) ;
272 S e r i a l . p r i n t l n ( ”” ) ;
273
274 S e r i a l . p r i n t ( ” realPower ” ) ;
275 S e r i a l . p r i n t l n ( ”” ) ;
276 f l o a t r e a l P o w e r 2=r o o t [ ” rp2 ” ] ;
277 S e r i a l . p r i n t ( realPower2 ) ;
278 S e r i a l . p r i n t ( ” apparentPower ” ) ;
279 f l o a t apparentPower2=r o o t [ ” ap2 ” ] ;
280 S e r i a l . p r i n t ( apparentPower2 ) ;
281 S e r i a l . p r i n t ( ” powerFactor ” ) ;
282 f l o a t powerFactor2=r o o t [ ” p f 2 ” ] ;
283 S e r i a l . p r i n t ( powerFactor2 ) ;
284 S e r i a l . print ( ” supplyVoltage ” ) ;
285 f l o a t s u p p l y V o l t a g e 2=r o o t [ ” vrms2 ” ] ;
286 S e r i a l . print ( supplyVoltage2 ) ;
287 Serial . print (” Irms ” ) ;
288 f l o a t Irms2=r o o t [ ” i r m s 2 ” ] ;
289 S e r i a l . p r i n t ( Irms2 ) ;
290 S e r i a l . p r i n t l n ( ”” ) ;
291
292 S e r i a l . p r i n t ( ” realPower ” ) ;
293 S e r i a l . p r i n t l n ( ”” ) ;
294 f l o a t r e a l P o w e r 3=r o o t [ ” rp3 ” ] ;
295 S e r i a l . p r i n t ( realPower3 ) ;
101
296 S e r i a l . p r i n t ( ” apparentPower ” ) ;
297 f l o a t apparentPower3=r o o t [ ” ap3 ” ] ;
298 S e r i a l . p r i n t ( apparentPower3 ) ;
299 S e r i a l . p r i n t ( ” powerFactor ” ) ;
300 f l o a t powerFactor3=r o o t [ ” p f 3 ” ] ;
301 S e r i a l . p r i n t ( powerFactor3 ) ;
302 S e r i a l . print ( ” supplyVoltage ” ) ;
303 f l o a t s u p p l y V o l t a g e 3=r o o t [ ” vrms3 ” ] ;
304 S e r i a l . print ( supplyVoltage3 ) ;
305 Serial . print (” Irms ” ) ;
306 f l o a t Irms3=r o o t [ ” i r m s 3 ” ] ;
307 S e r i a l . p r i n t ( Irms3 ) ;
308 S e r i a l . p r i n t l n ( ”” ) ;
309 S e r i a l . p r i n t l n ( ”−−−−−−−−−−−−−−−−−−−−−xxxxx−−−−−−−−−−−−−−−−−−−−” ) ;
310 Phase1V = s u p p l y V o l t a g e 1 ;
311 Phase2V= 0 ;
312 Phase3V= 0 ;
313 Phase1I = Irms1 ;
314 Phase2I= 0 ;
315 Phase3I= 0 ;
316 Phase1P = r e a l P o w e r 1 ;
317 Phase2P= 0 ;
318 Phase3P= 0 ;
319
320 pwrTotal=Phase1P+Phase2P+Phase3P ;
321 w h i l e ( WiFi . s t a t u s ( ) != WL CONNECTED)
322 {
323 Status [0]= ’ [ ’ ;
324 Status [1]= ’x ’ ;
325 Status [2]= ’ ] ’ ;
326 S t a t u s [ 3 ] = ’ \0 ’ ;
327 }
328
329 s t a t i c boolean d a t a s t a t e = 0;
330 unsigned long c u r r e n t M i l l i s = m i l l i s ( ) ;
331 i f ( c u r r e n t M i l l i s − p r e v i o u s M i l l i s >= i n t e r v a l ) {
332 previousMillis = currentMillis ;
333 i f ( d a t a s t a t e ==0)
334 {
335 ThingSpeak . w r i t e F i e l d ( myChannelNumber , 1 , pwrTotal , myWriteAPIKey ) ;
336 data state = 0;
337 S e r i a l . p r i n t l n ( ” uploaded ” ) ;
338 S e r i a l . p r i n t l n ( pwrTotal ) ;
339 data state = 1;
340 }
341 e l s e i f ( d a t a s t a t e ==1) {
342 ThingSpeak . w r i t e F i e l d ( myChannelNumber , 7 , s e n s o r V a l u e , myWriteAPIKey ) ;
343 S e r i a l . println ( sensorValue ) ;
344 data state = 0;
345 }
346 }
347 i n t remainingTimeBudget = u i . update ( ) ;
348 i f ( remainingTimeBudget > 0 ) {
349 // Don ’ t do s t u f f i f you a r e below your
350 // time budget .
351 d e l a y ( remainingTimeBudget ) ;
352
353 }
102
354 }
103
Appendix D
Data Sheets
104
Product Order Technical Tools & Support &
Folder Now Documents Software Community
Comparator Comparator
Voltage Voltage ALERT/ Voltage ALERT/
Reference Reference RDY Reference RDY
An IMPORTANT NOTICE at the end of this data sheet addresses availability, warranty, changes, use in safety-critical applications,
intellectual property matters and other important disclaimers. PRODUCTION DATA.
105
ADS1113, ADS1114, ADS1115
www.ti.com SBAS444D – MAY 2009 – REVISED JANUARY 2018
ADDR 1 10 SCL
10
ADDR 1 9 SDA
ALERT/RDY 2 9 SDA
GND 3 8 VDD
ALERT/RDY 2 8 VDD
AIN0 4 7 AIN3
Not to scale
AIN1
Pin Functions
PIN (1)
NAME ADS1113 ADS1114 ADS1115 TYPE DESCRIPTION
ADDR 1 1 1 Digital input I2C slave address select
AIN0 4 4 4 Analog input Analog input 0
AIN1 5 5 5 Analog input Analog input 1
AIN2 — — 6 Analog input Analog input 2 (ADS1115 only)
AIN3 — — 7 Analog input Analog input 3 (ADS1115 only)
ALERT/RDY — 2 2 Digital output Comparator output or conversion ready (ADS1114 and ADS1115 only)
GND 3 3 3 Analog Ground
NC 2, 6, 7 6, 7 — — Not connected
SCL 10 10 10 Digital input Serial clock input. locks data on SDA
SDA 9 9 9 Digital I/O Serial data. Transmits and receives data
VDD 8 8 8 Analog Power supply. Connect a 0.1-μF, power-supply decoupling capacitor to GND.
(1) See the Unused Inputs and Outputs section for unused pin connections.
106
D.2 ESP8266EX Datasheet - Espressif Systems
107
2. Pin Definitions
$
2. Pin Definitions
Figure 2-1 shows the pin layout for 32-pin QFN package.
EXT_RSTB
XTAL_OUT
XTAL_IN
RES12K
U0RXD
U0TXD
VDDD
VDDA
GND
33
32
31
30
29
28
27
26
25
VDDA 1 24 GPIO5
LNA 2 23 SD_DATA_1
VDD3P3 3 22 SD_DATA_0
VDD3P3 4 21 SD_CLK
ESP8266EX
VDD_RTC 5 20 SD_CMD
TOUT 6 19 SD_DATA_3
CHIP_EN 7 18 SD_DATA_2
XDP_DCDC 8 17 VDDPST
9
10
11
12
13
14
15
16
MTMS
MTDI
VDDPST
MTCK
MTDO
GPIO2
GPIO0
GPIO4
$
Figure 2-1. Pin Layout (Top View)
RF antenna interface
2 LNA I/O Chip output impedance=39+j6 Ω. It is suggested to retain the
π-type matching network to match the antenna.
5 VDD_RTC P NC (1.1V)
Espressif $ /$24
4 2018.11
108
2. Pin Definitions
$
Chip Enable
7 CHIP_EN I High: On, chip works properly
Low: Off, small current consumed
📖 Note:
1. GPIO2, GPIO0, and MTDO are used to select booting mode and the SDIO mode;
2. U0TXD should not be pulled externally to a low logic level during the powering-up.
Espressif $ /$24
5 2018.11
109
3. Functional Description
$
3. Functional Description
The functional diagram of ESP8266EX is shown as in Figure 3-1.
GPIO
Switch
Digital baseband
I2C
CPU
RF Analog I2S
transmit transmit
SDIO
Sequencers
PWM
ADC
Accelerator
PLL VCO 1/2 PLL
SPI
$
Figure 3-1. Functional Block Diagram
3.1.2. Memory
ESP8266EX Wi-Fi SoC integrates memory controller and memory units including SRAM
and ROM. MCU can access the memory units through iBus, dBus, and AHB interfaces. All
memory units can be accessed upon request, while a memory arbiter will decide the
running sequence according to the time when these requests are received by the
processor.
According to our current version of SDK, SRAM space available to users is assigned as
below.
Espressif $ /$24
6 2018.11
110
D.3 YHDC SCT-013-000 CT Sensor
111
R
Ip K
13±0.5 10±0.5
31±0.5
TVS Iout
Swiching angle
180° L
Current output type
11.5±0.5
Ip K
34±0.5
TVS
L
22±0.5 Voltage output type
23.5±0.5
※ Output type: voltage output type built-in sampling resistor, current output type built-in protective diode.
112