0% found this document useful (0 votes)
412 views127 pages

Smart Metering

load forecasting

Uploaded by

radhika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
412 views127 pages

Smart Metering

load forecasting

Uploaded by

radhika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 127

Smart Metering System and Domestic Task

Scheduling Under Dynamic Pricing Using the


Multiple Knapsack Method

Project Report
2019

Submitted in partial fulfillment for the award of


the Degree of Bachelor of Technology in
Electrical and Electronics Engineering
By

Christina George (RET15EE027)

Under the guidance of

Soniya Raju

Department of Electrical and Electronics Engineering


RAJAGIRI SCHOOL OF ENGINEERING AND TECHNOLOGY
Rajagiri Valley, Cochin - 682039,
Kerala, India.
CERTIFICATE

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

Academic Year 2018-2019

Vision of the Institution:


To evolve into a premier technological and research institution, moulding eminent
professionals with creative minds, innovative ideas and sound practical skill, and to
shape a future where technology works for the enrichment of mankind.

Mission of the Institution:


To impart state-of-the-art knowledge to individuals in various technological disci-
plines and to inculcate in them a high degree of social consciousness and human values,
thereby enabling them to face the challenges of life with courage and conviction.

Vision of the Department:


To excel in Electrical and Electronics Engineering education with focus on research
to make professionals with creative minds, innovative ideas and practical skills for the
betterment of mankind.

Mission of the Department:


To develop and disseminate among the individuals, the theoretical foundation, prac-
tical aspects in the field of Electrical and Electronics Engineering and inculcate a high
degree of professional and social ethics for creating successful engineers.

Programme Educational Objectives (PEOs):


PEO 1: To provide Graduates with a solid foundation in mathematical, scientific and
engineering fundamentals and depth and breadth studies in Electrical and Electronics
engineering, so as to comprehend, analyse, design, provide solutions for practical issues
in engineering.
PEO 2: To strive for Graduates’ achievement and success in the profession or higher
studies, which they may pursue.
PEO 3: To inculcate in Graduates professional and ethical attitude, effective commu-
nication skills, teamwork skills, multidisciplinary approach, the life-long learning needs
and an ability to relate engineering issues for a successful professional career.

Program Outcomes (POs)


Engineering graduates will be able to

1. Engineering knowledge: Apply the knowledge of mathematics, science, Engi-


neering fundamentals, and Electrical and Electronics Engineering to the solution
of complex Engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze


complex Engineering problems reaching substantiated conclusions using first prin-
ciples of mathematics, natural sciences, and Engineering sciences.

3. Design/development of solutions: Design solutions for complex Engineering


problems and design system components or processes that meet the specified needs

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:

1. To derive simulation model of an smart monitoring system

2. To improve the useage pattens of an consumer

3. to reduce the overall expense paid on electricity bills

4. to prevent excessive useage of power during high price peroids.

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

4 Dynamic Switching of Priority and Non-priority Loads Under Dynamic


Pricing 13
4.1 Load Switching based on priority under dynamic pricing . . . . . . . . . . 13
4.2 Detailed Working of the Program . . . . . . . . . . . . . . . . . . . . . . . 14

5 Energy performance management dashboard using Thingsspeak Plat-


form 17
5.1 Real-Time Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Formula Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.3 Trend Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4 Tariff Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.5 Alarms Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.6 Data Import/Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6 Residential Task Scheduling Under Dynamic Pricing Using the Multi-
ple Knapsack Method 19
6.0.1 Coordinated Scheduling of Residential Distributed Energy Re-
sources to Optimize Smart Home Energy Services . . . . . . . . . 20
6.0.2 Optimal and Autonomous Incentive-based Energy Consumption
Scheduling Algorithm for Smart Grid . . . . . . . . . . . . . . . . 21
6.0.3 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.0.4 Modeling The Objetive Function And Constrains . . . . . . . . . . 24
6.1 Simulation And Results using What’sBest solver . . . . . . . . . . . . . . 27

7 0-1 Multiple knapsack problem and Solving the Multi-Dimensional


Knapsack Problem with Python 30
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.2 Solving the Multi-Dimensional Knapsack Problem with Python . . . . . . 32

8 Design of Energy Meter Based on PROTEUS 33


8.1 Hardware Design 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8.1.1 Design of Voltage Sensor 1 . . . . . . . . . . . . . . . . . . . . . . . 33
8.1.2 Design of Current Sensor 2 . . . . . . . . . . . . . . . . . . . . . . 33
8.1.3 Design of Micro-controller 3 . . . . . . . . . . . . . . . . . . . . . . 33
8.1.4 Design of LED Indicator and Buzzer 4 . . . . . . . . . . . . . . . . 34
8.1.5 Design of Keypad 5 . . . . . . . . . . . . . . . . . . . . . . . . . . 34
8.1.6 Design of Circuit Breaker (Relay) 6 . . . . . . . . . . . . . . . . . 35
8.1.7 Design of LCD 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2 Simulations 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.3 Inferential Conclusions from Simulation Analysis 3 . . . . . . . . . . . . . 37

9 Circuit Design and Signal Integrity and Designing of PCB Layout 41


9.1 Measuring mains voltage and current . . . . . . . . . . . . . . . . . . . . . 41
9.1.1 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
9.2 Measuring AC Voltage with an AC to AC power adapter . . . . . . . . . . 42
9.3 Improving the quality of the bias source . . . . . . . . . . . . . . . . . . . 44
9.3.1 Buffered Voltage Bias . . . . . . . . . . . . . . . . . . . . . . . . . 44
9.3.2 Simulation of Buffered Voltage Bias Proteus . . . . . . . . . . . . . 44
9.3.3 Simulation Results of Buffered Voltage Bias Proteus . . . . . . . . 44
9.3.4 Simulation of complete circuit in direct loading . . . . . . . . . . . 44
9.4 CT Sensors - Interfacing with an Arduino . . . . . . . . . . . . . . . . . . 44
9.4.1 Calculating a Suitable Burden Resistor Size . . . . . . . . . . . . . 45
9.5 Extending the Current Transformer Cable . . . . . . . . . . . . . . . . . 48
9.5.1 Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.5.2 Choice of cable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.5.3 Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
9.6 Measurement Implications of ADC Resolution at Low Current Values . . 50
9.7 PCB designing using EasyEDA . . . . . . . . . . . . . . . . . . . . . . . . 52
10 Hardware 54
10.1 Current Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
10.1.1 Types of Current Transformer . . . . . . . . . . . . . . . . . . . . . 55
10.1.2 How a CT works . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
10.1.3 Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
10.2 Potential Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.3 Rogowski Coil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.4 Arduino Mega 2560 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.5 NodeMCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
10.5.1 Serial Communication between NodeMCU and Arduino . . . . . . 60
10.5.2 Sending Multiple data between NodeMCU and Arduino: . . . . . . 61
10.6 Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
10.7 Relay Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.7.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

11 Energy performance management dashboard using ThingsSpeakTM plat-


form 66
11.1 Real-Time Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
11.2 Thingspeak IoT Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
11.2.1 ThingSpeak Key Features . . . . . . . . . . . . . . . . . . . . . . . 67
11.3 Alarms Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.3.1 Over Usage Warning . . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.3.2 IdealUsage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.4 Formula Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.5 Trend Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.6 Measurement Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.7 Tariff Analytics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.8 Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.9 Operations Wastage Analysis . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.10Power Quality Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
11.11Performance Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
11.12Actions Tracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
11.13Data Import/Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

12 AC Power Theory - Arduino Maths 71


12.1 Instantaneous Voltage and Current . . . . . . . . . . . . . . . . . . . . . . 71
12.2 Calculating Real Power on an Arduino . . . . . . . . . . . . . . . . . . . . 72
12.3 Root-Mean-Square (RMS) Voltage . . . . . . . . . . . . . . . . . . . . . . 72
12.4 Apparent Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
12.5 EmonLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

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

Appendix A Work Division 83


A.1 Jojo Joseph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
A.2 Solamen Paul Alex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
A.3 Christina George . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

Appendix B Reference paper 85

Appendix C Software Source Code 92


C.0.1 Scheduling Program . . . . . . . . . . . . . . . . . . . . . . . . . . 92
C.0.2 Metering Algorithm using Emon Library running on Arduino Mega 95
C.0.3 IoT and Interface display (Thingspeak-node) running on NodeMCU
(ESP8266) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

Appendix D Data Sheets 104


D.1 ADS1115 - Texas Instruments . . . . . . . . . . . . . . . . . . . . . . . . . 104
D.2 ESP8266EX Datasheet - Espressif Systems . . . . . . . . . . . . . . . . . 107
D.3 YHDC SCT-013-000 CT Sensor . . . . . . . . . . . . . . . . . . . . . . . . 111
List of Figures

3.1 Load versus Time Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11


3.2 Initial Price versus Final Price . . . . . . . . . . . . . . . . . . . . . . . . 12

4.1 AN terminal of running program on raspberian OS . . . . . . . . . . . . 14


4.2 Smart Scheduling flow chart . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 Firebase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6.1 an example cost function,corresponding to the cost data . . . . . . . . . . 23


6.2 Results for the simple example . . . . . . . . . . . . . . . . . . . . . . . . 27
6.3 Results from an 18-appliance, 16-time-slot probleum . . . . . . . . . . . . 28
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

8.1 Design of Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . 34


8.2 Design of Electric Current Sensor . . . . . . . . . . . . . . . . . . . . . . 34
8.3 Block diagram of proposed energy meter . . . . . . . . . . . . . . . . . . 35
8.4 Design of Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8.5 Design of LED Indicator and Buzzer . . . . . . . . . . . . . . . . . . . . . 36
8.6 Design of Keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
8.7 Design of Circuit Breaker . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
8.8 Design of LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
8.9 The Simulation of Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . 39
8.10 The Simulation of Current Sensor . . . . . . . . . . . . . . . . . . . . . . 39
8.11 The Simulation of Voltage Sensor . . . . . . . . . . . . . . . . . . . . . . . 40
8.12 The Simulation of Current Sensor . . . . . . . . . . . . . . . . . . . . . . 40

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

10.1 YHDC Current Transformer SCT-013-000 . . . . . . . . . . . . . . . . . . 54


10.2 Magnelab split-core CT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
10.3 Magnelab solid-core CT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
10.4 Potential Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
10.5 Rogowski Coil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
10.6 Arduino Mega 2560 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
10.7 NodeMCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.8 NodeMCU Pin Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
10.9 serial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
10.10Serial Communication between NodeMCU and Arduino. . . . . . . . . . . 61
10.11Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
10.12Connecting the circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
10.13Control the Raspberry Pi GPIO pins and turn an LED on . . . . . . . . . 63
10.14Relay Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
10.154 channel relay schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

11.1 IoT systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67


11.2 Real-Time Analysis : Dashboard . . . . . . . . . . . . . . . . . . . . . . . 68
11.3 IoT systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
11.4 Data Import/Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

12.1 Instantaneous voltage or current reading . . . . . . . . . . . . . . . . . . 71


List of Tables

6.1 Appliance parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27


6.2 Description of the time slots . . . . . . . . . . . . . . . . . . . . . . . . . . 28

8.1 Test results for voltage sensor . . . . . . . . . . . . . . . . . . . . . . . . 38


8.2 Test results for current sensor . . . . . . . . . . . . . . . . . . . . . . . . 40
List of Abbreviations

1. DSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Demand-side management

2. C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Current

3. PCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printed Circuit Board

4. DSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Demand-side management

5. V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Volt

6. ANN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Artificial Neural Network

7. DFF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Flip Flop

8. DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Digital Circuits

9. TOTEM . . . . . . . . . . . . . . . . Total Elastic and diffractive cross section Measurement

10. PSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Particle Swap Optimization

11. CHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Combined Heat Power

12. EES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Electrical Energy Storage

13. HAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Home Automaton System

14. HAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Home Automation Network

15. HEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Home Energy Controller

16. RTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real Time Pricing

17. DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Demand Response

18. SM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Smart Meter

19. CS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Central System

20. VRMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Voltage Root Mean Square

21. AMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Metering Interface

22. DMES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Daily Maximum Energy Scheduling


23. MILS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Mixed Integer linear Scheduling

24. RES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Renewable Energy Source

25. CPP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Critical Peak Pricing

26. TOU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Time Of use

27. MM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Monotonic Marginal

28. ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Independent System Operator

29. CPSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Co-evolutionary Particle Swap Optimization

30. ECS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Energy Consumption Scheduling

31. MKP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Multiple Knapsack Problem

32. CT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Current Transformer

33. PT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Potential Transformer

34. GPIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . General purpose Input Output

35. USB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Universal Serial Bus

36. JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . JavaScript Object Notation

37. SPDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Single Push Double Throw

38. UDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User Datagram Protocol

39. PUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Power Usage Effectiveness

40. DG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Distributed Generators

41. LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Liquid Crystal Display

42. MAPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Main Absolute Percentage Error


Chapter 1

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 Project Overview


A cheap means of reducing expense on electricity bills by collecting power useage pattens
and determine the price during the day and also predicting the monthly price.

1.2 Problem Statements


with the rise in on-grid solar panels we can expect a change in pricing patterns these
could mean that there would be different prices at different point of time this may not
affect the solar panel owners much but for consumers that don’t own an panel they will
end up having to pay an considerable sum of money due to the lack of provision of
connection of solar panels.

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.

1.4 Project Objectives


The objectives of this project are:
1. To derive simulation model of an smart monitoring system
2. To improve the useage pattens of an consumer
3. to reduce the overall expense paid on electricity bills
4. to prevent excessive useage of power during high price peroids.
5. to make the consumer aware of his useage pattens and understanding of faults.

1.5 Proposed Idea


The project is a combination of the IoT remote monitoring system and switching and
provide a platform where we could utilize the low price point in dynamic pricing

1.6 Smart meter and smart scheduling


Implementation of various incentive-based demand response strategies has great poten-
tial to decrease peak load growth and customer electricity bill cost. Using advanced
metering and automatic demand management makes it possible to optimize energy con-
sumption, to reduce grid loss, and to release generation capacities for the sake of pro-
viding sustainable electricity supply. Executing an incentive-based program is a simple
way for customers to monitor and manage their energy consumption, and therefore, to
reduce their electricity bill. With these objectives, this paper examines the previously
suggested load scheduling programs and proposes a new practical one for residential
energy management. The method is aimed at optimizing customers’ bill cost and sat-
isfaction by taking into consideration the generation capacity limitation and dynamic
electricity price in different time slots of a day. Moreover, the proposed optimization
algorithm is compared with Particle Swarm Optimization (PSO) algorithm to illustrate
high efficiency of the proposed algorithm as a practical industrial tool for peak load
shaving.

1.7 Market Scenario


Automated electric energy metering systems for wholesale energy markets provide im-
plementation of electric energy metering functionality for different subjects of whole-
sale energy market: generating and transmission companies, electric energy guaranteed

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.

1.8 Smart Homes


Residential homes on smart grids usually have local electric power generation from pho-
tovoltaic systems, micro combined heat and power (micro-CHP) systems . Storage
systems are used to reduce the impact of output power fluctuation of renewable energies
on the grid voltage and frequency . The Smart Home Project (SmartPepper.ga) with
appliances used in the average house was started in 2018 as undergrad micro-project in
5th semester of Bachelor of Technology. The proposed smart home metering concept
consists of different renewable energy sources and an electrical energy storage system.
With smart plugs and sensors, the data about temperature, humidity and the lighting
level was transmitted to the central computer. In the central computer, the proposed
algorithm can perform load control aiming primarily at reducing consumer bills. The
SmartPepper is a single-family smart house developed at the Rajagiri School of Engi-
neering and Technology for the purpose of experimenting and analyzing the application
of intelligent technologies. The primary focus of this smart house is to enable better
quality of life for users with special needs and elderly people by using smart sensors
and intelligent appliances, but this smart living environment is suitable for everyone.
A smart home is equipped with smart devices and modern technology that can control
consumer appliances. When EES(Electrical Energy Storage System) stores power from
the network, the voltage decreases below the limit.The embedded system that provides
and manages a smart home energy requirement with solar and storage energy resources
in the smart home was proposed in . In terms of two-way communication, the home
gateway (H-Gateway) single chip embedded system integrated with the wireless network
was installed at the end-user side and the utility server (U-Server), a high end PC was
installed at the utility headquarter. Household appliances must be linked via a commu-
nication network that allows control of smart appliances to carry out load management.
The task of a home automation system is to achieve load management taking into ac-
count user comfort at low cost while satisfying technological constraints of equipment
. In a typical home automation network (HAN) architecture, smart appliances enable
intelligent decision making. These devices report their energy consumption to the Home
Energy Controller (HEC) and respond to its commands, such as on/off signals, or com-
mand to operate in an energy saving mode.
For example, after receiving control signals, smart dishwashers can delay wash cycles
until off peak periods. Smart meters send user data to the utility network and real-
time pricing (RTP) with DR(Demand Response) signals to the HEC at the home area
network .
The smart house can become part of the smart city. The demonstration project,
SmartPepper, aimed at reducing energy use, located in the Kochi,INDIA. It’s prosted to
consists of few commercial buildings and few test homes. The participating citizens will
provided with real-time energy consumption. This proposed project aimed to decrease

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.

2. developing strategies to control the aggregated power demand. Collectively, the


two parallel approaches make DSM whereas the later approach is known as Demand
Response (DR)

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 .

2.2 Smart Meter


A Smart Meter(SM) is usually an intelligent meter which measures and stores energy
consumption/production and some quantities related to it at regular time intervals and

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. Voltage and Current transducers section;

2. A microcontroller (C) ARM

3. A local graphic interface display

4. A memory section to locally store measurement results

Every SM continuously acquires voltage and current through a transduction and


conditioning section. The measured quantities are: Voltage and Current Root Mean
Square Value (VRMS and IRMS), Frequency (fS), Active Energy (eA), Reactive Energy
(eR), Active Power (P), Reactive Power (Q), Power Factor (PF), Voltage and Current
Total Harmonic Distortion (THDv and THDi) . Frequency is measured evaluating zero
crossings of voltage signal, after that the DC component, added by conditioning stage,
has been cancelled[5]. THDv and THDi are evaluated from Fast Fourier Transform
(FFT) of voltage and current signals, after that they are resampled to analyze a number
of samples equal to 1024, i.e. a power of 4. For space issues it been omitted the detailed
description of the measurement algorithm. After the measurement phase, these data are
transmitted across the CAN Bus from each meter to a SC that makes decisions based
on the consumption strategy adopted by the user .

2.3 Previous Case Study


Smart meters are powerful tools which fundamentally change the operation of power
grids . In addition to performing the functions of a traditional meter, smart meters
can be used as sensors across the entire distribution grid . When an Advanced Metering
Infrastructure (AMI) is in place, smart meter can measure and record actual power usage
during a day at certain time interval. These collected data are sent to a central data
management system over a secure network via wireless communication. In addition,
these sensors can be used by the utilities to detect fault and send outage or restoration
notifications [6]. Use of this information allows the utilities to provide more reliable
power supply. It also allows better planning, operation, and faster outage response of
the grid. These meters also allow increased resolution of data on various measurement
parameters across the grid and these data can be used by utilities for the following
applications :

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].

3. Improving resilience against disruptions, reducing potential outages, reducing fre-


quency and duration of outages by enhancing accuracy of the grid asset planning
and management.

2.4 Need for Advance Metering Interface


AMI is the system to add the communication link to the smart grid network. AMI
includes bidirectional data flow between end users and utilities. AMI provides intelligent
management, better maintenance, easier and proper additions and replacement of utility
assets which results in better power quality. AMI consists of three basic components:
smart metering devices at the user end, two way communication path between end user
and utility, and automated software and operation center for data processing[9].

2.5 Smart Scheduling and Billing


Electricity bill is a recurrent monthly expenditure for households and the demand for
electricity to residential consumers is generally inelastic. However, the percentage of
household income spent on energy is one of the indicators of energy poverty . Also, the
percentage of household income spent on monthly electricity bills by most residential
customers in South Africa is beyond the energy poverty threshold set by the Depart-
ment of Energy, South Africa. Hence, DSM and energy management techniques can be
introduced to enhance reasonable consumption of electricity as desired and government
threshold for energy poverty. Therefore in this work, Daily Maximum Energy Scheduling
(DMES) technique is proposed to attempt to help households spend more reasonably on
electricity bills and government to also have more households living below the energy
poverty threshold. Monthly electricity bill comes from cumulative daily consumption.
Therefore, daily energy consumption by smart home appliances connected in a HAN to
a smart meter is investigated in this work to ensure that electricity bills are within the
limit desired according to their income class[10]. This was carried out by setting max-
imum daily energy consumption limit for households through the DMES device. This
work assumes existing HAN in the homes where the DMES device will be deployed. Gen-
erally, linear programming has been a useful tool in solving many optimization problems
in economics, science and engineering. In smart grid, it has been proposed useful in
implementing many algorithms for DSM and DR among others. Mixed Integer Linear
Programming (MILP) is proposed in this work to formulate the problem for optimized
daily energy consumption in smart homes. This study has shown that incorporating
the DMES device into smart meters will further enhance energy and financial planning
and saving for both consumer and utility providers. The consumer would pay for elec-
tricity within their desired budget. The utility can also effectively plan for their energy
networks especially the generation and distribution[11]. Furthermore, the government
would have lesser number of energy poor households in the country. Also, this work is
novel to using DSM techniques to mitigate household-level energy poverty.

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

3. Demand Response with multiple energy sources’ utilization optimization

4. Demand Response experiences and experimental outcomes

3.1 Our Approach


We designed a novel dynamic pricing scheme which provides incentives for demand
response along with price certainty for consumers who are already using electricity.
Monotonic marginal (MM) pricing is based on the marginal cost of supplying electricity,
like real-time pricing, encouraging demand response during peak hours. However, by
tracking the start and end times of individual user loads, it can ensure that every users’
unit price is non-increasing for a constant consumption level.

3.2 Our results


We used publicly available data from an Independent System Operator (ISO) in the
United States to evaluate the demand response performance of an example MM pricing
plan versus historical real-time prices under various demand elasticities. The data shown
below are from a peak load (i.e., demand) day in 2012. Our simulation results (below,
left) show that MM pricing can provide system-level demand response comparable with
real-time pricing when the system needs it most. At the same time, our MM pricing
scheme ensures that every consumer’s final energy price is lower than her initial price
(below, right).

Figure 3.1: Load versus Time Curve

11
Figure 3.2: Initial Price versus Final Price

12
Chapter 4

Dynamic Switching of Priority


and Non-priority Loads Under
Dynamic Pricing

4.1 Load Switching based on priority under dynamic pric-


ing
the scheduling program in the project is done on the python language .
In the program the first objective is to obtain the 2 data that are provided for usage
, since the dynamic pricing is not available to create such an environment we use a
database to store the provided data (pricing) the database we used would be firebase
which is a google powered development software that helps us store the data and provided
other devices access provided the device has the key.
so in the second stage the data of units kWh that is needed for the prediction is
collected from the our website smartpepper.io from the collected data the pricing is
done multiplying the pricing value to the units every hour.
and with the collected data the necessary functions like scheduling and prediction
are done. for the switching of loads we use the GPIo pins that are available on the
raspberry pi.
we are able to observe the data of switching and prediction from the raspberry pi
terminal as we run the program on it
Smart scheduling is one form of load management action that allows to save energy
by minimizing demand. In order to have an efficient load schedule operation, the energy
manager should conduct power logging and record all sessions so as to measure the
usage of energy over a specific time.The electrical load schedule is an estimate of the
instantaneous electrical loads operating in a facility in terms of active ,reactive and
apparent power(measured in KW,KVar and KVA respectively).
Energy saving involves two direct benefits: sustainability and cost reduction.A hike
in the purchase of electrical appliances following a rising standard of living causes a
growing demand for energy in domestic buildings. Inefficient use of these appliances
causes wastage of energy. One way to tackle this is to give feedback to the consumers
on their behaviour, which may lead to a reduction in this wastage. Another way to re-
duce energy consumption is the application of demand side load management. The first

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:

1. provide live data pricing at every time interval

2. switching ON/OFF non priority loads when the pricing is high

3. the charging,discharge and OFF control of an inverter.

Figure 4.1: AN terminal of running program on raspberian OS

4.2 Detailed Working of the Program


The program is provided with two points in pricing .When the price is below the first
point,the procedure involves charging of inverters and running of priority and non pri-
ority loads. When it is greater than first point but below the second point , the inverter
is switched OFF while the remaining priority and non priority loads are run normally.

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.

Figure 4.2: Smart Scheduling flow chart

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.

• Accessible from Client Devices:The Firebase Realtime Database can be accessed


directly from a mobile device or web browser; there’s no need for an application
server. Security and data validation are available through the Firebase Realtime
Database Security Rules, expression-based rules that are executed when data is
read or written.

• Scale across multiple databases:With Firebase Realtime Database on the Blaze


pricing plan, you can support your app’s data needs at scale by splitting your data
across multiple database instances in the same Firebase project. Streamline au-
thentication with Firebase Authentication on your project and authenticate users
across your database instances. Control access to the data in each database with
custom Firebase Realtime Database Rules for each database instance.

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 .

Figure 4.3: Firebase

16
Chapter 5

Energy performance management


dashboard using Thingsspeak
Platform

5.1 Real-Time Analysis


Speed up your day-to-day energy management process through configurable widgets to
monitor measurements, metrics and savings, and with a feed of all the energy wastage
and failure notifications detected by our analytics software engines.

5.2 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.

5.3 Trend Analytics


Don’t waste any more time analysing raw measurements. Let our analytics engines
compare your energy use against expected patterns and alert you when your consumption
becomes abnormal.

5.4 Tariff Analytics


Assess the expected savings when negotiating new energy contracts with Utilities. Enter
the tariffs offered by the various Utilities and our tool will calculate how much you would
have paid for the past 12 months with each tariff for immediate benchmark.

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.

5.6 Data Import/Export


Control the import and export of energy data in the Wattics energy monitoring dash-
board. Apply adjustment data to your analysis for a better understanding of the factors
impacting energy use.

18
Chapter 6

Residential Task Scheduling


Under Dynamic Pricing Using
the Multiple Knapsack Method

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.

• Real-time pricing allows the prices to change on an hourly basis, based on


market demand.

• 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.

6.0.1 Coordinated Scheduling of Residential Distributed Energy Re-


sources to Optimize Smart Home Energy Services
Pedrasa et al. use a modified form of coevolutionary particle swarm optimization
(CPSO) with stochastic repulsion amongst particles, referred to as CPSO-R, for their
scheduler. The scheduler determines when various devices in the household need to
co-ordinate with each other to increase the benefits (during the peak-load hours) and
when they can operate independently (at times when coordinating with each other does
not add significant value). However, stochastic optimization techniques can be compu-
tationally expensive. If performed locally within the home, they may require significant
computational resources; if performed offline, the combined computation associated with
a large number of homes may be very significant. [11]

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.

Key terms and Notation


Cost function: The cost function Cost(t) represents the cost of consumption of a
certain amount of energy at a time instant t. It is assumed that variable peak pricing
is followed where the cost function varies with the time in the day. Generally the
cost of power consumption is high during the peak-hours (evenings and mornings) and
is considerably low during periods of low power usage (afternoons and late nights);
exceptions to these scenarios correspond to examples such as heat waves, where energy
consumptions in the afternoon may be large. Day-ahead pricing, combined with weather
forecasts, provides utilities with the tools to vary these prices in a quasi-dynamic way.
Practically speaking, the cost function is implemented as a discrete piecewise-constant
cost function, Costij, as illustrated in Figure . The per-unit price is altered to discrete
values at discrete time steps, e.g., at the top of every hour. In our exposition, we assume
that the time slots are of equal length, but it is rather simple to extend this approach
to the case where the time slot lengths are not the same.
Locally-generated power: This term may include any renewable sources of energy
such as wind energy or solar energy, that is generated on-site. These sources of energy
are not deterministic but may be reflected by their expected values. Again, weather
forecasts may be used to predict these values on a day-ahead basis

22
Figure 6.1: an example cost function,corresponding to the cost data

The Multiple Knapsack Problem or Greedy problem


In this Subsection, we map the scheduling problem to a multiple knapsack problem.
We begin by providing a brief overview of knapsack problems. The (single) knapsack
problem is a combinatorial problem where a number of objects, each associated with a
value and a weight, must be packed into a knapsack of a specific capacity, such that the
value of the objects within the knapsack is maximized. Single knapsack problems are a
standard problem template in computer science, and numerous practical problems have
been mapped on to this problem. The fractional version of the knapsack problem can be
solved using dynamic programming techniques in polynomial time. The integer problem
is NP-complete, but a number of efficient polynomial-time approximation algorithms are
available to provide near-optimal solutions.
The multiple knapsack problem (MKP) is a generalization of the single knapsack
problem. In essence, the MKP is a resource allocation problem wherein there is a set
of m resources (i.e., m knapsacks) and a set of n objects. As in the single knapsack
problem, each object i in this set of n objects has two important attributes associated
with it: the value of the object and its weight. Every resource (knapsack) j has a capacity
constraint Cj, which represents the maximum weight that the resource can support. The
objective of the MKP is to find a subset of the objects that can be packed within the
bins such that the net value of all objects within all knapsacks is maximized. Although
the integer MKP problem is NP-complete, in practice optimal or near-optimal solutions
are available in polynomial time or for very reasonable runtimes . [15] [16]

Mapping the Scheduling Problem to the MKP


The mapping between our scheduling problem and the MKP is now outlined:
• The m knapsacks correspond to m time intervals where the energy price is fixed.

• The n appliances correspond to n objects that must be packed.

• 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.

6.0.4 Modeling The Objetive Function And Constrains


The description of the problem formulation is divided into two sub phases: initially
we describe a formulation that schedules only the smart appliances, as specified by the
consumer. Next, we extend to formulation to account for must-run services and locally-
generated power.

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:

Incorporating Must-run Services and Locally-Generated Power


The formulation is now extended to include the power consumed by the must-run services
and locally-generated power. Let us consider Emj to be the power that is consumed by
the must-run services at a time slot j. As a result, the energy consumption in slot j must
be incremented by Emj for all slots j. The effects of this change are:

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)

For simplicity, we set Must-run usage = Locally-generated power = 0 in all slots


As seen earlier, these parameters simply affect the right-hand side of the capacity con-
straints, and can be considered as alterations to the capacity. The optimization problem
can then be formulated as:

(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

6.1 Simulation And Results using What’sBest solver


The optimization problem formulated above was solved using the What’sBest solver .
What’sBest is an add-on to Microsoft Excel and allows building large linear, non-linear,
integer, or stochastic optimization models within a spreadsheet. [17]

Table 6.1: Appliance parameters

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

Figure 6.3: Results from an 18-appliance, 16-time-slot probleum .

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.

uniformity in the energy profile in the home.


Further constraints can easily be built into this system: although these have not
been shown here. One example is when a customer wishes to constrain the time range
in which a specific task is scheduled by specifying a preference. This is quite simple
to incorporate into the current system by reducing the number of Xij variables: if an
appliance is not to be scheduled in a specified slot, the corresponding Boolean variable
is set to zero (and is therefore not a variable). This, in fact, makes the optimization
simpler since it reduces the number of variables. Another example: we have enabled
scheduling with interruptible tasks and sufficiently large time slots, but a customer may
wish for some appliances to be scheduled in contiguous time slots (e.g., laundry tasks).
In this connection, for finer-grained scheduling, fractional time slots with contiguous
scheduling may be desirable. We expect to include this in future work

29
Chapter 7

0-1 Multiple knapsack problem


and Solving the
Multi-Dimensional Knapsack
Problem with Python

The multiple knapsack problem is a generalization of the standard knapsack problem


(KP) from a single knapsack to m knapsacks with (possibly) different capacities. The
objective is to assign each item to at most one of the knapsacks such that none of the
capacity constraints are violated and the total profit of the items put into knapsacks is
maximized.

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)

If assumption is violated, fractions can be handled by multiplying through by a


proper factor, while nonpositive values can easily be handled by eliminating all items
with pj ¡ 0 and all knapsacks with c; ¡ 0. (There is no easy way, instead, of transforming
an instance so as to handle negative weights. All the considerations in this Chapter,
however, easily extend to the case of nonpositive values.) Items j violating assumption
, as well as knapsacks/ violating assumption, can be eliminated. If a knapsack, say /*,
violates assumption , then the problem has the trivial solution;

(7.5)

Finally, observe that if m ¿ n then the (m - n) knapsacks of smallest capacity can be


eliminated. We will further assume that the items are sorted so that

(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)

and two knapsacks with the following capacities:

(7.8)

We assign these items to knapsacks in order to maximize the profit?

(7.9)

32
Chapter 8

Design of Energy Meter Based on


PROTEUS

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.[?]

8.1 Hardware Design 1


Our proposed design was developed by using PROTEUS software. This software widely
used to simulate a system related to the electricity The hardware of Energy Meter in-
cludes several modules such as current sensor, voltage sensor, zero crossing detector,
microcontroller, Thin Film Transistor Display (TFT)display, keypad modules, Light-
Emitting Diode (LED) indicator or buzzer, and a Wifi module NODEMCU These mod-
ules are integrated as a system block diagram as shown in Fig.

8.1.1 Design of Voltage Sensor 1


Voltage is electrical potential difference between two points in a circuit. The measure-
ment of voltage is important in the digital energy meter.

8.1.2 Design of Current Sensor 2


Current sensor was used to measure how much electric current flows on the grid in the
household. This study uses current sensor that widely available in the market namely
the type ACS712. This sensor directly integrated with a digital energy meter. Fig.
shows the design of current sensor.

8.1.3 Design of Micro-controller 3


Power calculation process used in digital meter prepayment will be made in the form of
a program that is embedded in a chip microcontroller. The microcontroller process all

33
Figure 8.1: Design of Voltage Sensor

Figure 8.2: Design of Electric Current Sensor

the modules that have been integrated. Type of microcontroller used in the design of
our digital meter is ATmega2546 and ESP8266.

8.1.4 Design of LED Indicator and Buzzer 4


In order to complete the energy meter, an indicator needs to be installed. This indicator
could be a signal when the energy was reduced. This paper uses LED and buzzer as
the indicator. LED is an electronic components that can emit monochromatic light and
buzzer is an electronic component to convert electrical vibration into sound vibration.
Fig. 6 shows the design of indicator LED and buzzer.

8.1.5 Design of Keypad 5


In order to complete the energy meter, an indicator needs to be installed. This indicator
could be a signal when the energy was reduced. This paper uses LED and buzzer as
the indicator. LED is an electronic components that can emit monochromatic light and
buzzer is an electronic component to convert electrical vibration into sound vibration.
Fig. 6 shows the design of indicator LED and buzzer.

34
Figure 8.3: Block diagram of proposed energy meter

8.1.6 Design of Circuit Breaker (Relay) 6


Based on the calculation results by power digital meter, if it is deemed to exceed the
specified load, the system will disconnect the electrical current. In order to disconnect
automatically, it is necessary to install the circuit breaker module as shown in Figure.

8.1.7 Design of LCD 7


The important information such as voltage and current need to be displayed, it will
appear on the display screen. LCD (Liquid Crystal Display) size 20x4(which is replaced
by 2.4inch TFT display in real project Smart Pepper) is used to display the information.

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

Figure 8.5: Design of LED Indicator and Buzzer

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

Figure 8.7: Design of Circuit Breaker

8.3 Inferential Conclusions from Simulation Analysis 3


This chapter presents the simulation process of energy meter(Smart Pepper) based on
PROTEUS software. Our proposed hardware design is completely and successfully ap-
plied by the software. The cost of simulation was minimized because the experiment
was performed by using this software. Based on the simulation, our design energy meter
produces small error of voltage and current from sensor measurement. From the accu-

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

Table 8.1: Test results for voltage sensor

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

Figure 8.10: The Simulation of Current Sensor

39
Table 8.2: Test results for current sensor

Figure 8.11: The Simulation of Voltage Sensor

Figure 8.12: The Simulation of Current Sensor

40
Chapter 9

Circuit Design and Signal


Integrity and Designing of PCB
Layout

9.1 Measuring mains voltage and current


Including voltage measurement via AC-AC voltage adapter(regular transformer) and
current measurement via a CT sensor.

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

• 1x 9V AC-AC Power Adapter

• 1x 100kOhm resistor for step down voltage divider

• 1x 10kOhm resistor for step down voltage divider

• 2x 470kOhm (for voltage divider, any matching value resistor pair down to 10K)

• 1x 10uF capacitor

• 1x CT sensor SCT-013-000

• 1x Burden resistor 18 Ohms if supply voltage is 3.3V or 33 Ohms if supply voltage


is 5V

• 2x 470kOhm (for voltage divider, any matching value resistor pair down to 10K)

• 1x 10uF capacitor

9.2 Measuring AC Voltage with an AC to AC power adapter


An AC voltage measurement is needed to calculate real power, apparent power and
power factor. This measurement can be made safely (requiring no high voltage work) by
using an AC to AC power adaptor. The transformer in the adapter provides isolation
from the high voltage mains.
This session briefly covers the electronics required to interface an AC to AC power
adapter with an Arduino.

Figure 9.2: Measuring AC Voltage with an AC to AC power adapter

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:

Figure 9.3: 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.

9.3 Improving the quality of the bias source


9.3.1 Buffered Voltage Bias
The relatively simple voltage bias source illustrated in Measuring AC Voltage with an
AC to AC power adapter does have some limitations if high accuracy is required. It
can be improved by adding an operational amplifier. The op.amp isolates the mid-
point voltage at the junction of R3 R4 from the AC-AC adapter and voltage divider.
This significantly reduces the impedance of the voltage source, resulting in enhanced
performance. Only one op.amp is needed, the current sensors can share the bias supply
and connect to amplifier output (“mid-point”) with little fear of interaction between the
inputs (which can be troublesome in some circumstances).

9.3.2 Simulation of Buffered Voltage Bias Proteus


9.3.3 Simulation Results of Buffered Voltage Bias Proteus
9.3.4 Simulation of complete circuit in direct loading
• This modification might not be suitable if the power source is batteries,

• 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.

9.4 CT Sensors - Interfacing with an Arduino


To connect a CT sensor to an Arduino, the output signal from the CT sensor needs to
be conditioned so it meets the input requirements of the Arduino analog inputs, i.e. a
positive voltage between 0V and the ADC reference voltage.
Note: This session give the example of an Arduino board working at 5 V and of the
ACS 7115 working at 3.3 V. Make sure you use the right supply voltage and bias voltage
in your calculations that correspond to your setup.
This can be achieved with the following circuit which consists of two main parts:

• The CT sensor and burden resistor

• The biasing voltage divider (R1 R2)

44
Figure 9.4: Buffered Voltage Bias circuit diagram

Figure 9.5: Simulation of Buffered Voltage Bias Proteus

9.4.1 Calculating a Suitable Burden Resistor Size


If the CT sensor is a ”current output” type such as the YHDC SCT-013-000, the current
signal needs to be converted to a voltage signal with a burden resistor. If it is a voltage
output CT you can skip this step and leave out the burden resistor, as the burden resistor
is built into the CT.

45
Figure 9.6: Simulation Results(voltage waveforms) of Buffered Voltage Bias Proteus

Figure 9.7: Simulation of complete circuit in direct loading

Choose the current range you want to measure


The YHDC SCT-013-000 CT has a current range of 0 to 100 A. For this example, let’s
choose 100 A as our maximum current.

Convert maximum RMS current to peak-current by multiplying by 2.

1 Primary peak−c u r r e n t = RMS c u r r e n t 2 = 100 A 1 . 4 1 4 = 1 4 1 . 4A


2

46
Figure 9.8: CT Sensors

Figure 9.9: CT Waveform

Divide the peak-current by the number of turns in the CT to give the


peak-current in the secondary coil.
The YHDC SCT-013-000 CT has 2000 turns, so the secondary peak current will be:
1 Secondary peak−c u r r e n t = Primary peak−c u r r e n t / no . o f t u r n s = 1 4 1 . 4 A /
2000 = 0 . 0 7 0 7A
2

To maximise measurement resolution, the voltage across the burden resistor


at peak-current should be equal to one-half of the Arduino analog reference
voltage. (AREF / 2)
If you’re using an Arduino running at 5V: AREF / 2 will be 2.5 Volts. So the ideal
burden resistance will be:
1 I d e a l burden r e s i s t a n c e = (AREF/ 2 ) / Secondary peak−c u r r e n t = 2 . 5 V /
0.0707 A = 35.4
2

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 Extending the Current Transformer Cable


The output from a true current transformer is a current. The c.t. will generate whatever
voltage is needed to make that current flow in the burden resistor, where it is converted
into a voltage, which will range from zero to about 1 – 1.5 V. If you have a c.t. with an
internal burden, the “voltage output” type, then the output is the voltage that appears
across the burden resistor, but the current is very small. In both cases, the cable that
you need and how you connect it will be the same. There should be no real limit to the
maximum length of the cable that you can have. Voltage drop is largely irrelevant, and
the main limiting factor is likely to be interference from outside sources.

9.5.1 Materials
• A length of twin screened “microphone” cable.

• A 3-pole “stereo” 3.5 mm jack plug.

• A length of wire to earth the cable screen.

• Sleeving to insulate protect the joints.

9.5.2 Choice of cable


You should choose a cable designed for microphones. This will have twin twisted cores
with an overall braided screen. A ‘braided’ screen is better than ‘lapped’. The more
tightly the screen is woven, the better it will be at keeping out interference.

Figure 9.10: Choice of 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.11: 3.5 mm jack plug from your c.t.

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.

9.6 Measurement Implications of ADC Resolution at Low


Current Values
Common problems we faced:
• Current sensor read (X) Amps when there is no current flowing.
• Reading (Y) Watts when nothing is connected
It’s because the analogue to digital converter (ADC) in the Arduino chip is not
perfect.

Figure 9.13: schematics of CT bias voltage divider

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

Figure 9.15: Sample 2 -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.

9.7 PCB designing using EasyEDA


EasyEDA is a web-based EDA tool suite that enables hardware engineers to design,
simulate, share - publicly and privately - and discuss schematics, simulations and printed
circuit boards. Other features include the creation of a Bill of Materials, Gerber and
pick and place files and documentary outputs in PDF, PNG and SVG formats.
EasyEDA allows the creation and editing of schematic diagrams, SPICE simulation
of mixed analogue and digital circuits and the creation and editing of printed circuit
board layouts and, optionally, the manufacture of printed circuit boards.
Drawn the schematic on EasyEDA editor as below image showed:

Figure 9.16: schematic on EasyEDA editor

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

Figure 9.17: PCB Front side

Figure 9.18: PCB Back side

PCB).

53
Chapter 10

Hardware

10.1 Current Transformer

Figure 10.1: YHDC Current Transformer SCT-013-000

Here’s an example of a Magnelab split-core CT:

Figure 10.2: Magnelab split-core CT

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:

Figure 10.3: 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

10.1.1 Types of Current Transformer


There are two types, they operate in exactly the same way, the difference is in their
construction.

1. The Ring-core Current Transformer.

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.

2. The Split-core Current Transformer.

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.

10.1.2 How a CT works


A wire carrying an electric current sets up a magnetic field around it. The wire forms
the primary winding of the transformer. The iron (or ferrite) transformer core concen-
trates the field and couples it to the secondary winding. and, provided the magnetic
field continually changes, causes a current to flow in that winding too. That current
flows in the burden resistor, which generates a voltage the emonTx can use. A current
transformer will not measure direct current.
You can pass more than one wire through the opening of a current transformer if
you want the sum (more specifically, the vector sum) of the currents. There are two
common instances where this is useful:

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.

10.2 Potential Transformer

Figure 10.4: Potential Transformer

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.

10.3 Rogowski Coil


The Rogowski Coil is an electrical device used for measuring alternating current such
as high speed transient; pulsed currents or power frequency sinusoidal currents.In its
simplest form a Rogowski coil is an evenly wound coil of N turns per metre on a non-
magnetic former of constant cross sectional area A. The winding wire is returned to
the starting point along the central axis of the former and the two ends are typically
connected to a cable. The free end of the coil is normally inserted into a socket adjacent
to the cable connection in a way that allows it to be unplugged thus enabling the coil
to be looped around the conductor carrying the current to be measured.
An alternating or pulsed current in a conductor develops a magnetic field and the
interaction of this magnetic field and the Rogowski coil local to the field gives rise to an
induced voltage within the coil which is proportional to the rate of change of the current
being measured. Provided the coil constitutes a closed loop with no discontinuities,
it may be shown that the voltage E induced in the coil is proportional to the rate of
change of the encircled current I according to the relationship E=H.dI/dt, where H, the
coil sensitivity in (Vs/A), is proportional to NA.To obtain an output voltage VOUT
proportional to I it is necessary to integrate the coil voltage E; hence an electronic
integrator is used to provide a bandwidth extending down to below 1Hz. The op-amp

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.

10.4 Arduino Mega 2560


Arduino Mega 2560 is a Micro controller board based on Atmega 2560. It comes with
more memory space and I/O pins as compared to other boards available in the mar-
ket.There are 54 digital I/O pins and 16 analog pins incorporated on the board that
make this device unique and stand out from others.Out of 54 digital I/O, 15 are used for
PWM (pulse width modulation).A crystal oscillator of 16 MHz frequency is added on
the board.This board comes with USB cable port that is used to connect and transfer
code from computer to the board.DC power jack is coupled with the board that is used

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

Figure 10.8: NodeMCU Pin Diagram

10.5.1 Serial Communication between NodeMCU and Arduino


Serial communication is a communication process wherein data transfer occurs by trans-
mitting data one bit at a time in sequential order over a computer bus or a communi-
cation channel. It is the most widely used approach to transfer information between
data processing equipment and peripherals. Binary One represents a logic HIGH or 5
Volts, and zero represents a logic LOW or 0 Volts, used for communicating between the
Arduino board and a computer or other devices. All Arduino boards have at least one
serial port which is also known as a UART or USART. It communicates on digital pins
0 (RX) and 1 (TX) as well as with the computer via USB. Serial communication on pins
TX/RX uses TTL logic levels (5V or 3.3V depending on the board).To establish serial
communication between two devices, the devices should be connected as shown below.

60
Figure 10.9: serial

Figure 10.10: Serial Communication between NodeMCU and Arduino.

10.5.2 Sending Multiple data between NodeMCU and Arduino:


To send multiple data in serial, JSON can be adapted. JSON stands for JavaScript
Object Notation. JSON is a lightweight data interchange format for structuring data.
JSON is based on key-value pairs. Key is always string, where value may be a integer,
string or an array. An example of JSON is given below
1 {
2 ”name” : ” Smartpapper data 1 ” ,
3 ” no of posts ” :52 ,
4 ”members” : 4
5 }
6

JsonBuffer does the memory management function. It contains two types


1. DynamicJsonBuffer

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

Figure 10.11: Raspberry Pi

It is an highly integrated 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.The raspberry pi board comprises a program memory (RAM), processor
and graphics chip, CPU, GPU, Ethernet port, GPIO pins, Xbee socket, UART, power
source connector. And various interfaces for other external devices. It also requires
mass storage, for that we use an SD flash memory card. So that raspberry pi board will
boot from this SD card similarly as a PC boots up into windows from its hard disk.The
raspberry pi model Aboard is designed with 256MB of SDRAM and model B is designed
with 51MB.Raspberry pi is a small size PC compare with other PCs. The normal PCs
RAM memory is available in gigabytes. But in raspberry pi board, the RAM memory
is available more than 256MB or 512MB.
Making sure we can actually set a value on a GPIO pin We are installing a package
that allow us to set values on a pin from command line. Just to make sure we’re actually
able to turn the GPIO value high and low.
1 sudo apt−g e t i n s t a l l w i r i n g p i

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 Relay Module


A relay is an electrically operated switch that can be turned on or off, letting the
current go through or not, and can be controlled with low voltages, provided by the
Arduino pins.The relay module is a separate hardware device used for remote device
switching. We can remotely control devices over a network or the Internet using it .The
Relay module houses two SPDT relays and one wide voltage range, optically isolated
input.The 4-Channel Relay Driver Module makes it simple and convenient to drive loads
such as 12V relays from simple 5V digital outputs of Arduino compatible board or other
microcontroller.

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+

Figure 10.15: 4 channel relay schematic

control port Output: Connect a load, DC 30V/10AAC 250V/10A


1. Size: 75mm (Length) * 55mm (Width) * 19.3mm (Height) Weight: 61g

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

4. Optical coupling isolation, good anti-interference.

5. Closed at low level with indicator on, released at high level with indicator off

6. VCC is system power source, and JDVCC is relay power source.

7. Ship 5V relay by default. Plug jumper cap to use

8. The maximum output of the relay: DC 30V/10A, AC 250V/10A

65
Chapter 11

Energy performance management


dashboard using ThingsSpeakTM
platform

11.1 Real-Time Analysis


Speed up your day-to-day energy management process through configurable widgets to
monitor measurements, metrics and savings, and with a feed of all the energy wastage
and failure notifications detected by our analytics software engines.

11.2 Thingspeak IoT Platform


ThingSpeakTM is an IoT analytics platform service that allows you to aggregate, visualize
and analyze live data streams in the cloud. ThingSpeak provides instant visualizations
of data posted by your devices to ThingSpeak. With the ability to execute MATLAB R
code in ThingSpeak you can perform online analysis and processing of the data as it
comes in. ThingSpeak is often used for prototyping and proof of concept IoT systems
that require analytics.
nternet of Things (IoT) describes an emerging trend where a large number of em-
bedded devices (things) are connected to the Internet. These connected devices commu-
nicate with people and other things and often provide sensor data to cloud storage and
cloud computing resources where the data is processed and analyzed to gain important
insights. Cheap cloud computing power and increased device connectivity is enabling
this trend.
IoT solutions are built for many vertical applications such as environmental mon-
itoring and control, health monitoring, vehicle fleet monitoring, industrial monitoring
and control, and home automation.
At a high level, many IoT systems can be described using the diagram below:
On the left, we have the smart devices (the “things” in IoT) that live at the edge
of the network. These devices collect data and include things like wearable devices,
wireless temperatures sensors, heart rate monitors, and hydraulic pressure sensors, and
machines on the factory floor.

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.

11.2.1 ThingSpeak Key Features


• Easily configure devices to send data to ThingSpeak using popular IoT protocols.

• Visualize your sensor data in real-time.

• Aggregate data on-demand from third-party sources.

• Use the power of MATLAB to make sense of your IoT data.

• Run your IoT analytics automatically based on schedules or events.

• 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 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.

Figure 11.3: IoT systems

11.3.1 Over Usage Warning


When the power utilization is above a particular point

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.5 Trend Analytics


Don’t waste any more time analysing raw measurements. Let our analytics engines
compare your energy use against expected patterns and alert you when your consumption
becomes abnormal.

11.6 Measurement Verification


Set baseline/reporting periods and routine/non-routine adjustments and let Wattics
model your energy use and calculate kWh and rupees savings according to utility
provider.

11.7 Tariff Analytics


Assess the expected savings when negotiating new energy contracts with Utilities. Enter
the tariffs offered by the various Utilities and our tool will calculate how much you would
have paid for the past 12 months with each tariff for immediate benchmark.

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.

11.9 Operations Wastage Analysis


Evaluate quickly patterns of power consumption and when peak load demand happens.
Overnight activity and periods of high power activity will guide you to sources of oper-
ational wastage.

11.10 Power Quality Analysis


Access and visualise the wide range of electrical parameters for deep power quality
analysis. Navigating through different periods of time allows you to visualise the latest
kW, PF, V, I and THD readings and analyse daily/weekly patterns. Data can be
exported in one click to image, PDF and CSV format.

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.

11.12 Actions Tracker


Organise your energy-saving projects in one place to reduce the time spent on tracking
installations and behavioural changes. Compare daily average cost calculations to prove
your project’s savings for clients or for certification.

11.13 Data Import/Export


Control the import and export of energy data in the Wattics energy monitoring dash-
board. Apply adjustment data to your analysis for a better understanding of the factors
impacting energy use.

Figure 11.4: Data Import/Export

70
Chapter 12

AC Power Theory - Arduino


Maths

12.1 Instantaneous Voltage and Current


AC Voltage and current continually alternate and if we draw a picture of the voltage
and current waveform over time, it will be as shown in the image below. Depending on
the type of load consuming power, the current waveform (blue) is obtained by looking
at a typical laptop computer power supply. . The image is made by sampling the mains
voltage and current at high frequency, which is exactly done on the emontx or Arduino.
Measurements between 50 and 100 are made every 20 milliseconds , 100, if sampling
only current and 50, if sampling voltage and current. We are limited by the Arduino
analog read command and calculation speed.Each individual sample is an instantaneous
voltage or current reading.

Figure 12.1: Instantaneous voltage or current reading

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

12.3 Root-Mean-Square (RMS) Voltage


The root-mean-square is calculated in the way the name suggests. First we square the
quantity, then we calculate the mean and finally, the square-root of the mean of the
squares, this is how its done:
1 f o r ( n=0; n// i n s t v o l t a g e 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 .
2
3 squared voltage = inst voltage ∗ inst voltage ;
4
5 s u m s q u a r e d v o l t a g e += s q u a r e d v o l t a g e ;
6 }
7
8 mean square voltage = sum squared voltage / number of samples ;
9 root mean square voltage = sqrt ( mean square voltage ) ;
10
11 \ s e c t i o n {Root− Mean− Square (RMS) Current }

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 ) ;

12.4 Apparent Power


1 apparent power = root mean square voltage ∗ root 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 ;

That’s the fundamentals of AC power measurement on the smartpepper or an Arduino.


12.5 EmonLib
All these calculations have been packaged into an Arduino library called EmonLib to
simplify Arduino energy monitor sketches. The library can be found on github here:
https://github.com/TheJojoJoseph/EmonLib

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.

13.1 Load aggregation using clustering


The large network of AMI and smart sensors generate a large amount of data. If this
data is exploited for extraction of load patterns of individual customer, this data can
be utilized in decisions regarding not only the energy pricing but also for operational
management which includes load forecasting. However on the other hand, getting an
in-depth view of individual consumer loads for load patterns from a large volume of
smart meter data is challenging with the increasing population of smart meter owned
consumers .
To analyse smart grid data, there are different data mining and data clustering tech-
niques. The electricity consumption data is unlabelled and stochastic in nature, the
application of unsupervised learning using probabilistic techniques including data clus-
tering is more suitable for data mining rather than deterministic techniques .Clustering
techniques classify the consumers based on their behaviours and models of daily load
profiles can be built using the classes. Therefore, data clustering can be used to identify
consumers with similar energy consumption behaviours and each class of consumer can
be aggregated to generate a single profile which becomes the representative profile. This
profile can be used for forecasting of the entire consumer class. Most commonly used
techniques for data clustering in smart grids are Hierarchical and Kmeans clustering.
A comparative analysis of hierarchical, kmeans, fuzzy c-means and two staged fuzzy
clustering techniques to generated typical load profiles was carried out by and it was
found that K-means had the minimum MAPE while Hierarchical clustering had highest
MAPE. Therefore, in this study we used extended k-means clustering which a variation
of k-means clustering developed in our previous works and improved for automation
by defining different criterion. HE demand response is one of the key technologies in
smart grid that contributes to reducing the peak loads and reshaping the load profiles
to save additional investments on costly standby generation units. Many studies have
been done about the residential and commercial loads participating in the DR programs
. The typical load profiles are important to assess the schedulable load capacity, develop
price-based or incentive-based DR programs and decide the scheduling scheme. The
load classification is to separate enormous load profiles into several typical clusters. In
recent years, researchers have proposed a variety of clustering methods.
Some of clustering methods were usually used to process the load profiles such as
division-based clustering algorithms including fuzzy C-means and K-means, hierarchical-
based clustering algorithm, network-based clustering algorithm of self-organizing map,
density-based With the development of data mining technologies, some new clustering
methods have emerged for electricity consumption patterns classification. In order to
acquire the optimal number of clusters, literature proposes a clustering method based on

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.

13.2 Load modelling


Although data clustering has solved the problem of handling big data and load aggrega-
tion at suitable level, however the issue of volatility and variability of the load profiles
persists. For load forecasting, variability of the data increases the uncertainty thus
increasing the forecast error. This error can be tackled by linearizing the non-linear
patterns thus minimizing the variations in the load over time.
Linearization of load profiles from smart meter data was proposed in our previous
work . AD modeling is essential to power system analysis, planning, and control. For
example, studies have shown the importance of accurate load representations in volt-
age stability assessment . Although the need for accurate load models is recognized by
power system researchers and engineers more research is imperative to update existing
load models and understand characteristics of modern loads with emerging smart grid
technologies such as distributed generators (DGs), electric vehicles (EVs), and demand
side management (DSM). The uncertainty and difficulty of load modeling comes from
the large number of diverse load components, time-varying and weather-dependent com-
positions, and the lack of measurements and detailed load information. The goal of load
modeling is to develop simple mathematical models to approximate load behaviors.

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.

• Enable consumers to adjust their habits in order to lower electricity bills.

• Reduces the number of blackouts and system-wide electricity failures.

• Eliminates manual monthly meter readings.

• Monitors the electric system much more quickly.

• Makes it possible to use power resources more efficiently.

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.

• Avoids the capital expense of building new power plants.

• Helps to optimize income with existing resources.

• 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.

• Reduces pollution created by vehicles driven by meter readers.

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.

• Managing and storing vast quantities of the metering data collected.

• Ensuring the security and privacy of metering data.

• It’s hard to verify that the new meter is accurate.

• There’s no way to protect the privacy of the personal data collected.

• There is an additional fee for the installation of the new meter.

78
Chapter 15

Future Scope

15.1 Automatic pf correction with the help of capacitor


bank
A poor power factor due to induction motors, transformers, and other inductive loads
can be corrected by connecting suitable capacitors.
A poor power factor caused by distorted current waveform is corrected by adding
harmonic filters. The process of creating the magnetic field required by an inductive
load causes a phase difference between the voltage and the current. A capacitor corrects
the power factor by providing a leading current to compensate the lagging current.
Power factor correction capacitors are designed to ensure that the power factor is as
close to unity as possible. Although power factor correction capacitors can considerably
reduce the burden caused by an inductive load on the supply, they do not affect the
operation of the load. By neutralising the magnetic current, capacitors help to cut
losses in the electrical distribution system and reduce electricity bills.
These capacitor can be added to the household and with our current hardware and a
few modifiations in the software we can implement the automatic pf correction scheme
to our smartpepper with minimum .

15.2 Identification of loads


Dynamic load management, i.e., allowing electricity utilities to remotely turn electric
appliances in households on or off, represents a key element of the smart grid. Appliances
should however only be disconnected from mains when no negative side effects, e.g.,
loss of data or thawing food, are incurred thereby. This motivates the use of appliance
identification techniques, which determine the type of an attached appliance based on the
continuous sampling of its power consumption. While various implementations based on
different sampling resolutions have been presented in existing literature, the achievable
classification accuracies have rarely been analyzed. We address this shortcoming and
evaluate the accuracy of appliance identification based on the characteristic features of
traces collected during the 24 hours of a day.
So with this scheme we can identify which loads are being run at the given time and
provide notifications to alert the users

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.

15.4 Real-Time Analysis


Speed up your day-to-day energy management process through configurable widgets to
monitor measurements, metrics and savings, and with a feed of all the energy wastage
and failure notifications detected by our analytics software engines.

15.5 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.

15.6 Trend Analytics


Don’t waste any more time analysing raw measurements. Let our analytics engines
compare your energy use against expected patterns and alert you when your consumption
becomes abnormal.

15.7 Tariff Analytics


Assess the expected savings when negotiating new energy contracts with Utilities. Enter
the tariffs offered by the various Utilities and our tool will calculate how much you would
have paid for the past 12 months with each tariff for immediate benchmark.

15.8 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.

15.9 Data Import/Export


Control the import and export of energy data in the Wattics energy monitoring dash-
board. Apply adjustment data to your analysis for a better understanding of the factors
impacting energy use.

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.

[12] Mohsenian-Rad, A.-H., Wong, V. W. S., Jatskevich, J., Schober, R. (2010).


Optimal and autonomous incentive-based energy consumption scheduling al-
gorithm for smart grid. 2010 Innovative Smart Grid Technologies (ISGT).
doi:10.1109/isgt.2010.5434752

[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.

[15] H. Kellerer, U. Pferschy, and D. Pisinger, Knapsack Problems, Springer, 2004.

[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.

[17] “What’sBest” LINDO Systems Inc., http://www.lindo.com/index.php?option=comcontentvi


ew=articleid=3Itemid=11

[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.

[19] “Report on working of State Power Utilities Electricity Department”, 2011-12,


Planning Comission, India.

[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

A.1 Jojo Joseph


Jojo Joseph, was the keen in yielding the best results to industry and academia from
this project. He was instrumental to the foundation of this project. He envisioned and
implemented residential task scheduling algorithm under dynamic pricing using multiple
Knapsack problem.

1. IoT platform (MQTT protocol) ThingsSpeak IOT platform.

2. Metering algorithm based on correlations http://www.github.com/TheJojoJoeph/pepper.

3. Implemented residential task scheduling algorithm under dynamic pricing using


multiple Knapsack problem.

4. Creation of web interface(www.smartpepper.tk).

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

A.2 Solamen Paul Alex


1. started and built up the program for scheduling prediction and pricing.

2. implemented the usage of website and data collection algorithm .

3. simulated the testing of voltage and current sensors on proteus.

4. hardware testing and analysis.

5. PCB designing

83
A.3 Christina George
1. simulated the pf measurement unit on proteus.

2. simulated the overall measurement system on proteus.

3. assembly of hardware and calabration instruments

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

Software Source Code

C.0.1 Scheduling Program

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 }

C.0.3 IoT and Interface display (Thingspeak-node) running on NodeMCU


(ESP8266)

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

D.1 ADS1115 - Texas Instruments

104
Product Order Technical Tools & Support &
Folder Now Documents Software Community

ADS1113, ADS1114, ADS1115


SBAS444D – MAY 2009 – REVISED JANUARY 2018

ADS111x Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs


With Internal Reference, Oscillator, and Programmable Comparator
1 Features 3 Description
1• Ultra-Small X2QFN Package: The ADS1113, ADS1114, and ADS1115 devices
2 mm × 1.5 mm × 0.4 mm (ADS111x) are precision, low-power, 16-bit, I2C-
compatible, analog-to-digital converters (ADCs)
• Wide Supply Range: 2.0 V to 5.5 V offered in an ultra-small, leadless, X2QFN-10
• Low Current Consumption: 150 μA package, and a VSSOP-10 package. The ADS111x
(Continuous-Conversion Mode) devices incorporate a low-drift voltage reference and
• Programmable Data Rate: an oscillator. The ADS1114 and ADS1115 also
8 SPS to 860 SPS incorporate a programmable gain amplifier (PGA) and
a digital comparator. These features, along with a
• Single-Cycle Settling wide operating supply range, make the ADS111x well
• Internal Low-Drift Voltage Reference suited for power- and space-constrained, sensor
• Internal Oscillator measurement applications.
• I2C Interface: Four Pin-Selectable Addresses The ADS111x perform conversions at data rates up
• Four Single-Ended or Two Differential Inputs to 860 samples per second (SPS). The PGA offers
(ADS1115) input ranges from ±256 mV to ±6.144 V, allowing
precise large- and small-signal measurements. The
• Programmable Comparator (ADS1114 and ADS1115 features an input multiplexer (MUX) that
ADS1115) allows two differential or four single-ended input
• Operating Temperature Range: measurements. Use the digital comparator in the
–40°C to +125°C ADS1114 and ADS1115 for under- and overvoltage
detection.
2 Applications The ADS111x operate in either continuous-
• Portable Instrumentation conversion mode or single-shot mode. The devices
are automatically powered down after one conversion
• Battery Voltage and Current Monitoring in single-shot mode; therefore, power consumption is
• Temperature Measurement Systems significantly reduced during idle periods.
• Consumer Electronics
Device Information(1)
• Factory Automation and Process Control
PART NUMBER PACKAGE BODY SIZE (NOM)
X2QFN (10) 1.50 mm × 2.00 mm
ADS111x
VSSOP (10) 3.00 mm × 3.00 mm
(1) For all available packages, see the package option addendum
at the end of the data sheet.

Simplified Block Diagrams


VDD VDD VDD

Comparator Comparator
Voltage Voltage ALERT/ Voltage ALERT/
Reference Reference RDY Reference RDY

ADDR ADDR AIN0 ADDR


AIN0 16-Bit AIN0 16-Bit 16-Bit
û¯ I2C PGA û¯ I2C AIN1 PGA û¯ I2C
Interface SCL Interface SCL MUX Interface SCL
AIN1 ADC AIN1 ADC AIN2 ADC
SDA SDA SDA
AIN3
Oscillator Oscillator Oscillator
ADS1113 ADS1114 ADS1115

GND GND GND


Copyright © 2016, Texas Instruments Incorporated

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

5 Device Comparison Table


MAXIMUM SAMPLE INPUT CHANNELS
RESOLUTION SPECIAL
DEVICE RATE Differential PGA INTERFACE
(Bits) FEATURES
(SPS) (Single-Ended)
ADS1115 16 860 2 (4) Yes I2C Comparator
ADS1114 16 860 1 (1) Yes I2C Comparator
ADS1113 16 860 1(1) No I2C None
ADS1015 12 3300 2 (4) Yes I2C Comparator
ADS1014 12 3300 1 (1) Yes I2C Comparator
ADS1013 12 3300 1 (1) No I2C None
ADS1118 16 860 2 (4) Yes SPI Temperature sensor
ADS1018 12 3300 2 (4) Yes SPI Temperature sensor

6 Pin Configuration and Functions

RUG Package DGS Package


10-Pin X2QFN 10-Pin VSSOP
Top View Top View
SCL

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

GND 3 7 AIN3 AIN1 5 6 AIN2

AIN0 4 6 AIN2 Not to scale


5

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.

Copyright © 2009–2018, Texas Instruments Incorporated Submit Documentation Feedback 5


Product Folder Links: ADS1113 ADS1114 ADS1115

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)

Table 2-1 lists the definitions and functions of each pin.

Table 2-1. ESP8266EX Pin Definitions

Pin Name Type Function

1 VDDA P Analog Power 2.5V ~ 3.6V

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.

3 VDD3P3 P Amplifier Power 2.5V ~ 3.6V

4 VDD3P3 P Amplifier Power 2.5V ~ 3.6V

5 VDD_RTC P NC (1.1V)

ADC pin. It can be used to test the power-supply voltage of


VDD3P3 (Pin3 and Pin4) and the input power voltage of TOUT
6 TOUT I
(Pin 6). However, these two functions cannot be used
simultaneously.

Espressif $ /$24
4 2018.11

108
2. Pin Definitions
$

Pin Name Type Function

Chip Enable
7 CHIP_EN I High: On, chip works properly
Low: Off, small current consumed

Deep-sleep wakeup (need to be connected to EXT_RSTB);


8 XPD_DCDC I/O
GPIO16

9 MTMS I/O GPIO 14; HSPI_CLK

10 MTDI I/O GPIO 12; HSPI_MISO

11 VDDPST P Digital/IO Power Supply (1.8V ~ 3.6V)

12 MTCK I/O GPIO 13; HSPI_MOSI; UART0_CTS

13 MTDO I/O GPIO 15; HSPI_CS; UART0_RTS

14 GPIO2 I/O UART TX during flash programming; GPIO2

15 GPIO0 I/O GPIO0; SPI_CS2

16 GPIO4 I/O GPIO4

17 VDDPST P Digital/IO Power Supply (1.8V ~ 3.6V)

18 SDIO_DATA_2 I/O Connect to SD_D2 (Series R: 200Ω); SPIHD; HSPIHD; GPIO9

Connect to SD_D3 (Series R: 200Ω); SPIWP; HSPIWP;


19 SDIO_DATA_3 I/O
GPIO10

20 SDIO_CMD I/O Connect to SD_CMD (Series R: 200Ω); SPI_CS0; GPIO11

21 SDIO_CLK I/O Connect to SD_CLK (Series R: 200Ω); SPI_CLK; GPIO6

22 SDIO_DATA_0 I/O Connect to SD_D0 (Series R: 200Ω); SPI_MISO; GPIO7

23 SDIO_DATA_1 I/O Connect to SD_D1 (Series R: 200Ω); SPI_MOSI; GPIO8

24 GPIO5 I/O GPIO5

25 U0RXD I/O UART Rx during flash programming; GPIO3

26 U0TXD I/O UART TX during flash programming; GPIO1; SPI_CS1

Connect to crystal oscillator output, can be used to provide BT


27 XTAL_OUT I/O
clock input

28 XTAL_IN I/O Connect to crystal oscillator input

29 VDDD P Analog Power 2.5V ~ 3.6V

30 VDDA P Analog Power 2.5V ~ 3.6V

Serial connection with a 12 kΩ resistor and connect to the


31 RES12K I
ground

32 EXT_RSTB I External reset signal (Low voltage level: active)

📖 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.

RF Analog MAC Interface


receive receive UART
Registers
RF balun

GPIO
Switch

Digital baseband
I2C
CPU
RF Analog I2S
transmit transmit
SDIO
Sequencers
PWM

ADC
Accelerator
PLL VCO 1/2 PLL
SPI

PMU Crystal Bias circuits SRAM PMU Flash

$
Figure 3-1. Functional Block Diagram

3.1. CPU, Memory, and Flash


3.1.1. CPU
The ESP8266EX integrates a Tensilica L106 32-bit RISC processor, which achieves extra-
low power consumption and reaches a maximum clock speed of 160 MHz. The Real-Time
Operating System (RTOS) and Wi-Fi stack allow 80% of the processing power to be
available for user application programming and development. The CPU includes the
interfaces as below:
• Programmable RAM/ROM interfaces (iBus), which can be connected with memory
controller, and can also be used to visit flash.
• Data RAM interface (dBus), which can connected with memory controller.
• AHB interface which can be used to visit the register.

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

Split core current transformer

Model: SCT-013 Rated input current:5A/100A


Characteristics:Openning size: 13mm*13mm,
RoHS
Non-linerity±3%(10%—120% of rated input current)
1m leading wire, standard Φ3.5 three core plug output.
Current output type and voltage output type (voltage output
type built-in sampling resistor)
Purpose:Used for current measurement, monitor and protection for AC motor,
lighting equipment, air compressor etc
Core material: ferrite
Mechanical strength: the number of switching is not less than 1000 times(test at 25℃)
Safty index:Dielectric strength(between shell and output)1000V AC/1min
Fire resistance property: In accordance with UL94-Vo
Work temperature: -25℃~+70℃
Outline size diagram: (in mm)
32±0.5

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

Front View Side View Schematic diagram


Three-core plug size
35.3
X Y
L Output Vacancy K Output
2.5mm Audio Plug 11.9 2.5 Optional
ΦY standard
3.5mm Audio Plug 15.0 3.5
1m X

Diagram for standard three-core plug


Table of technical parameter:
Model SCT-013-000 SCT-013-005 SCT-013-010 SCT-013-015 SCT-013-020

Input current 0-100A 0-5A 0-10A 0-15A 0-20A

Output type 0-50mA 0-1V 0-1V 0-1V 0-1V

Model SCT-013-025 SCT-013-030 SCT-013-050 SCT-013-060 SCT-013-000V

Input current 0-25A 0-30A 0-50A 0-60A 0-100A

Output type 0-1V 0-1V 0-1V 0-1V 0-1V

※ Output type: voltage output type built-in sampling resistor, current output type built-in protective diode.

Tel: 86-13933609279 Fax: 86-7929499-804 skype:macymeng1


Web (China):www.yhdc.com Web (Latvia):www.yhdc.lv

112

You might also like