Iot Based Smart Electrical Distribution System
Iot Based Smart Electrical Distribution System
Iot Based Smart Electrical Distribution System
CERTIFICATE
This is to certify that the Project Report entitled “DESIGN AND IMPLEMENTATION
OF IOT BASED SMART ELECTRICAL DISTRIBUTION SYSTEM AND SMART
CONSUMPTION” is being submitted by S.S.Nagendra Kumar (14A31A0253),
S.Koteswara Rao (14A31A0250), M.Suresh Raju (14A31A0236), T.Ram Manohar
Reddy (14A31A0254), S.Trimurthulu (15A35A0214), K.Sivaji (14A31A0233) in
partial fulfillment for the award of the Degree of Bachelor of Technology in
Electrical & Electronics Engineering of Pragati Engineering College, for the record of
bonafide work carried out by them.
Assistant Professor
Dr. K. SATYANARAYANA
M. Tech., PhD, MIE, MIEEE, MISTE, C Eng
We are thankful to all our faculty members of the department for their valuable
suggestions. Our sincere thanks also extended to all the teaching and the non-teaching
staff of Pragati Engineering College.
i
LIST OF FIGURES
Fig. No Description of Figure Page No
1.1 Substation and Distribution System 2
1.2 Feeders 3
1.3 2 Wire DC System 4
1.4 3 Wire DC System 4
1.5 Primary Distribution System 5
1.6 Secondary Distribution System 6
1.7 Radial System 8
1.8 Radial System for AC system 9
1.9 Ring Main Distribution System 10
1.10 Interconnected System 11
1.11 Block Diagram of The Project 12
2.1 Load Prediction in India 14
2.2 Monthly Energy Audit in Puducherry 17
2.3 Security and Privacy in Smart Grid 19
2.4 Renewable generation Growth Trend 19
2.5 Supply Side Aspects of SG in UK 21
3.1 Reverse Tampering of Energy Meter 26
3.2 Tamper Detection Meter 26
3.3 Block Diagram of The Prepaid Meter 29
3.4 Plastic Case Closed Energy Meter 29
3.5 Leveling OF Demand Curve 35
4.1 Voltage Regulator 39
4.2 NODE MCU 41
4.3 Arduino UNO 42
4.4 HC-05 Bluetooth Module 44
4.5 Light Dependent Resistor (LDR) 45
4.6 Block Diagram of Energy Meter 46
4.7 Relay 46
4.8 Four Channel Relay 47
4.9 Classifications of Loads 48
4.10 Interfacing NodeMCU with HC-05 48
4.11 Interfacing Transformer Meter with NodeMCU 49
4.12 Interfacing Arduino UNO with HC-05 49
4.13 Interfacing Energy Meter with Arduino UNO 50
ii
LIST OF ABBREVIATIONS
iii
IOT BASED SMART ELECTRICAL DISTRIBUTION SYSTEM
CHAPTER 1
INTRODUCTION
Now a days, the energy consumption and energy distribution has become a
major problem because of huge difference in energy production and consumption. In
this regard, energy consumers are facing so many problems due to the frequent power
failures and the un-limited energy consumption of rich people.
IOT based Smart electrical distribution system is an evolution of the existing
distribution system. Advancement in high speed communication and low-cost sensors
coupled with the increased deployment of the advanced provide utilities with better
information to manage the distribution grid.
It comprises of a two-way communication where electricity and information
are exchanged by the consumer and utility to maximize efficiency. The control center
ensure that smart distribution grid optimizes circuit VAR flow and voltages, there by
power theft location can be monitored with help of the smart transformers and smart
energy meters.
The consumer has a smart meter which consists of Node-MCU and relays. For
each area there is Node-MCU meter hub which is connected to cloud for data analysis.
The entire digital data is sent to the Amazon web services cloud platform (internet).
The electrical bills are automatically generated in the internet (cloud) for every
consumer with unique Id’s.
This system also helps the consumers to monitor their daily usage of electricity
through internet. He can control the heavy appliances to reduce his electrical billing.
The communication between the consumer and service provider through web
increases the efficiency and reliability.
The part of power system which distributes electric power for local use is
known as distribution system [1]. In general, the distribution system is the electrical
system between the substation fed by the transmission lines and the consumer meters.
It generally consists of feeders, distributors and the service mains.
1.2.1 Feeders:
1.2.2 Distributor:
A distributor is a conductor from which tapings are taken for supply to the
consumers. In Fig. 1.2 AB, BC, CD and DA are the distributors. The current through a
distributor is not constant because tapings are taken at various places along its length.
While designing a distributor, voltage drop along its length is the main consideration
since the statutory limit of voltage variations is ± 6% of rated value at the consumers’
terminals.
.
Fig 1.3 2: Wire DC System
• This system is never used for distribution purposes due to low efficiency
but may be employed for distribution of DC power.
• Loads requiring high voltage (e.g., motors) are connected across the
outers, whereas lamps and heating circuits requiring less voltage are
connected between either outer and the neutral.
Advantages of AC system:
• The power can be generated at high voltages.
• The maintenance of AC sub-stations is easy and cheaper.
• The AC voltage can be stepped up or stepped down by transformers with ease
and efficiency. This permits to transmit power at high voltages and distribute
it at safe potentials.
Disadvantages of DC system:
• An AC line requires more copper than a DC line.
• The construction of AC distribution line is more complicated than a DC
distribution line.
• Due to skin effect in the AC system, the effective resistance of the line is
increased.
• An AC line has capacitance. Therefore, there is a continuous loss of power
due to charging current even when the line is open.
1.2.4.2 Type of Construction:
• The underground system uses conduits, cables and manholes under the
surface of streets and sidewalks.
• The choice between overhead and underground system depends upon several
differing factors.
(i) Public safety: The underground system is safe than overhead system because all
distribution wiring is placed underground and there are little chances of any hazard.
(ii) Initial cost: The underground system is more expensive due to the high cost of
trenching, conduits, cables, manholes and other special equipment. The initial cost of
an underground system may be five to ten times than that of an overhead system.
(iii) Flexibility: The overhead system is much more flexible than the underground
system. In the latter case, manholes, duct lines etc., are permanently placed once
installed and the load expansion can only be met by laying new lines. However, on an
overhead system, poles, wires, transformers etc., can be easily shifted to meet the
changes in load conditions.
(iv) Faults: The chances of faults in underground system are very rare as the cables
are laid underground and are generally provided with better insulation.
(v) Appearance: The general appearance of an underground system is better as all the
distribution lines are invisible. This factor is exerting considerable public pressure on
electric supply companies to switch over to underground system.
(vi) Fault location and repair. In general, there are little chances of faults in an
underground system. However, if a fault does occur, it is difficult to locate and repair
on this system. On an overhead system, the conductors are visible and easily
accessible so that fault locations and repairs can be easily made.
(vii) Current carrying capacity and voltage drop: An overhead distribution
conductor has a considerably higher current carrying capacity than an underground
cable conductor of the same material and cross-section. On the other hand,
underground cable conductor has much lower inductive reactance than that of an
overhead conductor because of closer spacing of conductors.
(viii) Useful life: The useful life of underground system is much longer than that of an
overhead system. An overhead system may have a useful life of 25 years, whereas an
underground system may have a useful life of more than 50 years.
(ix) Maintenance cost: The maintenance cost of underground system is very low as
compared with that of overhead system because of less chances of faults and service
interruptions from wind, ice, lightning as well as from traffic hazards.
(x) Interference with communication circuits: An overhead system causes
electromagnetic interference with the telephone lines. The power line currents are
superimposed on speech currents, resulting in the potential of the communication
channel being raised to an undesirable level. However, there is no such interference
with the underground system.
PRAGATI ENGINEERING COLLEGE Page 8
IOT BASED SMART ELECTRICAL DISTRIBUTION SYSTEM
• This is the simplest distribution circuit and has the lowest initial cost.
DRAWBACKS:
• The end of the distributor nearest to the feeding point will be heavily
loaded.
• Any fault on the feeder or distributor cuts off supply to the consumers who
are on the side of the fault.
• The consumers at the distant end of the distributor would be subjected to
serious voltage fluctuations when the load on the distributor changes.
• Due to these limitations, this system is used for short distances only.
ADVANTAGES:
• There are less voltage fluctuations at consumer’s terminals.
• The system is very reliable as each distributor is fed via *two feeders. In the
event of fault on any section of the feeder, the continuity of supply is
maintained.
• When the feeder ring is energized by two or more than two generating
stations or substations, it is called inter-connected system.
• Fig. shows the single line diagram of interconnected system where the
closed feeder ring ABCD is supplied by two substations S1 and S2 at points
D and C respectively.
• Distributors are connected to points O, P, Q and R of the feeder ring
through distribution transformers.
ADVANTAGES:
• It increases the service reliability.
• Any area fed from one generating station during peak load hours can be fed
from the other generating station.
• This reduces reserve power capacity and increases efficiency of the system.
1.2.5.3 Reliability:
Modern industry is almost dependent on electric power for its operation.
Homes and office buildings are lighted, heated, cooled and ventilated by electric
power. This calls for reliable service. Unfortunately, electric power, like everything
else that is man-made, can never be absolutely reliable. However, the reliability can be
improved to a considerable extent by (a) interconnected system (b) reliable automatic
control system (c) providing additional reserve facilities.
The core idea of the project is to DIGITALISE the distribution system based on
IOT. A digitalized smart distribution system includes the application of information
technology systems to handle new data and permits utilities to more effectively and
dynamically manage system operations. The information provided by smart
distribution systems also enables customers to make informed choices about the way
they manage energy use of electric power. By using IOT technology every change in
the distribution system can be detected. It comprises of two-way communication
PRAGATI ENGINEERING COLLEGE Page 12
IOT BASED SMART ELECTRICAL DISTRIBUTION SYSTEM
CHAPTER 2
LITERATURE SURVEY
India is the fourth largest energy consumer in the world. The fast paced growth
of Indian economy has resulted in a surging demand for energy. Projected electricity
demand growth in India is shown in below figure. Since independence, India has seen
a phenomenal development in power sector, despite that about 400 million people in
India have no access to electricity and hundreds of millions get electricity for only a
few hours. To maintain the pace of economic development, provide access of
electricity to all along with meeting environmental concerns, India needs to explore
non-conventional sources of energy for long term energy security and sustainability.
Unlike conventional generation renewables are non-dispatchable i.e. there are
uncertainties and variability associated with large scale wind / solar generation. Smart
Grid development in India is expected to facilitate in integration of large scale
renewable generation through enhanced monitoring of power system and greater
consumer participation as well as address the various issues associated with the
distribution sector[2].
It is evident that the far-reaching goals of the modern Indian power system can
be achieved by development of smart grids which can help to improve efficiency of
Indian power sector. Smart Grid Vision for India is: “Transform the Indian power
sector into a secure, adaptive, sustainable and digitally enabled ecosystem that
provides reliable and quality energy for all with active participation of stakeholders.”
It is aligned to the Government’s overreaching policy of “Access, Availability and
Affordability of Quality Power for all”.
Indian Smart Grid Task Force (ISGTF) under MoP, GoI has shortlisted fourteen
(14) Smart Grid Pilot Projects spread across the country for demonstration of
technology. Govt. of India will finance 50% of the cost of the project as grant and
balance cost has to be borne by respective state utilities [4].
.
Fig 2.2 Monthly Energy Audit in Puducherry
• Promotion of EVs:
Deployment of EV Charging Infrastructure envisaged under the National
Mission for Electric Mobility of MoHI can be coordinated under NSGM in some of
these cities.
• Distributed Generation in form of Roof top PVs:
The promotion of grid connected solar capacity addition, JNNSM also has a
mandate to encourage the rooftop solar segment. The promotion of Roof top PV based
Distributed Generation will be encouraged with invigoration of Central and state
government’s schemes in association with MNRE and respective state governments
and mechanism of funding and incentives will be worked out under their schemes.
• Technology Demo Projects for Real Time Monitoring:
These initiatives are directed towards improving Quality and reliability of
Power and will be partly-funded under NSGM in these cities.
India receives nearly 3,000 hours of sunshine every year with a solar
generation potential of about 20-30 MW/ km2. The country’s installed solar power
generation capacity has grown exponentially in the recent past, from mere 2.12 MW
in 2007-08 to 2208 MW in Jan 2014. Four major deserts i.e. Thar, Rann of Kutch,
Ladakh & Lahul Spiti in India have significant renewable (Solar) potential. A report
titled “Desert Power in India: 2050” describes integrated plan for renewable
development in Deserts of India.
However, the existing grid systems operate in liberalized markets where there
are different actors for transmission, distribution and supply of electricity and the
benefits these technologies can provide might sit with other parties. As a result, smart
grid investment requires a financial model that is different from traditional utility
capital investment analysis. This is mainly because a smart system requires a variety
of technologies and programs, none of which by themselves provide a business case
but together yield the utility’s required return.
and as a method for reducing the costs of meeting these challenges. Policy Drivers for
Smart Grids, the UK has legislated a policy goal of an 80% reduction in national
climate change emissions by 2050; further to this the UK has a legal obligation under
EU law for 15% of all energy consumption to come from renewable energy sources by
2020 (Great Britain Climate Change Act, 2008; European Commission, 2009b). This
change will need to occur in the context of an energy system which will see up to a
quarter of existing electricity generating capacity close as nuclear and coal power
stations reach the end of the operational life.
CHAPTER 3
PROBLEM STATEMENT AND SOLUTION
Electrical power Theft is the criminal practice of stealing electrical power. There
are various ways of electrical power theft, including Tapping a line or bypassing
the energy meter. According to a study, 80% of worldwide theft occurs in private
dwellings and 20% on commercial and industrial premises. The various types of
electrical power theft include [8].
3.1.1 Power Theft Techniques:
.
Fig 3.4 Plastic Case Enclosed Energy Meter
• The agency collecting need not maintain any books of account for the
transactions.
A grid connected system as the name suggests is the one in which solar power
system is connected to the local main grid. In this case, loads can run on solar power
as long as there is sufficient energy available from the sun during the day. Any deficit
is taken care by the main utility supply. However, if the solar energy production is in
excess as compared to the load requirement at that moment, the excess energy can be
either stored in the batteries (if available) or can be sold back to the utility grid. This
difference of energy can be tracked using a meter connected to your solar PV system.
Net metering is an agreement that allows the solar PV system owner to sell
excess solar energy to the utility company or buy deficit energy from the utility
company using a meter to track this energy exchange.
Following 2 cases take place in this scenario:
Case 1: If at any moment of time, if solar energy generation (kWh) is less than
the load requirement at that time, the difference of energy is taken from the
distribution system and the meter runs forward, as usual. In this case, the system
owner is charged for the units (kWh) consumed from the main grid.
Case 2: If at any moment of time, if solar energy generation (kWh) is more than
the load requirement at that time, the excess solar energy is fed back to the distribution
system and the meter now runs backward. In this case, the system owner gets credit
for the units (kWh) fed back to the main grid.
All the meter readings are adjusted in the cloud database itself, which makes it
easy during bill payments.
not have to switch on and off as many times to generate energy, which lowers
generation costs.
CHAPTER 4
HARDWARE IMPLEMENTATION
Rectifier, Voltage Regulator, Node MCU, Arduino Uno HC-05 Module, LDR, Energy
Meter, Relays, Electrical loads.
4.2.1 Transformer:
A transformer is a device that transfers electrical energy from one electrical
circuit to another through mutual electromagnetic induction and without change in
frequency. Transformers are used to increase or decrease alternating current (AC)
voltage in circuits. The transformer is usually built with two coils around the same
core. The primary coil or input coil is connected to supply side while secondary coil
supplies power to load. The second one is called the output coil. Energy is transferred
from the primary to the secondary by electromagnetism. The Step-down transformer
of (220Vto 12V) is used in this project.
4.2.2 Rectifier:
A rectifier is an electrical device that converts alternating current (AC), which
periodically reverses direction, to direct current (DC), which flows in only one
direction. The process is known as rectification. Because of the alternating nature of
the input AC sine wave, the process of rectification alone produces a DC current that,
though unidirectional, consists of pulses of current. Many applications of rectifiers,
such as power supplies for radio, television and computer equipment, require
a steady constant DC current (as would be produced by a battery). In these
applications the output of the rectifier is smoothed by an electronic filter, which may
be a capacitor, choke, or set of capacitors, chokes and resistors, possibly followed by
a voltage regulator to produce a steady current.
4.2.3 Voltage Regulator:
For ICs within the 78xx family, the xx is replaced with two digits, indicating
the output voltage (for example, the 7805 has a 5-volt output, while the 7812 produces
12 volts). The 78xx line are positive voltage regulators: they produce a voltage that is
positive relative to a common ground. There is a related line of 79xx devices which
are complementary negative voltage regulators. 78xx and 79xx ICs can be used in
combination to provide positive and negative supply voltages in the same circuit.
A voltage regulator is an electrical regulator designed to automatically
maintain a constant voltage level. In this project, power supply of 5V and 12V are
required. In order to obtain these voltage levels, 7805 and 7812 voltage regulators are
to be used. The first number 78 represents positive supply and the numbers 05, 12
represent the required output voltage levels. 7812 is a famous IC which is being
widely used in 12V voltage regulator circuits. Truly speaking it is a complete
standalone voltage regulator. We only need to use two capacitors, one on the input and
second one on the output of 7812 in order to achieve clean voltage output and even
these capacitors are optional to use. To achieve 12V 1A current, 7812 should be
mounted on a good heat sink plate.
It lacks only a DC power jack, and works with a Mini-B USB cable instead of
a standard one. The Arduino Nano can be powered via the Mini-B USB connection, 6-
20V unregulated external power supply (pin 30), or 5V regulated external power
supply (pin 27). The power source is automatically selected to the highest voltage
source.
loads such as lights, fans and other appliances. Most interesting type are used as
prepaid electricity meters.
In analog type meters, voltage and current values of each phase are obtained by
voltage divider and current transformers which are directly connected to the load.
ADC converter converts these analog values to digitized samples and it is then
converted to corresponding frequency signals by frequency converter. These
frequency pulses then drive a counter mechanism where these samples are integrated
over a time to produce the electricity consumption.
4.2.10 Relay:
A relay is an electrically operated switch. Many relays use an electromagnet to
mechanically operate a switch. Relays are used where it is necessary to control a
circuit by a separate low-power signal, or where several circuits must be controlled by
one signal. A type of relay that can handle the high power required to directly control
an electric motor or other loads is called a contactor.
The Relay has Electromagnetic Coil turned around a metal piece this will reacts
as magnet when coil gets energized. Movable Armature attached with spring exactly
placed above the electromagnet setup and makes contact between common terminal
and Normally closed contact (N/C), without any supply or zero input supply, this
condition may be termed as normally open relay. When the coil get energized
movable armature attracted by electromagnet and N/O contact becomes closed and
N/C becomes open.
4.2.11 Electrical load:
The device which takes electrical energy is known as the electric load. In other
words, the electrical load is a device that consumes electrical energy in the form of the
current and transforms it into other forms like heat, light, work, etc. The electrical load
may be resistive, inductive, capacitive or some combination between them.
The classifications of loads are shown in the figure below.
CHAPTER 5
Software Implementation
CHAPTER 6
RESULT
This kit explains about the project “IOT BASED SMART ELECTRIC
DISTRIBUTION SYSTEM”. In this prototype we create unique websites for both the
provider and consumer.
Consumer Dashboard
Provider Dashboard
YES Notified
NO ----------
CONCLUSION:
With the growing world population, thus increasing demand the need for
resource depleting intelligent and efficient in our energy consumption has to have
become an imperative. Implementation of the smart distribution concept would go a
long way in solving many of today's energy issues and problems. The entire network
needs to be improved to meet the requirements, i.e., transmission and distribution
level requirements. Researches continue to find to make all the desired properties
possible the optimal solution and new technologies. Through the use of smart
distribution technology, energy can be used up to and would not be wasted. This
technology also helps to save the earth from global warming. It refers to the
modernized version of the earlier traditional methods of energy supply. Smart meters,
Smart Homes, Smart City and so would make the Smart distribution. As the new
technologies would be invented and strengthened existing ones to the desired
specifications meet the Smart distribution system would be reality and change the
whole pattern of energy in the world
FUTURE SCOPE:
Future research will focus primarily on machine learning, plug and play
technology, self-healing grid and total automation of the grid.
Plug and play technology for smart distribution system can enable and incentivize
consumers to give back i.e., redistribute energy generated by the consumer via
personal means (solar cells, wind turbines) through the smart system to other
consumers in need.
A self-healing system comprising of sensors, automated controls and advanced
software that utilizes real time distribution data to detect and isolate faults and to
reconfigure the distribution network to minimize the customers impacted.
As technology evolves further, the goal is to completely automate the grid –from
power generation to distribution and service management.
REFERENCES:
[1] Lecture notes on Electrical Distribution Systems B.Tech EEE IV Year I Semester
(Jntua-R13) Mr. Y.Hari Krishna Asst.Professor, Department Of Electrical and
Electronics Engineering Chadalawada Ramanamma Engineering College.
[2] “SMART GRID DEVELOPMENT IN INDIA – A CASE STUDY” I S Jha1,
Director (Projects), Power Grid Corporation of India Ltd., Gurgaon, India, Subir Sen2,
General Manager (Smart Grid & Energy Efficiency) Power Grid Corporation of India
Ltd., Gurgaon, India and Rajesh Kumar3 , Chief Manager (Smart Grid) Power Grid
Corporation of India Ltd., Gurgaon, India.
[3] Southern power distribution company of A.P. Limited, ARR & Tariff Proposals
for Retail Supply, Business for FY 2012-13
[4] “Smart Grid in Indian Power System”, I.S.Jha Y. K.Sehgal, Subir Sen, Rajesh
Kumar, NPSC 2012
[5] http://www.nsgm.gov.in/en/nsgm
[6] Smart Grid Security and Privacy: Challenges, Literature Survey and Issues Rajiv
.K. Bhatia, Varsha Bodade Dept. of Information Technology Terna Engineering
College Nerul, Navi-Mumbai 400-706, India
[7] Scenarios for the Development of Smart Grids in the UK: Literature Review
Dimitrios Xenias, Colin Axon, Nazmiye Balta-Ozkan, Liana Cipcigan, Peter Connor,
Rosemary Davidson, Alexa Spence, Gary Taylor, and Lorraine Whitmarsh.
[8] https://en.wikipedia.org/wiki/Theft_of_electricity
[9]https://www.revolvy.com/main/index.php?s=Theft%20of%20electricity
[10] Modernization of Metering, Billing and Collection System, the Customer
Relationship Management Tripta Thakur, Gayatri Agnihotri and Chaturbhuj Ahirwar
[11] https://en.wikipedia.org/wiki/Energy_demand_management
[12] https://www.bijlibachao.com/using-renewables/net-metering-policy-for-roof-top-
pvs-in-various-states-in-india.html
APPENDIX-1:
Node MCU code:
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Thread.h>
int ldr_value = 0;
double time_mseconds = 0;
int number_of_blinks = 0;
int delay_value = 0;
double units_consumed = 0;
float gm=0,cm=0,diff=0,avg=0;
int _mode=1;
int start=0;
WiFiClient client;
WiFiClient cl;
void anotherCallback()
{ if ( !cl.connect(http_site, http_port) ) {
// return false;
cl.print("GET /smartgrid/getmeterstatus.php");
cl.println(" HTTP/1.1");
cl.print("Host: ");
cl.println(http_site);
cl.println();
delay(10);
int test = 0;
while( cl.available() ) {
String ch = cl.readStringUntil('\n');
test++;
if(test>=7)
{ _ Serial.println(ch);}
{ Serial.println(ch); }
if(test>=8)
{ Serial.println(ch); }
{ Serial.println(ch); }
void niceCallback(){
if ( !client.connect(http_site, http_port) ) {
// return false;
client.print("&cmid=");
client.print(String(cmid));
client.print("&gmval=");
client.print(String(gmval));
client.print("&cmval=");
client.print(String(cmval));
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(http_site);
client.println("Connection: close");
client.println();
cmval = "";
gmval = "";
delay(10);
while( client.available() ) {
char c = client.read();
void setup()
Serial.begin(38400);
Wire.begin(D1, D2);
myThread.onRun(niceCallback);
myth.onRun(anotherCallback);
// Connect to WiFi
connectWiFi();
void loop()
if(start == 0)
int i = 0;
while(i<=6)
{ Serial.println("I");
i++;
start=1;
if(cmval.equals(""))
while (Serial.available()) {
cmval += ch;
if(ch == '\n')
while (0 <Wire.available()) {
char c = Wire.read();
else{ gmval+=c;
if(myThread.shouldRun())
myThread.run();
if(myth.shouldRun())
myth.run();
break;
void connectWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PSK);
delay(100);
char buffer[6];
String s;
float gmval=0;
int ldr_value = 0;
double time_mseconds = 0;
int number_of_blinks = 0;
int start=0;
void setup() {
void loop() {
if(start==1){
ldr_value = analogRead(input_pin);
{ number_of_blinks++;}
delay(delay_value);
time_mseconds += delay_value;
s = dtostrf(gmval, 4, 2, buffer);
while (0 <Wire.available()) {
start=1;
void requestEvent() {
Serial.println(s);
Wire.print(s);
time_mseconds = 0;
number_of_blinks = 0;
gmval=0;
// actual
int ldr_value=0;
int light_on_threshold=930;
int light_off_threshold=1000;
double time_mseconds=0;
double mseconds_per_minute=60000;
int number_of_blinks=0;
int delay_value=50;
double units_consumed=0;
int wattage_blinks=3200;
String state;
char st;
void setup()
pinMode(solar_ip,OUTPUT);
pinMode(solar_out,OUTPUT);
pinMode(pd,OUTPUT);
Serial.begin(38400);
void loop()
if(start == 0)
digitalWrite(pd,LOW);
digitalWrite(solar_ip,LOW);
digitalWrite(solar_out,LOW);
if (Serial.available()) {
state = ch;
if(state == "I")
{ start = 1;
else {
if(time_mseconds==mseconds_per_minute)
if(meter_stat == 0)
Serial.println((number_of_blinks*1000.0/wattage_blinks)*(-1));
if(meter_stat == 1)
Serial.println(number_of_blinks*1000.0/wattage_blinks);
//Serial.println(number_of_blinks);
number_of_blinks=0;
time_mseconds=0;
ldr_value= analogRead(input_pin);
if(ldr_value<light_on_threshold)
number_of_blinks++;
delay(delay_value);
time_mseconds+=delay_value;
// relays code
if (Serial.available()) {
digitalWrite(solar_ip,HIGH);
digitalWrite(solar_out,HIGH);
digitalWrite(pd,HIGH);
meter_stat = 0;
digitalWrite(solar_ip,LOW);
digitalWrite(solar_out,LOW);
//digitalWrite(pd,LOW);
meter_stat = 1;
if(meter_stat == 1)
digitalWrite(pd,HIGH);
digitalWrite(pd,LOW);