Development of Low-Cost Microcontroller-Based Load Shedding Device
Development of Low-Cost Microcontroller-Based Load Shedding Device
SHEDDING DEVICE
July 2019
ACKNOWLEDGEMENT
This thesis becomes a reality with the kind support and help of many individuals.
Foremost, we want to offer this endeavor to our Almighty God for the wisdom he
bestowed upon us, the strength, peace of our mind and good health in order to finish
this research.
We would like to thank our adviser Engr. Albert C. Velasco and our co-adviser
Mr. John Ferdinand G. Osorio for their time, effort, patience and overwhelming
guidance. Without them this study would not have been possible.
Lastly. we express our very profound gratitude to our family and friends for
years of study and through process of researching and writing this thesis. This
accomplishment would not have been possible without them. Thank you.
We dedicate this dissertation to our beloved parents; Alex & Arleen Capiral,
Fernando & Virginia Martinez, and Legaspi & Ma. Evangeline Primero. This is for us.
ABSTRACT
In modern time the demand for electricity is very high, almost anything is
powered by electricity, thus making our life highly dependent on it. Today, world power
management plays a significant role in reducing the power consumption and increasing
the efficient utilization of the available resources. In fact, there are power saving
devices available in the market, some of them may be too expensive, some are
affordable but doesn't guarantee a remarkable result and some requires a professional
applied to large scale factories that maintains a specific load usage. Automatic load
shedding automatically disconnects loads to lessen the power usage and be able to
shedding device that can be used in industrial or commercial purposes. Further, the
device will promote power saving and load shedding. The prototype device can display
the real-time power consumption and is also capable to set the desired consumption
limit for a specific branch circuit. Once the branch circuit power usage is near its power
consumption limit it will automatically cut the electricity flow on that said branch.
LIST OF TABLES
Table 4.1: Loads Used to Test the Monitoring Function of the Device ………………… 34
Table 4.3: Percent Difference Between Actual Power and Measured Power ………… 36
LIST OF FIGURES
Figure 2.4: Difference Between Traditional Meters vs. Smart Meters …………………… 15
Appendix D: Specification Sheet of Current Sensor and Arduino Mega 2560 ………….. 79
ACKNOWLEDGEMENT …………………………………………………………………………………………. ii
CHAPTER 1 : INTRODUCTION
1.1 BACKGROUND OF THE STUDY .........................................................1
1.2 OBJECTIVES OF THE STUDY ............................................................3
1.3 SIGNIFICA NCE OF THE STUDY .......................................................4
1.4 SCOPES AND LIMITATIONS .............................................................5
1.5 CONCEPTUAL FRAMEWORK .............................................................7
1.6 DEFINITION OF TERMS ...................................................................8
CHAPTER 3 : METHODOLOGY
3.1 GATHERING OF DATA ................................................................... 23
3.2 METHODS OF RESEARCH............................................................... 24
3.3 INSTRUMENTATION ...................................................................... 26
3.4 STATISTICAL ANALYSIS ................................................................ 31
BIBLIOGRAPHY ..………………………………………………………………………………………………. 46
APPENDIX A …………………………………………………………………………………………………….. 48
APPENDIX B …………………………………………………………………………………………………….. 77
APPENDIX C …………………………………………………………………………………………………….. 78
APPENDIX D …………………………………………………………………………………………………….. 79
APPENDIX E …………………………………………………………………………………………………….. 92
Chapter 1
INTRODUCTION
To maintain the life of the human community, and to facilitate life, many
important inventions were discovered and made to make life easier. There is no
doubt that the most important of all inventions is electricity. People became
dependent on it over time. People now live in a time where electricity is used
very simple device like a toothbrush. Along with the technological advancement
of the availability of electricity, people neglect the importance of it. People take
it for granted and only see the importance of electricity during power outages,
1
manufacturing, processing, and etcetera of the things that people use in their
everyday life. Industrial plants use machines/ equipment daily, these machines
are not the typical machines that can be seen anywhere, these are big
machines/ equipment that are humongous, state of the art, and powerful. Even
though these machines/ equipment acts as the heart and soul of an industrial
plant its electricity consumption is severe, making industrial plants as the main
Power saving is achievable without the use of power saving devices like
Electricity Energy Power Saving Box and renewable energy devices. It can be
process in which the system balances the electricity supply with the demand.
which are not used or less priority and will maintain only those that are
prioritized and must be maintained most of the time, so that the less significant
loads will be sorted out in way it can be easily unloaded once the power
2
1.2 OBJECTIVES OF THE STUDY
The main goal of this study is to give industrial plants an option to use
Programmable Logic Circuit (PLC) are the commonly used controlling device
today, but Programmable Logic Circuit (PLC) are very expensive, quite hard to
economical.
The main objective of this study is to develop a low- cost microcontroller- based
load;
3
1.3 SIGNIFICANCE OF THE STUDY
monitoring their power consumption, to limit their load and prioritize their
preferred process. The researchers want to develop a device that would help
industrial plants control and manage their energy consumption which would not
only lessen the chance of demand charges but also helps maintain a specific
plants, there would be substantial amount of electricity saving, and would also
lessen the impact on the environment, as this means that there will be lesser
demand for electricity which in turn would also lessen the demand for electricity
consumers but also to residential and commercial consumers also. When power
the situation would be like what happened last 2017 when there was a power
maintenance. The lesser the demand for electricity, the lesser demand also for
4
The consumers would also benefit from this study. Once the industrial
plants were able to achieve their desired power consumption, their electricity
industrial plants will greatly decrease, decrease in operating cost means the
manufacturers can lower the prices of their products which is very beneficial to
the consumers.
This research will be a useful reference for the researchers who would
plan to make any related study precisely the standard underlying the Bachelor
The scope of the study is for prototype making, testing and simulation
only. This research involves the use of microcontrollers which would be used to
monitor the power consumption, and automatic power cut-off. There are three
functions that the researchers want in the device: Load monitoring and
system due to number of reasons, namely: Time constraints, money, and most
importantly, the permission of the owner due to safety concerns. The testing of
the device would be on a small representation only wherein the researchers will
produce a system that would simulate the electrical system of an industrial load.
shedding of loads by limiting the power that can be consumed by each branch
circuit will help the users optimize their electrical usage and prioritize critical
that are important to the operation should be prioritized as shutting them off
6
1.5 CONCEPTUAL FRAMEWORK
INPUT
1. Current reading of branches
2. Setting of limits by the user
3. Concurrence to standards (PEC 2017)
PROCESS
4. Prioritization of the loads
5. The researchers will provide an estimation of demand
loads.
OUTPUT
6. Automatic load-shedding device
7. Active monitoring of the power consumption of each
branch circuit
7
The inputs in this research will be the current drawn by the branch
circuits and the limit that is set by the consumers/users. The device will make
use of current sensor to detect and monitor the current and the data taken by
the sensors will then be feed to the Arduino and calculated to be displayed as
power consumed. The other input would be the limit that is set by the users.
Depending on the current financial standing of the user, he/she can set the
Arduino microcontroller that can automatically turn on/off the loads, monitor
the power consumption, and manage their electrical system. The output of this
system will be a prototype or a device that would satisfy the objective of the
8
Load Shedding- It is a process wherein a load or a circuit is terminated to
Smart Meter- It is a device which measures and record the energy consumption
Load Profiling- It is a graph of the variation in the electrical load versus time.
Load Demand- It is the sum of the operational load and non-operational load.
9
Chapter 2
The name of the device that can detect, measure and display energy
since way back late 19th century and has many types including the electrolytic
meter and the commutator meter which operates differently with each other.
determine the power usage. (Vadda & Seelam, 2013) A Simple electricity meter
is shown below.
10
Limitations of a traditional electricity meters are the following:
time, the disc will slow down a few percentage making the reading
slightly inaccurate.
11
2.2 SMART METERING
According to Gandhi and Bansal (2013), that people today does not
really care about their own consumption of electricity in their everyday living
and will only bothered when they received their electricity bill or in case of
power. As time goes by, technological advancement was consistent, along with
which is now called Smart meters. Smart Metering System consists of three
Meter Data Management. Smart metering has many advantages especially for
the consumers. Smart metering system provides an efficient way for the
consumers to access all their transaction history and pay on time. Smart
metering also reduces the risk of tampering with the meter and gives a security
12
Figure 2.2 This is an example image of a smart meter
Source: https://www.smart-energy.com/magazine-article/global-trends-in-smart-metering/
13
From “Smart Metering for Intelligent Buildings” by Zivic et al. (2016),
service providers obtain instant and accumulative data on the consumers with
the help of smart metering, at the same time the consumers are also able to
energy consumptions and etcetera. Smart meters provide both real-time and
anomalies, sorting out which energy wasting equipment can be laid off, and can
help in improving the consumption efficiency of the consumer. It does not only
help the end consumer to identify and remedy the sources of high energy
consumption but also helps the provider to determine the times of peak energy
replacing the traditional electricity meters with a digital meter also called the
smart meter which measures and records the power consumption hourly.
14
In traditional electricity meters, the reading is done manually by
inspectors, the consumers would have to wait for their monthly electric bill to
know their usage, no power outage detection, and the connections and
disconnections must also be done manually. However, for smart meters, meter
provided near real time, and connections and disconnections are faster as they
can be managed remotely. Smart meters are also more accurate than
traditional meters, has more features and also provides security as smart
meters are harder to be manipulated rather than the traditional meters which
still uses a disc. Although smart meters have many advantages and benefits, it
still has some disadvantages such as, smart meters have shorter life expectancy
of just less than 10 years compared to the traditional meters which can last 30
unemployment to thousands.
15
2.4 LOAD SHEDDING
According to Syadli et al. (2016), load shedding is done as the last resort
shedding is done when there is not enough electricity to supply the demand of
the consumers. When power supply cannot meet the demand, it could cause an
unbalance in the power system resulting to a blackout and that could take a
large period of time to recover and to be repaired. When power is not enough,
the first step the utility company takes is to ask large consumers (industrial &
system, load shedding can be also applied into a small-scale system such as
residential buildings so that energy consumption and electric bills will go lower.
In that process, some of the appliances used might turn off temporarily for the
According to Syadli et al. (2016), there are 2 widely used methods for
load shedding schedule. That is the ‘Shortest Job First’ or SJF and the Round
Robin Scheduling or RR. For the SJF, each process is determined based on their
16
‘importance’, the least priority process will then be cut-off until the power
system can supply the demand again. Meanwhile in RR, each process will be
home which is connected to smart power meter that signals to turn off or on
appliances optimally or automatically. Smart plugs are the one that applies the
controlling the electrical appliances with the help of appropriate sensors and
actuators can help improve load shedding. Some of the best strategies that can
appliances/ loads, setting the desirable start and end time of certain device,
17
2.5 LOAD MONITORING
monitoring. Understanding first the electrical loads and knowing the energy
According to Berges et al. (2011), last 2008, 40% of the total energy
compared to the service providers monthly reports, this gives the consumer
real-time energy feedback on their current consumption, which can help them
18
information, so that the user can point out which specific appliances consumes
the most energy. Load monitoring can be categorized into two. Intrusive load
not all loads have the same characteristic in drawing current. NILM provides
high level of detail and yet it costs less than the hardware-based submetering.
Figure 2.5 Block diagram illustrating the different steps involved in basic NILM implementation
Source: https://ascelibrary.org/doi/10.1061/%28ASCE%29CP.1943-5487.0000108
19
Based on the study made by Devlin and Hayes (2018), Non-Intrusive
big role in a smart grid. Demand side load management enables the users to
determine their energy consumption during peak and off-peak hours, it does
not only give a much more reliable system with an improvement on efficiency,
but also has a low emission of CO2 in smart grids. Because of Information and
communication technology (ICT), grids today are more advanced and efficient.
With the availability of new sensor and the ability to communicate real time
power, monitoring and controlling grids today are much more reliable and
productive.
load consumption every hour for 24 hrs. Rescheduling of loads, is the process
by shifting the schedule of large electric loads into different scheduled time to
20
chart and a process chart will give the user a more accurate schedule on when
to operate the equipment that ensures an improved load factor which reduces
using electricity during off peak periods. Off peak hour promotes energy saving
For load limiting, a limiter device is used to restrict the flow of electricity
but will still allow a minimal amount of power to pass through the meter in
setting a limit on how much power can the consumer consume, they can assure
that their power consumption would not exceed past the limit set. The power
will stay on as long as the consumer stays within their set limit (e.g. only 350-
watt hours in a 15-minute period) but when they do exceed the limit, the
21
There are 4 types of power limiters available
A real-time clock (RTC) is a digital clock and calendar that uses minimal
companies such as MERALCO and Maynilad charges the bill at the end of the
month. Based on a study of Morad et al. (2018). If the time reaches to the set
time, the count will reset to zero and start count back the pulse. Which means
that with the help of RTC, the smart meter should reset the metering and
should be able to notify the users total amount of energy consumed for the
22
Chapter 3
METHODOLOGY
The researchers will make use of the following equipment to gather data
2. Arduino
- The Arduino will be responsible for all the data gathering. All
the data that will be gathered such as the limits set by the
such as power.
23
3.2 METHODS OF RESEARCH
industrial building, this step is done to determine the components used in the
device whether it can handle the load/s that will be used. Due to the
household appliances.
The next step would be choosing the appropriate components that will
Knowing that the researchers would not be able to find a residential house that
turn on and off the supply for every branch circuits, and a device that can
monitor the total power consumption of each branch circuits. The device will
make use of an Arduino MEGA, RTC module, Relay, and Current Sensor to
achieve the desired functions. The Arduino is responsible for the process that
will be done to shed load, manage load, and/or limit load, the RTC module is
24
used to keep track of the time and relay to act as a switch which will cut off the
Once the design is finalized and the proper components were chosen,
the researchers will create a code for the Arduino Mega 2650 for it to operate
After coding the device, the researchers will now calibrate the current
sensor for it to accurately read the current consumption of each branch circuit.
accurate reading and at the same time the device will be able to shed the
Assembly would be the last part of creating the project before the
testing. In this part the researchers will now combine all the components to
build the system; everything will be placed in a casing that has contactors,
electrical system.
The last part would be the testing of the prototype. The researchers will
now test the chosen load/s. The researchers will conduct 3 tests on the two
25
single-phase branch circuits, and 2 tests on the three-phase branch circuit. The
circuit and will check if the system will automatically shut of the electricity on
that said branch circuit. The researchers will record the power consumption,
time, and whether the device successfully lay-off the branch circuit.
3.3 INSTRUMENTATION
current being drawn by the branch circuits. The current sensor will detect the
26
current passing through the wires and will generate a signal based on the
current detected.
device. It will serve as the brain of the device, because it is the one responsible
27
Figure 3.3 Arduino Compatible 5V Relay Board
Source: https://www.jaycar.com.au/arduino-compatible-5v-relay-board/p/XC4419
Relay will be used as the main switching device of the prototype. Relay is
the one that will trigger the electricity on the branch circuit, it is also the one
28
Figure 3.4 Digital Multimeter
Source: https://www.fluke.com/en-ph/product/electrical-testing/digital-multimeters/fluke-87v
29
Figure 3.5 Clamp Meter
Source:
https://www.indiamart.com/proddetail/fluke-302-plus-digital-clamp-meter-9049752297.html
The clamp meter will be the major instrument used in this study so that
the researchers will have a much more accurate measurement on the current of
30
BRANCH TEST # LOAD/S LIMIT TIME LOAD SHED
CIRCUIT
(YES/NO)
1 Y
BRANCH 1 2 Y
SINGLE-
PHASE 3 Y
BRANCH 2 1 Y
THREE-
PHASE
2 Y
1 Y
BRANCH 3 2 Y
SINGLE- 3 Y
PHASE
This table will be used to record all the results of each test that will be
conducted. This table gives the researchers the reliability and the accuracy of
the device.
In this research, the data taken from the measurements are analyzed
and compiled in a table. The researchers will use quantitative research method
to determine if the device works as it is supposed to. The data gathered will be
31
tabulated and analyzed once all the testing has been conducted. The device will
be connected between the load and the circuit breakers to monitor the
individually. The researchers will make use of 3 branch circuits for testing
purpose of the device and will use a combination of resistive loads such as
lamps and inductive loads such as motors for the tests. The researchers will
purposely reach the assigned consumption limit that is set in order to test the
function of the device, the results will be monitored and stored. All in all, 5 tests
for each branch circuit will be conducted on the device so that the researchers
The device will display the power consumption, since the device will only
measure the current, the researchers will set the voltage at fixed 230 volts.
With this, the researchers will use Dependent Variable, the current and the
voltage will be the independent variable, while the power will be the dependent
dependent variable.
32
Chapter 4
This chapter presents and analyzes the data gathered by the researchers
1. Flat iron
2. Hair dryers
3. Laptop charger
33
4. Three-phase induction motor
Table 4.1 Loads used to test the monitoring function of the device
The loads used in the testing process are loads typically used not just in a
induction motor is also used in order to mimic the load on an industrial building.
The current measured using the device is not a 100% accurate but the margin
of error is ±0-10%.
34
PHASE) 3 Laptop 5 Wh 379 secs Y
Charger
the testing as close as possible to real life situations. As seen on the table
above, different loads are connected to each branch circuit and they are
branch circuit and turn it off once the assigned limit is reached.
35
Branch no. Test no. Actual Measured Percent
Table 4.3 Percent Difference between Actual Power and Measured Power
This table shows the difference between actual power and measured power.
The measured power came from the reading consumption of the device.
36
Chapter 5
The current sensor is connected in series with the relay / contactor in order to
simultaneously measure the current of the branch circuit while turning off / on
37
the circuit. The current sensors are connected on pins A11, A12, and A13 of the
Arduino MEGA as input. The relays are connected on pins 41, 42, and 43 of the
Arduino MEGA as output. The 4x4 keypad is connected in a matrix and has 4
column pins and 4 row pins which are connected to pins 22, 24, 26, and 28,
and pins 30, 32, 34, and 36 for column and row pins respectively. The LCD and
RTC module both use I2C (Inter-integrated circuit) and are connected to SDA
The device will make use of Arduino MEGA as its microprocessor; the
Arduino MEGA will be the “brain” of the device as it is the one responsible for
There will be a total of 3 branch circuits that will be used in the testing
process. In between each branch circuits and load, a current sensor and relay
38
will be connected. The current sensor will monitor and measure the current
flowing on the branch circuit and the data taken will then be transmitted into
the Arduino and will be processed accordingly. The relay is also connected in
order to satisfy the function load shedding, the relay will be responsible for the
this operation as it fits all the needed characteristics. Based on the device’s
39
features, the researchers determined the needed components which are the
following:
10. Contactor will act as a switch for the 3-phase branch circuit
The next step would be the encoding of the commands necessary for the
function of the device into the Arduino. The codes will dictate the actions that
The device will be able to measure the current, the researchers set the
voltage specifically at 230 volts. Power can be computed with this formula
P=VRMS*IRMS*pf, voltage will be fixed at 230 volts, power factor will be set to
0.8 and the current is the one that will be measured by the device.
Sample computation:
𝑃 = 𝑉 × 𝐼 × 𝑝𝑓
40
𝑃 = 230 𝑣𝑜𝑙𝑡𝑠 × 35 𝑎𝑚𝑝𝑒𝑟𝑒 × 0.8 = 6,440 𝑤𝑎𝑡𝑡𝑠
The last step would be to test the functionality of the device in a small-
The loads used during the testing procedures are flat iron, hair dryers, laptop
that will be used are RTC Module, Relay, Current sensor, Keypad, and LCD
41
After planning, laying out and designing the circuit, the components will
be installed and soldered in its designated location. Upon the installation of the
components, wiring will be done to connect the components. Once all the
electronic components are done and fully operational, the researcher will design
researchers will ensure that all the components will fit perfectly in a casing to
42
wattmeter. All of the equipment, prototype, protective devices, and receptacle
outlets will be placed in a wooden sheet. There will be three receptacles that
will represent each branch circuit, two will be in single-phase outlet and the
43
Chapter 6
6.1 Conclusion
load shedding device that can be used in industrial application. The researchers
were able to create a load shedding device using Arduino Mega 2560. The
device can cut the electricity consumption of a specific branch circuit once it
reaches its assigned value. The researchers were also able to create a load
shedding device that is less expensive compared to PLC’s, thus, satisfying the
6.2 Recommendation
meaning that if the device developed by the researchers will be used on proper
buildings, the relay and the current sensor must be replaced with the same
components but with different capacity as the relay used in the device can only
handle up to 30 Amperes while the current sensors can only handle 5 amperes
44
for the branches 1 and 3, while 30 amperes for branch 2. Future researchers
can also include a backup power supply for the prototype in case of unexpected
power outage. Future researchers can improve the device by eliminating the
wishes to adjust his/ her energy consumption, another person could fill-in
his/her position.
A SMS system should be added so that the owner can remotely adjust
45
BIBLIOGRAPHY
energy load profile for domestic buildings in the UK. Energy and
Overview. 46.
10.11591/ijece.v7i6.pp3235-3245.
4. Syadli, Husna & Abdullah, Md Pauzi & Faridiansyah, Iqbal & Hassan,
78. 10.11113/jt.v78.8714.
5. Gandhi, Karan & Bansal, Hari. (2013). Smart Metering in electric power
10.1109/CARE.2013.6733756.
46
6. Montana, Johny & Candelo-Becerra, John & Racines, Diana. (2018). Non-
1321-1329. 10.17559/TV-20170317203817.
9. Zunnurain, Izaz & Maruf, Md. Nasimul Islam & Rahman, Md Moktadir &
10.3390/infrastructures3040050.
“Https://Www.electricitylocal.com/States/California/Pico-Rivera/.” CA
www.electricitylocal.com/states/california/pico-rivera/.
47
APPENDIX A
#define relayOne 41
#define relayTwo 42
#define relayThree 43
#include <DS3231.h>
#include <SPI.h>
#include <SD.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
int lastState1;
int lastState2;
int lastState3;
48
unsigned long previousTime = 0;
double lastSample = 0;
double sampleSum = 0;
int sampleCount = 0;
int pos = 0;
float oneAmps = 0;
float oneVA = 0;
float oneVAEnter = 0;
float twoAmps = 0;
float twoVA = 0;
float twoVAEnter = 0;
49
float threeAmps = 0;
float threeVA = 0;
float threeVAEnter = 0;
int ave1 = 0;
int ave2 = 0;
int ave3 = 0;
char keys[ROWS][COLS] = {
};
50
byte rowPins[ROWS] = {36, 34, 32, 30};
char key;
File thesis;
);
void setup() {
Serial.begin(9600);
SD.begin(4);
rtc.begin();
pinMode(One, INPUT);
pinMode(Two, INPUT);
pinMode(Three, INPUT);
pinMode(relayOne, OUTPUT);
pinMode(relayTwo, OUTPUT);
51
pinMode(relayThree, OUTPUT);
pinMode(A10, INPUT);
pinMode(A14, INPUT);
lcd.init();
lcd.backlight();
//importdata();
void loop() {
+ String(analogRead(A13)));
displayrtc();
base();
unitOne();
keyInterrupt();
base();
VoltAmpHour();
keyInterrupt();
base();
displayUnitOne();
keyInterrupt();
52
base();
VoltAmpHour();
keyInterrupt();
base();
unitTwo();
keyInterrupt();
base();
VoltAmpHour();
keyInterrupt();
base();
displayUnitTwo();
keyInterrupt();
base();
VoltAmpHour();
keyInterrupt();
base();
unitThree();
keyInterrupt();
base();
VoltAmpHour();
keyInterrupt();
53
base();
displayUnitThree();
keyInterrupt();
base();
VoltAmpHour();
keyInterrupt();
base();
//exportdata();
void unitOne() {
sampleCount = 0;
sampleSum = 0;
lastSample = 0;
/*if (ave1>=517){
ave1=523;
}*/
do {
sampleCount++;
54
lastSample = millis();
keyInterrupt();
oneAmps = 0;
oneVA = 0;
sampleSum = 0;
sampleCount = 0;
void unitTwo() {
sampleCount = 0;
sampleSum = 0;
lastSample = 0;
55
/*if (ave2>=517){
ave2=523;
}*/
do {
sampleCount++;
lastSample = millis();
keyInterrupt();
twoAmps = 0;
twoVA = 0;
sampleSum = 0;
56
sampleCount = 0;
void unitThree() {
sampleCount = 0;
sampleSum = 0;
lastSample = 0;
/*if (ave3>=517){
ave3=523;
}*/
do {
sampleCount++;
lastSample = millis();
keyInterrupt();
57
threeAmps = 0;
threeVA = 0;
sampleSum = 0;
sampleCount = 0;
void VoltAmpHour() {
currentTime = millis();
if (tBetMeasurements >= 0) {
oneVAhLeft -= oneVAh;
if (oneVAhLeft <= 0) {
digitalWrite(relayOne, 0);
digitalWrite(12, 1);
lastState1 = 0;
58
oneVAhLeft = 0.00;
oneVAhLeft = 0.00;
twoVAhLeft -= twoVAh;
if (twoVAhLeft <= 0) {
digitalWrite(relayTwo, 0);
lastState2 = 0;
twoVAhLeft = 0.00;
twoVAhLeft = 0.00;
threeVAhLeft -= threeVAh;
if (threeVAhLeft <= 0) {
digitalWrite(relayThree, 0);
59
lastState3 = 0;
threeVAhLeft = 0.00;
threeVAhLeft = 0.00;
previousTime = millis();
void keyInterrupt() {
num = 0;
key = keypad.getKey();
if (key == '*') {
menu1:
lcd.clear();
menu1();
key = keypad.getKey();
switch (key) {
60
case NO_KEY:
break;
case '1':
lcd.clear();
menu2:
menu2();
key = keypad.getKey();
switch (key) {
case '1':
lcd.clear();
menu3();
GetNumber();
oneVAEnter = num;
oneVAhLeft = oneVAEnter;
base();
digitalWrite(relayOne, 1);
base();
digitalWrite(12, 0);
lastState1 = 1;
goto disp;
61
break;
case '2':
lcd.clear();
menu3();
GetNumber();
twoVAEnter = num;
twoVAhLeft = twoVAEnter;
base();
digitalWrite(relayTwo, 1);
base();
lastState2 = 1;
goto disp;
break;
case '3':
lcd.clear();
menu3();
GetNumber();
threeVAEnter = num;
threeVAhLeft = threeVAEnter;
base();
digitalWrite(relayThree, 1);
62
base();
lastState3 = 1;
goto disp;
break;
key = keypad.getKey();
goto menu1;
break;
case '2':
lcd.clear();
menu2();
key = keypad.getKey();
switch (key) {
case '1':
lcd.clear();
menu3();
GetNumber();
oneVAEnter += num;
oneVAhLeft += num;
63
base();
digitalWrite(relayOne, 1);
base();
digitalWrite(12, 0);
lastState1 = 1;
goto disp;
break;
case '2':
lcd.clear();
menu3();
GetNumber();
twoVAEnter += num;
twoVAhLeft += num;
base();
digitalWrite(relayTwo, 1);
base();
lastState2 = 1;
goto disp;
break;
case '3':
lcd.clear();
64
menu3();
GetNumber();
threeVAEnter += num;
threeVAhLeft += num;
base();
digitalWrite(relayThree, 1);
base();
lastState3 = 1;
goto disp;
break;
key = keypad.getKey();
goto menu1;
break;
key = keypad.getKey();
lcd.clear();
lcd.clear();
65
}
key = keypad.getKey();
disp:
int a = 0;
void displayUnitOne() {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("UNIT 1 REMAINING");
lcd.setCursor(0, 1);
lcd.setCursor(1, 2);
lcd.setCursor(2, 3);
void displayUnitTwo() {
lcd.clear();
lcd.setCursor(2, 0);
66
lcd.print("UNIT 2 REMAINING");
lcd.setCursor(0, 1);
lcd.setCursor(1, 2);
lcd.setCursor(2, 3);
void displayUnitThree() {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("UNIT 3 REMAINING");
lcd.setCursor(0, 1);
lcd.setCursor(1, 2);
lcd.setCursor(2, 3);
67
void menu1() {
lcd.setCursor(8, 0);
lcd.print("MENU");
lcd.setCursor(2 , 1);
lcd.setCursor(4, 2);
lcd.setCursor(4, 3);
void menu2() {
lcd.setCursor(2 , 0);
lcd.setCursor(4, 1);
lcd.setCursor(4, 2);
lcd.setCursor(4, 3);
68
void menu3() {
lcd.setCursor(5 , 0);
lcd.print("HOW MUCH?");
lcd.setCursor(0, 1);
lcd.print(" Wh");
lcd.setCursor(0 , 2);
lcd.print("A - ACCEPT");
lcd.setCursor(0 , 3);
lcd.print("C - CLEAR");
lcd.setCursor(0, 1);
key = keypad.getKey();
switch (key) {
case NO_KEY:
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
69
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
Serial.println(num);
break;
case 'C':
num = 0;
lcd.setCursor(0, 1);
lcd.print(" ");
break;
key = keypad.getKey();
/*void exportdata() {
SD.remove("lastLimit1.txt");
SD.remove("lastLimit2.txt");
SD.remove("lastLimit3.txt");
70
SD.remove("lastLeft1.txt");
SD.remove("lastLeft2.txt");
SD.remove("lastLeft3.txt");
SD.remove("lastState1.txt");
SD.remove("lastState2.txt");
SD.remove("lastState3.txt");
if (thesis) {
thesis.println(oneVAEnter);
thesis.close();
if (thesis) {
thesis.println(twoVAEnter);
thesis.close();
if (thesis) {
thesis.println(threeVAEnter);
thesis.close();
71
thesis = SD.open("lastLeft1.txt", FILE_WRITE);
if (thesis) {
thesis.println(oneVAhLeft);
thesis.close();
if (thesis) {
thesis.println(twoVAhLeft);
thesis.close();
if (thesis) {
thesis.println(threeVAhLeft);
thesis.close();
if (thesis) {
if (lastState1 == 1) {
thesis.println("1");
else if (lastState1 == 0) {
72
thesis.println("0");
thesis.close();
if (thesis) {
if (lastState2 == 1) {
thesis.println("1");
else if (lastState2 == 0) {
thesis.println("0");
thesis.close();
if (thesis) {
if (lastState3 == 1) {
thesis.println("1");
else if (lastState3 == 0) {
thesis.println("0");
73
}
thesis.close();
void importdata() {
String()
thesis = SD.open("lastLimit1.txt");
if (thesis) {
while (thesis.available()) {
oneVAEnter = (thesis.read()).toInt;
myFile.close();
}*/
void displayrtc() {
delay(2000);
lcd.clear();
74
lcd.setCursor(0, 1);
lcd.setCursor(0, 2);
void base(){
int asd = 0;
long mean1 = 0;
long mean2 = 0;
long mean3 = 0;
ave1=0;
ave2=0;
ave3=0;
do {
asd++;
75
ave1 = mean1 / asd;
/*if (ave1>=540){
ave1=512;
if (ave2>=525){
ave2=512;
if (ave3>=540){
ave3=512;
}*/
Serial.println(asd);
76
APPENDIX B
USER MANUAL
77
APPENDIX C
BUDGET ALLOCATION
Material (Php)
78
APPENDIX D