Professional Documents
Culture Documents
ELECTRONIC ENGINEERING
Submitted By
Md Ruhul Quader 008-34-32
Khaled Ashraf Nayan 008-34-57
Supervisor
Fahmida Sharmin Jui
Assistant Professor
Department of Electrical & Electronic Engineering
Southern University Bangladesh
Submitted To:
DEPARTMENT OF
ELECTRICAL & ELECTRONIC ENGINEERING
SOUTHERN UNIVERSITY BANGLADESH
Spring-2023
SMART UTILITY LOAD MANAGEMENT AND FAULT
DETECTION
Submitted by
Md Ruhul Quader 008-34-32
Khaled Ashraf Nayan 008-34-57
Supervisor:
This project report is submitted to the Department of Electrical & Electronic Engineering, Southern University
Bangladesh, in partial fulfillment of the requirement for the degree of Bachelor of Science in Electrical and
Electronic Engineering.
DEPARTMENT OF
ELECTRICAL & ELECTRONIC ENGINEERING
SOUTHERN UNIVERSITY BANGLADESH
Spring-2023
ii
SMART UTILITY LOAD MANAGEMENT AND FAULT
DETECTION
Submitted by
Md Ruhul Quader 008-34-32
Khaled Ashraf Nayan 008-34-57
This Project is submitted to the Department of Electrical & Electronic Engineering, Southern University
Bangladesh in partial fulfillment of the requirement for the degree of Bachelor of Science in Electrical and
Electronic Engineering.
Approved By
______________________
__________________
Professor Mohammad Abdul Alim External
Professor
University of Chattogram
iii
ACKNOWLEDGEMENT
We are thankful to almighty, for giving His blessings and mercy to work hard for completing this
project. We would like to express our sense of gratitude and indebtedness to our respected project
supervisor Fahmida Sharmin Jui, Professor, Department of Electronics and Communication
Engineering for her valuable guidance, generous advice, endless encouragement and unfilled
enthusiasm given throughout the research and preparation of the entire project. We are thankful to our
honorable head of the department Dr. Hadaate Ullah and all teachers of the department of Department
of Electrical & Electronic Engineering, Southern University Bangladesh for their cordial help and
support. We are also indebted to all those who made constructive criticism, as well as those who shared
their thoughts and we are also heartily thankful to our classmates and senior brothers for their helpful
suggestions throughout the project. We like to convey our deepest gratitude to our parents for their
unconditional love and indulgence at the moment of triumph turmoil
iv
Table Of Contents
ACKNOWLEDGEMENT.................................................................................................................. iv
Table Of Contents.............................................................................................................................v
ABSTRACT.....................................................................................................................................vii
CHAPTER 01.........................................................................................................................................1
INTRODUCTION & OBJECTIVES...................................................................................................1
1.1 Introduction...........................................................................................................................1
1.2 Motivation............................................................................................................................. 1
1.3 Project Objectives................................................................................................................ 2
CHAPTER 02.........................................................................................................................................3
LITERATURE REVIEW.................................................................................................................... 3
2.1 Historical Background.......................................................................................................... 3
2.2 Recent Plans........................................................................................................................ 5
2.3 Related Research History.................................................................................................... 6
2.4 Load Adjustment/Load Balancing........................................................................................ 8
2.5 Peak Curtailment/leveling and Time of Use Pricing............................................................. 9
CHAPTER 03.......................................................................................................................................10
EXPERIMENTAL SETUP...............................................................................................................10
3.1 Block Diagram.................................................................................................................... 10
3.2 Working Procedure of Block Diagram................................................................................ 10
3.3 System Flow Chart............................................................................................................. 11
3.4 Circuit Diagram...................................................................................................................12
3.5 Circuit Description.............................................................................................................. 12
3.6 Arduino Nano..................................................................................................................... 13
3.7 Current Sensor................................................................................................................... 13
3.8 Wi-Fi Module (ESP8266)....................................................................................................13
3.9 Liquid-Crystal Display.........................................................................................................14
3.10 Relay Switch Circuit......................................................................................................... 14
3.10.1 NPN Relay Switch Circuit........................................................................................15
CHAPTER 04.......................................................................................................................................17
RESULT ANALYSIS....................................................................................................................... 17
4.1 Result................................................................................................................................. 17
4.2 Controlling & Monitoring Section IoT Result with Hardware.............................................. 18
4.3 Discussion.......................................................................................................................... 19
4.4 Application..........................................................................................................................19
4.5 Advantages........................................................................................................................ 20
4.6 Cost Analysis......................................................................................................................20
CONCLUSION............................................................................................................................... 21
FUTURE WORK............................................................................................................................ 22
REFERENCE................................................................................................................................. 23
APPENDIX..................................................................................................................................... 25
v
LIST OF FIGURES
Figure No Figure Name Page Number
v
LIST OF TABLES
Table No Table Name Page Number
vi
ABSTRACT
Load management we can handle the output loads and save the energy. Load management, also known
as demand side management, is the process of balancing the supply of electricity on the network with
the electrical load by adjusting or controlling the load rather than the power station output. This can be
achieved but direct intervention of the utility in real time, by the use of sensitive relay triggering the
circuit breakers, by time clock or by using special tariffs to influence consumer behavior. Load
management allows utilities to reduce demand of electricity during peak usage times, which can, in
turn reduce costs by eliminating the need for peaking power plants. This paper also proposes a
low-cost small hydropower plant that can benefit communities in rural areas which are endowed with
small hydropower resources. Consumer wants to reduce the electricity bills so we use this type of
power generation.
vii
CHAPTER 01
INTRODUCTION & OBJECTIVES
1.1 Introduction
The project is an automatic load operation system that controls load operation, multiple numbers of
times according to programmed instruction. The project eliminates the manual ON/OFF switching of
load. This project is required for load shedding time management which is used when the electricity
demand exceeds the supply and there comes a need for manually switching ON/OFF the electrical
devices in time. Hence this system eliminates the manual operation by automatically switching the
load ON/OFF. A matrix keypad is interfaced with the microcontroller from where the specified time is
input to the microcontroller. When this input time equals the real time, based on the commands the
microcontroller initiates that particular relay to switch ON/OFF the load. The time is displayed on a
LCD display. [1]
Load shedding is the thing that electric utilities do when there is a huge demand interest for power that
surpasses the supply. In this way in a distribution framework, it should decisively control the for the
particular timeframe. Programmable load shedding time administration framework is a dependable
circuit that assumes control over the manual undertaking of switch ON/OFF the electrical gadgets
concerning time. While the set time equivalents to the constant, at that point microcontroller, offers the
charge to the comparing transfer to turn ON the heap and afterward another order to turn OFF
according to the program. Numerous ON/OFF time passage is the greatest favorable position with this
project. A grid keypad helps to enter the time. A LCD show is interfaced to the microcontroller to
show time.
1.2 Motivation
Bangladesh has energy crisis but load shedding has a huge potential on the contrary. Our system may be
a possible solution for meeting the increasing demand of electricity. Asit can automatically detect,
calculate and distribute electricity as per load requirements & reduces the system loss at the same time.
➢ Power Saving Using Time Operated Electrical Appliance Controlling System is a reliable circuit
that takes over the manual task of switch on/off the electrical devices with respect to time.
➢ When this time equals to the programmed ‘ON’ time, then the corresponding Relay for the device is
switched ON and then OFF as per the ‘OFF’ time that finally switches the load ON or OFF.
➢ Multiple ON/OFF times entry is the biggest advantage with this project. ➢ Matrix keypad helps
entering the time while relays used with relay drivers for the loads. ➢ The complete circuit has its
on-board power supply.
1
1.3 Project Objectives
➢ To control load in distribution line by using this system.
➢ To develop a fully automated IoT based smart load management. Also monitor and controlled for
remote area only by the authorized personal at a very low cost.
➢ To address the zone fault detection through our purpose system.
2
CHAPTER 02
LITERATURE REVIEW
3
Generation report of BPDP
Chattagram Zone
Karnaphuli Hydro PP
1 Unit-1,2,3,4,5 230.00 230.00 46.00 46.00
Teknaf 20 MW PP
6 Solartech 20.00 20.00 19.00 0.00
Patenga 50 MW
7 PP(Baraka) 50.00 50.00 6.00 6.00
b) Shikalbaha Peaking
9 (GT) 150.00 150.00 0.00 0.00
Shikalbaha 225 MW
10 CCPP 225.00 225.00 204.00 204.00
Anwara 300 MW PP
11 (United) 300.00 300.00 85.00 100.00
Juldah 100 MW PP
12 Unit-3(Acorn) 100.00 100.00 25.00 25.00
Hathazari 100 MW
14 Peaking pp 98.00 98.00 24.00 25.00
Barabkunda 22 MW PP
15 (Regent) 22.00 22.00 18.00 18.00
Malancha, Ctg.EPZ
16 (United) 0.00 0.00 0.00 17.00
4
Installed Derated Actual Peak Actual Peak
SL No. Name of Power Station
Capacity Capacity Day Evening
Chittagong 108 MW PP
17 ECPV 108.00 108.00 0.00 0.00
Sikalbaha 54 MW
Power Plant (Jodiac
18 Power) 54.00 54.00 17.00 0.00
Chattogram 116MW PP
22 (Anlima Energy Ltd.) 116.00 116.00 0.00 17.00
Chattogram 2*612MW
Coal Based PP (SS
24 Power Unit-1) 1224.00 1224.00 300.00 410.00
Matarbari 2*600MW
25 (CPGCL) 0.00 0.00 568.00 589.00
The Ministry of Power and Energy has been mobilizing Tk 40,000 crore ($5.88 billion) to generate
5,000 MW of electricity to reduce load shedding to a tolerable level within the next four and half years
during the term of the present government. Under the plan, the Power Development Board (PDB) had
produced 500 MW gas-fired electricity between July and December, 2009 to overcome load shedding
5
within December. The PDB had hired furnace-oil based 1,000MW of electricity from the private sector
from January to June 2010. In 2011, the government would install
furnace-oil based 800 MW capacity of power plant. The PDB officials would seek suitable places to
establish the plant, a senior official of the PDB said. Besides, the government would also hire another
diesel or furnace oil based power plant having capacity of 700 MW in 2012 to keep load shedding to a
mild level, the official said. However, the government also contemplates to establish four coal
fired based power plants with capacity of producing 500 MW of electricity each with public and
private partnership (PPP) in Rajshahi and Chittagong region. The government has initially tried to
create a fund of Tk 6,000 crore to implement the plan, sources said. The power division has tried to
utilize the government's budgetary allocation of Tk. 2000 crore for PPP in this regard, sources added.
"If we can create the fund of Tk. 6,000 crore, it would be possible also to mobilize Tk 40,000 crore
under PPP to produce 5,000 MW of electricity within four and half years," PDB chairman ASM
Alamgir Kabir told the New Nation on June 29, 2010. During the meeting, Prime Minister Sheikh
Hasina permitted the power division to implement the PDB plan to reduce load shedding up to a
tolerable level. [5]
Bangladesh plans to set up the 1,000 MW power plant at Rooppur, 200 km (125 miles) northwest of
the capital Dhaka, by 2011.
7
etc.) of electric supply. Usually, the sub-stations are monitored and controlled manually, or by using expensive
PLCs and SCADA system which required more manpower and involved a higher maintenance cost. Under the
conventional protection of substation especially in differential protection, the relay often requires pilot wires to
operate itself which involves a greater capital cost in addition with a sudden interruption of relay operation. To
mitigate the mentioned disadvantages, IoT based substation monitoring and controlling offers a promising
solution with a fully automated system ensuring a greater level of reliability, and thereby increasing the system
performance with the efficient use of the equipment.
“Internet of Things” in short form IoT is created from the word “Internet” and “Things” where “Things” refers
to any internet connected device. The Internet of Things (IoT) is a system of interrelated computing devices,
mechanical and digital machines, objects, animals or people that are provided with a unique identifier and the
ability to transfer data over a network without requiring human-to-human or human-to-computer interaction. In
recent years, the IoT is augmented with sensors and actuators, the technology becoming an instance of the more
general class of cyber-physical-systems, which also encompasses technologies such as smart grids, virtual power
plants, smart homes, intelligent transportation, and smart cities. Because of low-cost, networkable
micro-controller modules, the Internet of Things is considered as the key technology to establish a smart
substation. However, IoT itself has still not reached maturity and many IoT communication protocols such as
CoAP MQTT, XMPP have been proposed as IoT standards. These protocols vary in characteristics with
different strengths and limitations. Finally, due to the technological revolution all over the world, smart
technologies are replacing the old ones. In the power sector, IoT technology is becoming more attractive
nowadays. It is expected that within 2020, around 20–50 billion things would be connected to the internet
throughout the world. [8]
The main aim of this work is to develop a fully automated IoT based substation by which associated equipment
can be protected, monitored and controlled from any place in the world only by the authorized personnel at a
very low cost. Reliability and reduction of manpower using IoT technology are also the prime concerns while
developing smart substation framework.
The rest of the paper is organized as follows. A thorough review of related studies is discussed in Section 2.
Section 3 illustrates the system model highlighting the major parts of the system. Section 4 represents the
experimental setup along with the practical circuit diagram. Section 5 includes the results and discussion.
Finally, Section 6 concludes this paper.
9
CHAPTER 03
EXPERIMENTAL SETUP
3.1 Block Diagram
Flow Chart
11
3.4 Circuit Diagram
No voltage fault
0V is a point in the circuit that you assign as your zero volt potential and it is usually referred to as
15
“common ground”. 0 ground is a 0V point literally connected to an external grounding facility.
Low Voltage Fault
One common cause of low voltage system faults is faulty or damaged wiring. Inspect the wiring and
connections in the affected area or device for any signs of wear and tear. Look for loose connections,
exposed wires, or damaged insulation
Banked transformers are tied together through secondary mains and are supplied by the same primary
feeder. Banked transformers help to reduce lamp flicker, decrease the capacity required, produce better
average voltage along the secondary lines, and have greater flexibility for load growth.
16
CHAPTER 04
RESULT ANALYSIS
4.1 Result
Table 6.1: Load calculation
SL No Load 01 Load 02 Load 03 Load 04 Voltage Watt Current
04 Low Voltage Fault When Load Supply Voltage less then 11V DC
17
4.2 Controlling & Monitoring Section IoT Result with Hardware
18
Fig 4.6: Total System
4.3 Discussion
Our Proposed system is a smart utility Load Management System is a system that helps to manage the
load of electricity in a smart way. It is designed to gain advanced control and minimize cost by
reducing downtime, reducing energy costs, supporting capacity planning, improving efficiency, and
providing a view into the system as a whole. Load management is the process of balancing the supply
of electricity on the network with the electrical load by adjusting or controlling the load rather than the
power station output. We focus on the priority based load management line in a different zone and
consumer section which is shown in the above table 6.2 and 6.3. There are many methods of load
management which can be followed by an industry or a utility, such as load shedding and restoring,
load shifting, installing energy-efficient processes and equipment, energy storage devices, co
generation, non-conventional sources of energy, and reactive power control. We also develop renewable
energy like hydro power generation.
4.4 Application
19
▪ Domestic Applications.
▪ Mobile tower Applications
4.5 Advantages
▪ Improving power reliability and quality
▪ Better controlling and monitoring using sensor networks and communications. ▪ Better and faster
balancing of supply and demand
▪ Reduced operations and management cost.
▪ Enhancing the capacity and efficiency of the electric load control.
Total = 5500/-
20
CONCLUSION
The suggested framework will be a demo rendition that gives expense effectiveness, taking less time,
and technically the easiest way for differentiating objects. This framework utilizes Arduino Nano
which makes this model simple to utilize. Therefore, it is very important to have proper and checked
sensors. Further, making desirable changes can be used in small-scale and large-scale industries as
well. A prototype of programmable load time management for the utility department using IoT is
developed that is competent to recognize various kinds of load shedding in the work station or
industries such as production factory, food packaging factory etc. for emergencies. To confirm that the
system works according to the requirements specified time management, it was broadly tested. To
increase more human interference this system is enhanced by the webserver for monitoring the
electrical load present condition. It has been underlined that this hardware solution can perfectly
address the current challenges in these fields such as high control performance, reliability, and
efficiency. Programmable parameters allow complete control over the whole system.
21
FUTURE WORK
22
REFERENCE
[1] .K.Mehta and Rohit Mehta, “ principles of power system”, 4th ed, . hand publication, 2008.
[2] Ashfaq Husain, “Electrical power system”, 5th ed, B publishers and distributors vt. Ltd., 2007.
[3] M. .O liveira and . . Barioni, “Technical loss calculation by distribution system segment with
corrections from measurements'', roc.20th international conference and Exhibition on Electricity
Distribution, Prague, Czech Republic, June 2009, pp. 1–4.
[4] unil . Rao, “ switchgear protection and power systems”, 9th ed, Khanna publishers, 2012. [5] .
.Wadhwa, “Electrical power systems”, 4th ed, New Age International Publishers, 2005. [6] C. J.
Bandim, E. R. Alves ., A. V. Pinto, F. C. Souza, M. R. B. Loureiro, C. A. Magalhaes
and F. Galvez- urand, “Identification of Energy Theft band Tampered Meters sing a central Observer
Meter: Mathematical approach”, Transmission and distribution conference and exposition, 2003 IEEE
PES, vol. 1, pp. 163-168,2003.
[7] “RW -434N datasheet”, Wenshing electronics co., td., Taipei, Taiwan. [8] J.J. Ford, H. Bevrani, G.
edwich, " adaptive load shedding and regional protection,” International Journal of Electrical power
Energy systems”, volume 31, ages 611-618. Issue 10, November-December 2009
[9] F. apitanescu, B. Otomega, H. efebvre, . ermanson, T. an utsem, “ decentralized tap changer
blocking and load shedding against voltage instability: Prospective tests on the RTE system,Electrical
power and Energy systems”, ol 31, Issue 9, 2009, pp 570–576.
[10] R. M. Maliszewski, R. . unlop, and G. . Wilson, “Frequency Actuated load shedding and
restoration Part I— philosophy”, IEEETransactions on power apparatus and systems, vol. 90, no. 4,
1971, pp.1452–1459.
[11] A. Saffarian, M. Sanaye-pasand, H. sadi,” performance Investigation of New combinational load
shedding schemes”, Joint International conference on power system Technology and IEEE Power
IndiaConference, 2008. pp 1 – 8.
[12] A. A. Abou, A. Zein El- in, . R. pea, .R., “Optimal load shedding n power systems”, Eleventh
International Middle East Power SystemsConference, Volume 2, 2006, pp. 568 – 575.
[13] Tah Eric Wesoff mid (2 April 2013). "Aquion Energy's Disruptive Battery Tech Picks Up $35M in
VC". greentechmedia.com. Archived from the original on 6 August 2013.
22
[14] Zachary Shahan (9 May 2015). "Tesla Powerwall & Powerpacks Per-kWh Lifetime Prices vs
Aquion Energy, Eos Energy, & Imergy". CleanTechnica. Retrieved 19 March 2018.
[15] David L. Chandler, MIT News Office (19 November 2009). "Liquid battery big enough for the
23
electric grid?". MIT News. Archived from the original on 13 February 2010.
[16]" Appalachian Power Dedicates Mega Battery; New Technology Provides Extra Power,
Reliability" (Press release). Appalachian Power. 20 July 2006. Archived from the original on 22
October 2006.
[17] Eric Wesoff (24 May 2012). "Sadoway's MIT Liquid Metal Battery Startup Adds $15M and
Khosla Ventures as Investor". greentechmedia.com. Archived from the original on 25 September 2012.
[18] "Renewable. Rechargeable. Remarkable.", Feature Article, September 2005 Archived 15 January
2009 at the Wayback Machine
[19] "Grid-Scale storage with vanadium redox flow batteries". REDT Energy Storage. Archived from
the original on 15 May 2014.
[20] "Wind farm with battery storage in Ireland". Leonardo Energy. Archived from the original on 2
November 2007.
[21] Parker, Robin; Clapper, Jr, William L. "HYDROGEN-BASED UTILITY ENERGY STORAGE
SYSTEM" (PDF). Archived (PDF) from the original on 26 January 2017. Retrieved 2 February 2017.
[22] Gyuk I, Kulkarni P, Sayer JH, et al. (2005). "The United States of storage". IEEE Power and
Energy Magazine. 3 (2): 31–9. doi:10.1109/MPAE.2005.1405868.
24
APPENDIX
#include <LiquidCrystalSerial.h>
#include <SoftwareSerial.h>
#define butt A4
#define SH 6
#define DS 4
#define ST 5
#define rly1 1
#define rly2 2
#define rly 3 3
#define rly4 4
#define rly 5 5
bool r1 = 1, r2 = 1, r3 = 1, r4 = 1, r5 = 1;
void setup() {
Serial.begin(115200);
gsm.begin(9600);
lcd.begin(16, 2, SERIAL);
randomSeed(analogRead(A7));
pinMode(butt, INPUT);
pinMode(SH, OUTPUT);
pinMode(DS, OUTPUT);
pinMode(ST, OUTPUT);
output(rly1, r1);
output(rly2, r2);
output(rly3, r3);
output(rly4, r4);
output(rly5, r5);
void loop() {
char key = keypad.getKey();
acVolt = getVoltage(A6);
amp1 = getCurrent(A7) - 0.09;
amp2 = getCurrent(A5) - 0.09;
wh1 = acVolt * amp1;
wh2 = acVolt * amp2;
if (!rechargeFlag) amount -= ((wh1 * (hh + (mm / 60.0))) / 1000.0) * UNIT_FEE;
if (amount < 0) amount = 0;
if (wh1 < 0) wh1 = 0;
if (wh2 < 0) wh2 = 0;
if (r5 == 1) {
lcd.setCursor(0, 0);
lcd.print((String)acVolt + "V | " + amp1 + "A ");
lcd.setCursor(0, 1);
lcd.print((String)wh1 + "W " + amount + "TK ");
}
else {
lcd.setCursor(0, 0);
lcd.print((String)"GRID: " + acVolt + "V ");
lcd.setCursor(0, 1);
lcd.print((String)amp2 + "A " + wh2 + "W ");
}
if (gridFlag == 1) {
if (tSS == setSS && tMM == setMM && tHH == setHH) {
tSS = 0; tMM = 0; tHH = 0;
r5 = !r5;
output(rly5, r5);
}
}
if (digitalRead(butt)) {
rechargeFlag = !rechargeFlag;
lcd.clear();
rechargeFlag ? lcd.print("FREE Mode ON") : lcd.print("FREE Mode OFF"); delay(1000);
lcd.clear();
}
if (ss % 10 == 0) {
checkServer();
String link = "WEB=0,http://kitsware.com/projects/energymeter/update_machine.php?"; link += (String)"ac1=" + acVolt + "&";
link += (String)"ac2=" + acVolt + "&";
link += (String)"amp1=" + amp1 + "&";
link += (String)"amp2=" + amp2 + "&";
link += (String)"wh1=" + wh1 + "&";
link += (String)"wh2=" + wh2 + "&";
link += (String)"blnc=" + amount + "&";
link += (String)"time=" + setHH + ":" + setMM + ":" + setSS;
Serial.println(link);
delay(1500);
}
checkSMS();
if (key >= '1' && key < '6') OTPMode(key - 49);
if (key >= 'A') setupTimer();
runClock();
}
void checkServer() {
Serial.println("WEB=1,http://kitsware.com/projects/energymeter/stat_machine.php"); while (!Serial.available());
if (Serial.available()) {
String rx = Serial.readString();
action(rx);
}
}
26
if (rx.indexOf("l1=1") != -1) r1 = 0;
else if (rx.indexOf("l1=0") != -1) r1 = 1;
if (rx.indexOf("l2=1") != -1) r2 = 0;
else if (rx.indexOf("l2=0") != -1) r2 = 1;
if (rx.indexOf("l3=1") != -1) r3 = 0;
else if (rx.indexOf("l3=0") != -1) r3 = 1;
if (rx.indexOf("l4=1") != -1) r4 = 0;
else if (rx.indexOf("l4=0") != -1) r4 = 1;
if (rx.indexOf("l5=1") != -1) r5 = 0;
else if (rx.indexOf("l5=0") != -1) r5 = 1;
output(rly1, r1);
output(rly2, r2);
output(rly3, r3);
output(rly4, r4);
output(rly5, r5);
void OTPMode(byte b) {
String password = "";
lcd.clear();
lcd.print("Sending OTP..");
for (byte i = 0; i < 6; i++) password += (char)(random(10) + 48);
Serial.println((String)"PASS=" + password);
sendSMS(NUM, (String)"OTP is: " + password);
lcd.setCursor(0, 1);
lcd.print("DONE.");
delay(1000);
lcd.clear();
lcd.print("Enter OTP:");
byte x = 0;
String pass = "";
while (1) {
char key = keypad.waitForKey();
if (key == '*' || key == '#') break;
lcd.setCursor(x, 1);
lcd.print(key);
pass += key;
x++;
if (x == 6) break;
}
if (pass == password) {
lcd.clear();
lcd.print((String)"Added " + (rechrgAmount[b]) + "TK"); amount += rechrgAmount[b];
lcd.setCursor(0, 1);
lcd.print((String)"Balnc: " + amount + "TK"); delay(2000);
lcd.clear();
}
else {
lcd.clear();
lcd.print("WRONG OTP!!");
delay(1000);
}
}
void setupTimer() {
27
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SET TIMER:[HH]");
delay(200);
int x = 0;
String val = "";
while (1) {
char key = keypad.waitForKey();
if (key == 'B') break;
lcd.setCursor(x, 1);
lcd.print(key);
delay(500);
val += key;
x++;
}
setHH = val.toInt();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SET TIMER:[MM]");
delay(200);
x = 0;
val = "";
while (1) {
char key = keypad.waitForKey();
if (key == 'B') break;
lcd.setCursor(x, 1);
lcd.print(key);
delay(500);
val += key;
x++;
}
setMM = val.toInt();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SET TIMER:[SS]"); delay(200);
x = 0;
val = "";
while (1) {
char key = keypad.waitForKey(); if (key == 'B') break;
lcd.setCursor(x, 1);
lcd.print(key);
delay(500);
val += key;
x++;
}
setSS = val.toInt();
lcd.clear();
tSS = 0; tMM = 0; tHH = 0;
if (setSS || setMM || setHH) gridFlag = 1; else gridFlag = 0;
}
void runClock() {
static long ct = millis();
if (millis() - ct > 1000) {
ss++;
cp = 0;
if (ss == 60) {
ss = 0;
mm++;
if (mm == 60) {
28
hh++;
mm = 0;
}
}
tSS++;
if (tSS == 60) {
tSS = 0;
tMM++;
if (tMM == 60) {
tHH++;
tMM = 0;
}
}
ct = millis();
}
}
void GSMinit() {
lcd.clear();
lcd.print("GSM Powering UP"); lcd.setCursor(0, 1);
lcd.print("Please wait...");
delay(15000);
gsm.print("AT\r\n");
delay(1000);
gsm.print("ATE0\r\n");
delay(1000);
gsm.print("AT+CMGF=1\r\n"); delay(1000);
gsm.print("AT+CNMI=1,2,0,0,0\r\n");
delay(1000);
lcd.clear();
}
gsm.print("AT+CMGF=1\r\n");
delay(200);
gsm.print((String)"AT+CMGS=\"" + number + "\"\r\n"); delay(200);
gsm.print(msg);
gsm.write(0x1A);
gsm.print("\r\n");
delay(3000);
lcd.clear();
}
void checkSMS() {
String sms = "";
if (gsm.available()) {
sms = gsm.readString();
if (sms.indexOf("+CMT:") == -1) {
if (sms.indexOf("INFO") != -1) {
String msg = "IoT Energy Meter";
msg += (String)"\nAC Volt: " + acVolt;
msg += (String)"\nAmp 1: " + amp1;
msg += (String)"\nAmp 2: " + amp1;
msg += (String)"\nWh 1: " + wh1;
msg += (String)"\nWh 2: " + wh2;
msg += (String)"\nBalance: " + amount;
msg += (String)"\nTime: " + setHH + ":" + setMM + ":" + setSS; sendSMS(NUM, msg);
}
29
else if (sms.indexOf("##") != -1) action(sms);
}
}
}
Device = 16C73B
30
ADCON1 = 7
TRISA = 0 : PORTA = 0
Dim x As Byte
Dim temp[3] As Byte
Dim second As Byte
Dim minute As Word
Dim a_sec_r2 As Word
Dim a_sec_r3 As Word
Dim a_sec_r4 As Word
Dim m_sec_r1 As Word
Dim m_sec_r2 As Word
Dim m_sec_r3 As Word
Dim m_sec_r4 As Word
Dim g_sec_r1 As Word
Dim g_sec_r2 As Word
Dim g_sec_r3 As Word
Dim g_sec_r4 As Word
Dim mode As Byte
Dim t_stop As Bit
Dim r1_done As Bit
Dim r2_done As Bit
Dim r3_done As Bit
Dim r4_done As Bit
Dim msg[20] As Byte
Clear
Include "keypad4x4.inc"
main:
Print At 1,1,"Time Management."
Print At 2,1, Dec2 minute, ":", Dec2 second
If second = 60 Then
second = 0
Inc minute
EndIf
If rly1 = 0 Then Print At 2,7, 1 : Else : Print At 2,7, 0 If rly2 = 0 Then Print At 2,8, 1 : Else : Print At 2,8, 0 If rly3 = 0 Then
Print At 2,9, 1 : Else : Print At 2,9, 0 If rly4 = 0 Then Print At 2,10, 1 : Else : Print At 2,10, 0
If mode = 0 Then
Print At 2,12, "AUTO "
If second = a_r1_sec Then rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 1 If second = a_sec_r2 Then rly1 = 0 : rly2 = 0 : rly3 = 1 : rly4 =
1 If second = a_sec_r3 Then rly1 = 0 : rly2 = 1 : rly3 = 1 : rly4 = 1 If second = a_sec_r4 Then rly1 = 1 : rly2 = 1 : rly3 = 1 : rly4
= 1 If second = 50 Then rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0 : second = 0
ElseIf mode = 1 Then
Print At 2,12, "Man. "
31
If second = m_sec_r1 Then rly1 = 1
If second = m_sec_r2 Then rly2 = 1
If second = m_sec_r3 Then rly3 = 1
If second = m_sec_r4 Then
rly4 = 1
DelayMS 2000
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0 : second = 0
EndIf
ElseIf mode = 2 Then
Print At 2,12, "GSM. "
If second = g_sec_r1 Then rly1 = 1
If second = g_sec_r2 Then rly2 = 1
If second = g_sec_r3 Then rly3 = 1
If second = g_sec_r4 Then
rly4 = 1
DelayMS 2000
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0 : second = 0
EndIf
EndIf
GoSub capture_key
If key_value = "A" Then
mode = 0
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0
EndIf
If key_value = "B" Then
mode = 1
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0
GoSub manual_set
GoTo main
Receive_SMS:
Clear msg
HSerIn 1000, over, [Wait("+CMT"), Wait(13,10), Str msg] g_sec_r1 = (msg[2] - 48) * 100 + (msg[3] - 48) * 10 + (msg[4] - 48)
g_sec_r2 = (msg[7] - 48) * 100 + (msg[8] - 48) * 10 + (msg[9] - 48) g_sec_r3 = (msg[12] - 48) * 100 + (msg[13] - 48) * 10 +
(msg[14] - 48) g_sec_r4 = (msg[17] - 48) * 100 + (msg[18] - 48) * 10 + (msg[19] - 48) PORTA = $ff
Cls
Print At 1,1,"R1: ", Dec3 g_sec_r1, " R2: ", Dec3 g_sec_r2 Print At 2,1,"R3: ", Dec3 g_sec_r3, " R4: ", Dec3 g_sec_r4
DelayMS 2000
Cls
second = 0
g_sec_r2 = g_sec_r2 + g_sec_r1
g_sec_r3 = g_sec_r3 + g_sec_r2
g_sec_r4 = g_sec_r4 + g_sec_r3
mode = 2
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0
over:
Return
manual_set:
Cls
Print At 1,1,"Manual Setup:"
DelayMS 1000
Print At 2,1,"Relay 1:"
For x = 0 To 2
GoSub read_key
Print At 2,x+10, key_value
temp[x] = key_value - 48
Next
m_sec_r1 = temp[0] * 100 + temp[1] * 10 + temp[2] Cls
Print At 1,1,"Relay 1:", Dec3 m_sec_r1, "sec" Print At 2,1,"*:Confirm #:Back"
While 1 = 1
GoSub capture_key
If key_value = "*" Then GoSub setup2 If key_value = "#" Then GoSub manual_set If key_value = "D" Then Cls : GoSub
main Wend
setup2:
32
Cls
Print At 1,1,"Manual Setup:"
Print At 2,1,"Relay 2:"
For x = 0 To 2
GoSub read_key
Print At 2,x+10, key_value
temp[x] = key_value - 48
Next
m_sec_r2 = temp[0] * 100 + temp[1] * 10 + temp[2] Cls
Print At 1,1,"Relay 2:", Dec3 m_sec_r2, "sec" Print At 2,1,"*:Confirm #:Back"
While 1 = 1
GoSub capture_key
If key_value = "*" Then GoSub setup3 If key_value = "#" Then GoSub setup2 If key_value = "D" Then Cls : GoSub main
Wend
setup3:
Cls
Print At 1,1,"Manual Setup:"
Print At 2,1,"Relay 3:"
For x = 0 To 2
GoSub read_key
Print At 2,x+10, key_value
temp = key_value - 48
Next
m_sec_r3 = temp[0] * 100 + temp[1] * 10 + temp[2] Cls
Print At 1,1,"Relay 3:", Dec3 m_sec_r3, "sec" Print At 2,1,"*:Confirm #:Back"
While 1 = 1
GoSub capture_key
If key_value = "*" Then GoSub setup4 If key_value = "#" Then GoSub setup3 If key_value = "D" Then Cls : GoSub main
Wend
setup4:
Cls
Print At 1,1,"Manual Setup:"
Print At 2,1,"Relay 4:"
For x = 0 To 2
GoSub read_key
Print At 2,x+10, key_value
temp[x] = key_value - 48
Next
m_sec_r4 = temp[0] * 100 + temp[1] * 10 + temp[2] Cls
Print At 1,1,"Relay 4:", Dec3 m_sec_r4, "sec" Print At 2,1,"*:Confirm #:Back"
While 1 = 1
GoSub capture_key
If key_value = "*" Then GoSub done If key_value = "#" Then GoSub setup4 If key_value = "D" Then Cls : GoSub main
Wend
done:
Cls
rly1 = 0 : rly2 = 0 : rly3 = 0 : rly4 = 0 : second = 0 m_sec_r2 = m_sec_r2 + m_sec_r1
m_sec_r3 = m_sec_r3 + m_sec_r2
m_sec_r4 = m_sec_r4 + m_sec_r3
Print At 2,1,"Done.."
DelayMS 1000
Cls
GoSub main
33