Professional Documents
Culture Documents
Electricity Theft Detection For Utilities Companies
Electricity Theft Detection For Utilities Companies
Submitted by
Waheed Ahmad Mian (15PWMCT-0417)
Ghazanfar Iqbal (15PWMCT-0402)
Abdul Nasir (15PWMCT-0398)
Supervisor
Dr. Riaz Akbar Shah
i
Electricity Theft Detection for Utilities Companies
ii
Dedication
Initially, all is the finesse of Almighty Allah who made us equipped for getting, learning and
actualizing our obtained information. Besides, we are genuinely thankful and devote our work
to our task director Dr. Riaz Akbar Shah, without his help it was impractical, he invited every
one of us an opportunity to examine any issue and challenge looked by us. He has constantly
upheld us and guided us the correct way. You're the best to his. We want his to enjoy all that
life has to offer for eternity.
iii
Declaration of Originality
We thus proclaim that the work contained in this proposal and the scholarly substance of this
postulations are the result of my/our own work. This proposition has not been recently
distributed in any structure nor does it contain any verbatim of the distributed assets which could
comprehend the terms 'copyright' and 'written falsification,' and that if there should arise an
occurrence of any copyright infringement or literary theft found in this work, we will be
Signature: ______________________________
Signature: ______________________________
Gazanfar Iqbal
Signature: ______________________________
Abdul Nasir
Date: ____________________
iv
Acknowledgement
We are heartedly thankful and recognize the favors of Almighty Allah for our great wellbeing so
we had the option to work with full devotion and assurance, without His endowments we would
not have had the option to accomplish our objectives.
We wish to offer our earnest thanks to the administrator of the division for giving us the chances
to express our aptitudes and actualize our insight as well as could be expected.
We might likewise want to thank the undertaking boss for the genuine help. He helped us
through the troublesome periods of our venture, without his significant direction and consolation
it was impractical. We additionally thank our folks for the persistent help, support and
consideration.
v
Table of Contents
1 Introduction........................................................................................................1
1.1 MOTIVITION: ................................................................................................................................. 1
1.2 THESIS OBJECTIVE: ........................................................................................................................ 2
1.3 THESIS ORGANIZATION: ................................................................................................................ 2
vi
3.10.1 Description: ......................................................................................................................... 20
3.10.2 Specification: ....................................................................................................................... 20
4 METHODOLOGY ..........................................................................................22
4.1 INTRODUCTION: .......................................................................................................................... 22
4.2 PROPOSED SYSTEM ARCHITECTURE: .......................................................................................... 22
4.3 PROPOSED CODING ARCHITECTURE AT THE RECEIVING SIDE: ................................................... 24
4.3.1 Coding architecture of data extraction: ............................................................................... 26
7 REFERENCES ................................................................................................33
8 APPENDIX .......................................................................................................34
8.1 APPENDIX A: ................................................................................................................................ 34
8.1.1 MAIN STATION ARDUINO CODE: ........................................................................................ 34
8.2 APPENDIX B: ................................................................................................................................ 49
8.2.1 ARDUINO CODE OF CURRENT SENSOR ............................................................................... 49
vii
List of Figures
Figure 3.1: Arduino Mega............................................................................................................... 7
Figure 3.2: Arduino Nano ............................................................................................................. 11
Figure 3.3: Jumper wires............................................................................................................... 13
Figure 3.4: 12v Power Adapter Charger ....................................................................................... 14
Figure 3.5: Buck Converter........................................................................................................... 15
Figure 3.6: GSM ........................................................................................................................... 16
Figure 3.7: 4 Channel Relay ......................................................................................................... 17
Figure 3.8: Bulb ............................................................................................................................ 18
Figure 3.9: Current Sensor ............................................................................................................ 19
Figure 3.10: 128x64 LCD display ................................................................................................ 21
Figure 4.1: Block diagram of Electricity theft detection operation .............................................. 22
Figure 4.2: Block diagram of Electricity theft detection operation .............................................. 23
Figure 4.3: Coding Architecture on the Receiving Side ............................................................... 25
Figure 4.4: Architecture of data extraction ................................................................................... 27
Figure 4.5: Project prototype ........................................................................................................ 28
viii
List of Tables
Table 5.1: Legal use of electricity................................................................................................. 29
Table 5.2: Illegal use of electricity ............................................................................................... 30
Table 5.3: Illegal use of electricity ............................................................................................... 30
ix
x
1 Introduction
1.1 MOTIVITION:
The electricity losses in Pakistan are increasing day by day. The electricity theft is process in
which the costumer is using electricity illegally. Which causes a huge lose in electricity. The
population of Pakistan is increasing day by day and thus the uses of electricity are also increase.
Pakistan electricity theft is increasing in domestic users which make electric supply company to
financial problem for electricity producing and cause load shading in the urban as well as in the
rural area. Electricity theft occurs in every region and feeder in each province of Pakistan which
is big loss and his bad effect on the power generation sector of electricity. The electricity losses
are two kinds one is Technical losses and other is non-technical losses (NTL). The major loss is
non-technical loss. The major cause of electricity theft is meter fraud and bypassing the meter
and direct connection from the distribution lines[1]. According to World Bank report about 50%
of electricity obtaining by the consumer is illegal[2]. The use of electricity in Pakistan is
23670MW and the generation is 18110MW with big difference of 5560MW which cause load
shading[3]. The shortfall of electricity is 5560MW and when we include the electricity thefts
create a big trouble for the legal consumer of electricity. To avoid this gap of lose we to
implement such method to minimize the non-technical loss (NTL) through Global System for
Mobile (GSM) and current sensor. This system will point out the theft location for grid station
which will be an easy way.
1
1.2 THESIS OBJECTIVE:
The objective of the thesis is to control Electricity theft in Pakistan. Facing the power loss is a
challenging problem. In our project we are working mainly on two things to avoid electricity
theft one is Global System for Mobile (GSM) and Current sensor. The current sensor will take
the consumption units from the user and sends it to grid station through Global System for
Mobile (GSM). This system will monitor all the consumer and sends messages to the main grids
stations. However many methods are used for electricity theft detection in worldwide but our
focus is on those electric theft which make direct connection from distributions lines.
In chapter 2 we have discussed the different method of stealing of electricity, the circumstances
that motivate electricity theft. The literature review based on the different uses and kind of
electricity theft. In chapter 3 we have discussed our project hardware description. The detail
information of every module which we use in our project and it clarify the insights regarding
physical parts of undertaking, their working standards and specialized particulars. Different parts
of the segments that are significant from the usage perspective are talked about in detail. In
chapter 4 we have discussed the proposed methodology of our project. All the information are
described in step by step. The Current sensor taking values from the consumption homes and
sending these values through GSM and these values received by other GSM and compare it in
the main station. The decisions of electricity theft are taking in the main station through
algorithm. In chapter 5 we have discussed the environmental effect of the project. How our
project contributes to the society. We discuss some importance effects of the project and also
negative effects.
2
2 FACTORS AND PROCEDURES FOR
CONTROLLING ELECTRICITY THEFT
Normally electricity consumers can be generalized as legal consumers, partial consumers, and
illegal consumers. In this chapter we will discuss different method of stealing electricity, impact
of illegal consumers of electricity, and selected method for detection of electricity theft.
The easiest way to steal electricity is to make direction connection from the distribution lines of
electricity. The second easiest way to steal electricity is to tamper the recording meter. There are
many methods used to tamper meter, some of they are:
Making strong magnetic field near the meter.
Putting high thick fluid in the disk to minimize the rotation of the disk.
Making a shunt connection between incoming and outgoing terminals.
Disturbing the coil of the meter.
Mechanical shock to meter.
On the other hand engineered method of tampering of meter is damaging the terminals. Connect
one of the load terminals to the ground and open the ground wire from the energy meter. In the
case of three phase meters, phases are shifted to lower the power consumption reading by the
energy meter. When the consumer demands are more in this case they use illegal electricity.
Sometimes the wrong calibrations of the meter reading also affect. There are several methods
were made to detect direct tapping or tampered meter and locating illegal connection.
In many countries, the usage of illegal electricity is punishable under their law.
3
2.2 CIRCUMSTANCES THAT MOTIVATE ILLEGAL
ELECTRICITY THEFT:
Elements that impact purchasers to take power on different nearby parameters that fall into
various classes like communal, managerial, economical and law. Of these variables, financial
components impact individuals to a more prominent degree in taking power.
In past years many methods, laws and policies are made for electricity theft. Some procedures
are describes that control electricity theft in worldwide. A decent procedure for battling
debasement in utilities must be created thinking about the political situations, business forms, the
executives, methods, and advances in metering and circulation checking, control and
computerization dependent on the geographic area. Notwithstanding the non-specialized
measures introduced prior, regularization of horticultural associations should be finished. The
4
majority of the agreements for sending and upkeep of the dissemination part should be
redistributed dependent on the presentation of the venture to which the offer will be granted.
What's more, in many nations, power robbery is viewed as a genuine offense and illicit
utilization in any type of unbilled vitality having a place with an utility is culpable under law.
Karachi Electric Supply Company (KESC) take the fatwa from Islamic scholars, that illegal use
of electricity is a sin[4]. Different techniques are used to find the illegal utilities against NTL.
Some methods are selected to find power theft. These methods have the ability to gather, sends,
and make operation on the data between different meters. Tis method can help to control the
electricity theft. To develop this method, a remote method can also be implemented to control
the theft[5].Installation of such energy meter that control electricity theft and also servile the
distribution system[6]. The total electricity from the main station is compared with the total
consumption of electricity read by the meter. These current values are compared to find the
illegal consumption[7]
5
3 HARWARE DESCRIPTION
This project is done on a prototype and done on 220V practically. This is a prototype type project
in which different components are used to present its concept that in near future how we tackle
the discussed problem. As the mission of our project is to give a roadmap to stop electricity theft
The following equipment is used in this project.
The Arduino Mega 2560 is a microcontroller board dependent on the ATmega2560. It has 54
computerized input/yield pins (of which 15 can be utilized as PWM yields), 16 simple sources of
info, 4 UARTs (equipment sequential ports), a 16 MHz gem oscillator, a USB association, a
power jack, an ICSP header, and a reset catch. It contains everything expected to help the
microcontroller; essentially interface it to a PC with a USB link or power it with an AC-to-DC
connector or battery to begin. The Mega 2560 board is good with most shields intended for the
Uno and the previous sheets.
6
Figure 3.1: Arduino Mega
3.1.1 Programming:
Arduino Mega 2560 can be programmed using Arduino Software called IDE which works on
C++ language. The code is called sketch which is burned in software and then shifted to board
through USB cable. The board comes with a build in bootloader so no need of burner. The
bootloader uses STK500 protocol. When programme is burnt on board once then unplug the
USB cable and power removes from board. When the board is used in our project then power
through Vin pin of board.
7
3.1.2 Specifications:
8
3.1.3 PINS OF ARDUINO Mega:
3.1.3.1 5V&3.3V:
This pin provides output of 5V.The power supply power up the controller and other components
on board. Another 3.3V voltage regulation can be provided. It can draw a maximum power of
50mA.
3.1.3.2 GND:
5 pins are present for more than one ground when more grounds are required.
3.1.3.3 RESET:
This pin is used to reset the board. Setting this pin low will reset the board. It means that
program memory sets to the starting address. Our code starts from beginning and hardware reset.
3.1.3.4 VIN:
The input voltage supplied to board when it using external power source from 7-20V. The
voltage from external bank can be access through this pin. However, the output voltage to board
is set to 5V automatically.
Arduino and Genuino boards have built in support for serial communication on pins 0 and 1, but
what if you need more serial ports. The SoftwareSerial Library has been developed to allow
serial communication to take place on the other digital pins of your boards, using software to
replicate the functionality of the hardwired RX and TX lines. This can be extremely helpful
when the need arises to communicate with two serial enabled devices, or to talk with just one
device while leaving the main serial port open for debugging purpose.
9
3.1.3.6 LED:
This board contains LED to pin 13. High value to this pin will turn it on and low value to turn it
off.
There are 6 Analog pins on the board named as A0 to A15. All these pins can be used as digital
I/O pins. Each pin has 10-bit resolution.
There are 22 Digitals pins on the board named as D0 to D22. All these pins can be used as digital
I/O pins. Each pin has 10-bit resolution.
is a smallest, complete, and breadboard friendly. It has everything that has (electrically)
with more analog input pins and onboard +5V AREF jumper. Physically, it is missing
power jack. The Nano is automatically sense and switch to the higher potential source
of power, here is no need for Nano’s got the breadboard-ability of the Board uino and
the Mini+USB with smaller footprint than either, so users have more breadboard space.
It’s got a pin layout that works well with the Mini or the Basic Stamp (TX, RX, ATN, GND
on one top, power and ground on the other).This new version 3.0 comes with
ATMEGA328 which offer more programming and data memory space. It is two layers.
10
3.2.1 Specifications:
11
3.3 WIRES:
We are using jumper wires which are simply wires that have property or ability at both ends
Depth 1mm
Width 56mm
12
Figure 3.3: Jumper wires
3.4 CHARGER:
We are using 12v DC output charger. This charger is being provided with 220v AC supply,
which is step down to 12v DC. Since we are using buck converter to provide 4.7v to GSM. Thus
9V DC output of charger is provided to buck converter which is again step down to 4.7v or 4.6v
as required.
13
Figure 3.4: 12v Power Adapter Charger
Output voltage: The output voltage can vary is for our demand. We can take a
Voltage of 1v to 12v and it can be vary by potentiometer. As our demand for GSM
14
Figure 3.5: Buck Converter
3.6 GSM:
GSM originally stood for Group Special Mobile but now means Global System for Mobile
communications. In 1982, Group Spécial Mobile (GSM) was created. Then it was not used
commercialized until 1991.According to World wide mobile communications industry,
approximately 80% of world uses GSM technology. It provides different features as phone call
encryption, data networking, call, SMS etc. GSM works in 1900 MHz band in US while 900
MHz band in Europe and Asia.
Power your GSM by connecting it to Buck converter which providing 4.7v and GND. The
ground pin, we are providing to GSM from Buck converter, should be connected with Arduino
board ground pin. Insert your SIM card to GSM module and lock it. After inserting the SIM in
the GSM the GSM LED will start blinking. Now wait for some time (say 1 minute) and see
15
the LED blinking rate. It will this time for connecting with mobile network. When the GSM
LED blink after every one second it mean there is no connection. The GSM are not connected to
network. If LED would blink after every 3 seconds, it means the GSM is connected to the
network.
16
3.7.1 FEATURES:
17
3.8 LOAD
For load we use 100 watt bulbs.In our our project we use nine bulb.These bulbs represent home
consumption.
18
Figure 3.9: Current Sensor
The graphical LCD utilized in this test depends on KS0108B controller, which is a 128×64 pixel
monochromatic showcase. The KS0108B is a dab grid LCD section driver with 64 channel yield.
Then again, the KS0107B is a 64-channel basic driver which creates the planning sign to control
19
the two KS0108B portion drivers. The KS0108B and KS0107B prominent controller and have
advanced into numerous graphical LCDs.
3.10.1 Description:
WG12864B is a mono 128x64 realistic LCD show, corner to corner size 2.4 inch. WG12864A
model is worked in with NT7108 controller or identical IC; it bolsters 6800 8-piece parallel
interface. This WG12864B 128x64 LCD modules is 5V power stock. In the event that you need
negative voltage 3.3V power supply, if you don't mind pick WG12864BP1. This 12864 Graphic
LCD module is accessible for without backdrop illumination or with LED backdrop illumination
alternatives. WG12864B is accessible in different LCD board hues including dark, yellow/green
and blue LCD choices. This model realistic LCD show can be working at temperatures from -
20℃ to +70℃; its stockpiling temperatures go from - 30℃ to +80℃.
3.10.2 Specification:
20
Figure 3.10: 128x64 LCD display
21
4 METHODOLOGY
4.1 INTRODUCTION:
This chapter will describe how we implement the idea, analyzing data on the consumer side. The easiest
way to identify the illegal consumer is to keep record of his energy consumption after several times in
the hour and compare that data with the main outgoing data on the input side. There are many ways of
communication to send data from one side to the other like using WIFI module to send data on the own
server then on the receiving side download that data from the server and do operations on the data but
the most feasible data technique is to send data by GSM module.
Current
Arduino GSM
Sensor
Consumer data
yes
GSM Arduino cut
Theft
electricity
no
Mian data station
Allow electricity
22
At the consumer side Arduino take data from the current sensor the data is stored in the Arduino
Then Arduino send this data after specific time through GSM to main station. At main station the
data is received from all connections which are made from the transformer as shown in figure 4.2
Current
Arduino GSM
Sensor
Home Connection
Current Current
Arduino GSM GSM Arduino Relay Arduino GSM
Sensor Sensor
Current
Arduino GSM
Sensor
Home Connection
The data is received one by one from each connection, all the data saved in the main station
when the last connection data is received then at main station all connections data summed up
and then the Arduino takes data from the current sensor at the main station and compare that data
removing the loses value on the basis of this comparison it makes decision as shown in Figure
4.1 if the data receives matches the data send it allows the electricity to the transformer if it
doesn’t then it cuts off the electricity.
23
4.3 PROPOSED CODING ARCHITECTURE AT THE
RECEIVING SIDE:
The proposed coding architecture at the receiving side is given in Figure 4.3. The first serial
monitors to show data on the screen and to display all the commands which will be given to the
GSM. One the other side also starting the GSM, then printing the sensor data on the LCD screen
as the GSM started it will also wait for the SMS so if condition is applied here.
24
Figure 4.3: Coding Architecture on the Receiving Side
25
With the IF condition we check whether the SMS is received or not IF the condition is true then
we then the next step is to extract data from the SMS but if the condition is False then we check
the sensor data and display it on the LCD screen and again move to the IF condition. After data
is extracted from the SMS then we convert data from character type to the float type for making
data suitable for calculation. As the calculation is completed the data is saved in the Arduino.
As all the calculation are done the next step is to compare this data with the in sensor data
which was saved and displayed on the LCD before after comparison the next comes which to
take decision if the output data is equal to the input data then connection is allowed but if not
then connection of electricity to the homes are cut out.
Data extraction is one of the important parts of this coding so we discussed it as a separate
26
Figure 4.4: Architecture of data extraction
27
When the SMS is received it is then converted to character array, the SMS is changed to
character array because the id of the individual meters are saved as character. Now the message
is checked one by one by every identity which is saved in the Arduino data. If the message does
not match the saved messages identity then no further operations are done on the message and
the array is reset to zero.
As the message id is once checked and it is matched with the saved meters identity now
further operations are starts, a for loop is applied on the message array which extract the four
digit one by one from the message which the contain the current sensor value at the same time
one by one these characters are converted to integer form at the same time these values are
displayed on the LCD with its following meter id it then shows that how much that home is
consuming current. All the integers are placed together set as unit ten and hundred. As the we
come out of the loop we have the sensor value which then saved and Arduino waits for the next
message to come.
As all the messages arrived the Arduino will do all the operation as discussed above and save the
data. When the last message come to Arduino it takes all the values which come from different
GSM, sum all the values make one output value and goes for calculation now at that time
Arduino also takes current sensor value on the input side and then we have IF condition applied
here if the input/output are same then the Arduino will allow the current to flow if not it will
block by the relay.
28
5 RESULTS AND RECOMMENDATIONS
5.1 RESULTS:
In our project we make different test on electricity theft. For this purpose we made different
kinds of load or home consumption. We have three kinds of load or home consumption, two of
them of are legal home consumption and one is illegal home consumption.
When the current flows and legal home consumption use it so there will no theft occurs, this
decision occurs in main station and when the illegal home use the current so the theft will occurs
and the electricity will stop from the main station through all home consumption. In every home
we connect three 100 Watt bulbs in parallel and the combine bulbs consume 1 ampere current.
The main station will take the decision to stop or allow the current on the basis of current values
which is send by the individual homes to the main station. The below table show the different
values of home consumption.
In the above case when the current flow individuals homes and the consumption are legal homes
and the current values are not greater from two ampere, there will be no electricity theft.
29
Table 5.2: Illegal use of electricity
There is no use of legal user but only illegal users are using the electricity. In this case the main
station is not receiving values from those homes which are connected to current sensors. Those
home are legal which is connected to the current sensor. In this case the legal home1 and home2
current sensors are not sending the consumption values to the main station and still there is the
consumption of electricity. The main station will detect the electricity theft and take action to
prevent the current supply to homes.
5.2 RECOMMENDATIONS:
In our project we used GSM for sending values from consumption to the comparing
unit but GSM is not proper module for it. A lot of problems in GSM.
GSM operating voltage problem, weak signal problem problems. For sending data
there should be use another modules.
Foe advancement internet of thing can also be use in the project, it will facilitate the
consumer easily their consumed unit will send to it and also show the electricity
theft.
Do not use WIFI module because it will send your data but you cannot received it.
30
6 ENVIRONMENTAL EFFECT
We are encompassed by innovation, development and bliss. Electricity is one of the best
mechanical advancements of mankind. It has now turned into a piece of our day by day life and
one can't think about a world without electricity. Before finding it, individuals have been living
for quite a long time without it, which you could envision added to one dull world during the
evening except for a light here and there. Nevertheless, despite the fact that people have made
due without it. This is because of improvement and development that was conceivable because
of the generation of power. The minute the thought was displayed to the world that electricity
could be made and life into the world, was the minute that everything changed.
It isn't just used to switch on the lights in your home and enable you to helpfully cook, clean and
approach your day or work as you would typically today, yet it likewise includes supporting of a
variety of enterprises, which one of the greatest incorporates innovation. On the off chance that
the possibility of power and the way toward making it didn't happen, there wouldn't have been
any innovation and life would remain the same. Starting with your home, power is significant for
working all apparatuses, diversion, lighting and obviously, all innovation.
With regards to voyaging, power is significant for the utilization of electric trains, planes and
even a few vehicles.
In the event that you consider offices, for example, schools, therapeutic offices, for example,
emergency clinics and retail offices, all need power to run proficiently. With regards to the
medicinal field, power takes into consideration the accessibility of X-Rays, ECG's and moment
31
results in regards to blood tests, just as whatever else. It takes into account a progressively
effective medicinal practice in these offices. Power is likewise significant for the reason and
activity of machines, for example, PCs or screens that show information to improve prescription.
Without power, clinics and medication would not have the option to be progressed and fix
sicknesses, which would likewise bring about more setbacks.
32
7 REFERENCES
[1] N. S. T, “Wireless Power Theft Monitoring System Using Zigbee,” vol. 1, no. 5, pp. 144–
147, 2017.
[2] P. Antmann, “Reducing technical and non-technical losses in the power sector.,” Backgr.
Pap. World Bank Gr. Energy Sect. Strateg., no. July 2009, pp. 1–35, 2009.
[3] “1117810.” .
[4] “867318.” .
[5] “0000000290_power theft detection.” .
[6] A. Kamble, M. Torane, and P. D. M. A, “Electricity Theft Detection Using Zigbee,” pp.
2494–2497, 2018.
[7] M. I. Hussain, “Embedded prepaid energy meter system to control electricity,” Int. J.
Recent Trends Eng. Res., vol. 4, no. 4, pp. 26–30, 2018.
[8] K. Lacommare and J. H. Eto, “Ernest Orlando Lawrence Cost of Power Interruptions to
Electricity Consumers in the United States,” Energy, vol. 31, no. 12, pp. 1845–1855,
2006.
[9] T. B. Smith, “Electricity theft: A comparative analysis,” Energy Policy, vol. 32, no. 18,
pp. 2067–2076, 2004.
33
8 APPENDIX
8.1 APPENDIX A:
#include "U8glib.h"
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
U8GLIB_ST7920_128X64 u8g (13, 11, 10, U8G_PIN_NONE );
double Voltage = 0;
int intpart = 0;
double VRMS = 0;
float AmpsRMS = 0;
34
void draw(void)
{
//u8g.setFont(u8g_font_helvR08);
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(0,19);
u8g.print("Home 1 Current=");
u8g.drawStr(95,19, h1_string);
u8g.drawHLine(0,1+19,128);
u8g.setPrintPos(0,29);
u8g.print("Home 2 Current=");
u8g.drawStr(95,29, h2_string);
u8g.drawHLine(0,1+29,128);
u8g.setPrintPos(0,40);
u8g.print("Home 3 Current=");
u8g.drawStr(95,40, h3_string);
u8g.drawHLine(0,1+40,128);
u8g.setPrintPos(0,52);
u8g.print("Input Current =");
u8g.drawStr(95,52, in_string);
u8g.drawHLine(0,1+52,128);
u8g.setPrintPos(0,62);
u8g.print("Output Current=");
u8g.drawStr(95,62, out_string);
u8g.drawHLine(0,1+62,128);
35
void restbuffer(){
}
void setup(void)
{
//u8g.setFont(u8g_font_unifont); // 12 pixels high
u8g.setColorIndex(1); // BW display
Serial.begin(19200);
SIM900.begin(19200);
delay(1000);
Serial.print("SIM900 ready...");
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(illegalpin, INPUT);
void loop()
{
u8g.firstPage();
do {
if(SIM900.available()>0)
36
{
textMessage = SIM900.readString();
if (textMessage.indexOf("+923005654761") > 0)
textMessage.toCharArray(buf, 200);
Serial.print(textMessage);
// u8g.drawStr(35,35, textMessage);
delay(10);
n=0;
i=0;
r=0;
for( n=49;n<=53;n++){
val[i]=buf[n];
Serial.print(val[i]);
u8g.setPrintPos(35,35);
u8g.print(val); i++;
if(n==51)x = atof(val);
if(n==52)y = atof(val);
if(n==53)
if(n==53)z = atof(val);
r=x*100+10*y+z;
Serial.println();
Serial.print("the value of integer x = ");
Serial.print(x);
37
//dtostrf(x, 3, 1, sms_string);
Serial.println();
Serial.print("the value of integer y = ");
Serial.print(y);
Serial.println();
Serial.print("the value of integer z = ");
Serial.print(z);
Serial.println();
Serial.print("the value of integer r = ");
Serial.print(r);
dtostrf(r, 3, 1, h1_string);
cal(r); r=0;
}
r=0;i=0;
}
n=0;
restbuffer();
textMessage="";
}
textMessage.toCharArray(buf, 200);
Serial.print(textMessage);
// u8g.drawStr(35,35, textMessage);
delay(10);
n=0;
i=0;
r=0;
38
for( n=49;n<=53;n++){
val[i]=buf[n];
Serial.print(val[i]);
u8g.setPrintPos(35,35);
u8g.print(val); i++;
if(n==51)x = atof(val);
if(n==52)y = atof(val);
if(n==53)
if(n==53)z = atof(val);
r=x*100+10*y+z;
Serial.println();
Serial.print("the value of integer x = ");
Serial.print(x);
//dtostrf(x, 3, 1, sms_string);
Serial.println();
Serial.print("the value of integer y = ");
Serial.print(y);
Serial.println();
Serial.print("the value of integer z = ");
Serial.print(z);
Serial.println();
Serial.print("the value of integer r = ");
Serial.print(r);
dtostrf(r, 3, 1, h2_string);
cal(r); r=0;
}
39
r=0;i=0;
}
n=0;
restbuffer();
textMessage="";
}
if (textMessage.indexOf("+923109806771") > 0)
textMessage.toCharArray(buf, 200);
Serial.print(textMessage);
// u8g.drawStr(35,35, textMessage);
delay(10);
n=0;
i=0;
r=0;
for( n=49;n<=53;n++){
val[i]=buf[n];
Serial.print(val[i]);
u8g.setPrintPos(35,35);
u8g.print(val); i++;
if(n==51)x = atof(val);
if(n==52)y = atof(val);
if(n==53)
if(n==53)z = atof(val);
40
r=x*100+10*y+z;
Serial.println();
Serial.print("the value of integer x = ");
Serial.print(x);
//dtostrf(x, 3, 1, sms_string);
Serial.println();
Serial.print("the value of integer y = ");
Serial.print(y);
Serial.println();
Serial.print("the value of integer z = ");
Serial.print(z);
Serial.println();
Serial.print("the value of integer r = ");
Serial.print(r);
dtostrf(r, 3, 1, h3_string);
cal(r); r=0;
}
r=0;i=0;
}
n=0;
restbuffer();
textMessage="";
}
41
else
{
textMessage="";
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707
AmpsRMS = (VRMS * 1000)/mVperAmp;
//dtostrf(intpart, 3, 0, in_string);
Serial.println();
Serial.print("SENSOR VAULE IS ");
Serial.println(intpart);
Serial.print("STATE IS ");
Serial.print(relaystate);
draw();
} while ( u8g.nextPage() );
42
void cal(int d){
Serial.println();
Serial.println("d val= ");
Serial.print(d);
sum=sum+d;
//dtostrf(sum, 3, 0, sum_string);
relay();
if ( sum == intpart )
{
//digitalWrite(relay1, LOW);
relaystate = 1 - relaystate;
if (relaystate = 0)
{
digitalWrite(relay1, LOW);
}
else
{
digitalWrite(relay1, HIGH);
43
out.toCharArray(out_string,5);
sum=0;
s=0;
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
44
// Subtract min from max
result = ((maxValue - minValue) * 5.0)/1024.0;
return result;
}
void relay()
{
if (sum != intpart)
{
relaystate = 1 - relaystate;
if (relaystate == 1)
{
digitalWrite (relay1, LOW);
if (relaystate==0)
digitalWrite(relay1, HIGH);
if (sum == intpart)
{
45
relaystate = 1;
if (relaystate == 1)
{
digitalWrite (relay1, LOW);
digitalWrite (relay2, LOW);
digitalWrite (relay3, LOW);
}
}
if (sum != intpart)
{
do{
if (relaystate == 0)
46
digitalWrite (relay1, HIGH);
digitalWrite (relay2, HIGH);
digitalWrite (relay3, HIGH);
}
illegalstate = 0;
relaystate = 0;
if (relaystate == 0)
{
digitalWrite (relay1, HIGH);
digitalWrite (relay2, HIGH);
digitalWrite (relay3, HIGH);
}
}
}
void check()
{
illegalstate = digitalRead (illegalpin);
if (illegalstate == HIGH )
{
relaystate = 0;
47
if (relaystate == 0)
{
digitalWrite (relay1, HIGH);
digitalWrite (relay2, HIGH);
digitalWrite (relay3, HIGH);
}
if (illegalstate == LOW)
{
relaystate = 1;
if (relaystate == 1)
{
digitalWrite (relay1, LOW);
digitalWrite (relay2, LOW);
digitalWrite (relay3, LOW);
}
}
}
48
8.2 APPENDIX B:
#include <SoftwareSerial.h>
const int sensorIn = A0;
int mVperAmp =66 ; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
void setup() {
// Arduino communicates with SIM900 GSM shield at a baud rate of 19200
// Make sure that corresponds to the baud rate of your module
Serial.begin(19200);
GSM.begin (19200);
// Give time to your GSM shield log on to network
delay(20000);
void loop() {
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707
AmpsRMS = (VRMS * 1000)/mVperAmp;
Serial.print(AmpsRMS
49
);
Serial.println(" Amps RMS");
if (GSM.available())
Serial.write (GSM.read());
}
if (Serial.available())
{
GSM.write(Serial.read());
}
}
void sendSMS() {
for (int i =0;i<50;i++)// here by changing i value wwe change the number of sms
{
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707
AmpsRMS = (VRMS * 1000)/mVperAmp;
GSM.print("AT+CMGF=1\r");
delay(100);
GSM.println(AmpsRMS);
delay(100);
GSM.println((char)26);
50
delay(100);
GSM.println();
delay(15000);
}
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
return result;
}
51