Overview
In this project, we will make a GSM Based Prepaid Electricity Energy Meter using Arduino. Prepaid Electricity Energy Meter is one of the best concepts for the current electricity payment system. In this system, you can recharge the device and update the balance as we do on our mobile phones.
By sending a simple SMS, you can recharge the electricity balance through this system. It can also disconnect the home power supply connection if there is a low or zero balance in the system. And this system will read the energy meter readings and automatically send some updates to the user’s mobile phone like low balance alert, cut off alert, resume alert and recharge alert. The Anti-Theft Alert can also be detected when someone tries stealing the meter by opening the lid. So, let us see how we can build this project.
There is an advance version of this project based on Internet of Thing, which you may look into:
1. IoT AC Energy Meter using Old Blynk
2. IoT AC Energy Meter using New Blynk
3. IoT DC Energy Meter
Bill of Materials
Following is the list of materials that you need to make an Arduino & GSM Based Prepaid Energy Meter. You can purchase all the components from the following link.
| S.N. | Components | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino UNO Board | 1 | Amazon | AliExpress |
| 2 | SIM800/900 GSM Module | 1 | Amazon | AliExpress |
| 3 | Single Channel Relay | 1 | Amazon | AliExpress |
| 4 | 16x2 I2C LCD Display | 1 | Amazon | AliExpress |
| 5 | Micro Limit Switch | 1 | Amazon | AliExpress |
| 6 | 5V Buzzer | 1 | Amazon | AliExpress |
| 7 | Optocoupler IC 4N35 | 1 | Amazon | AliExpress |
| 8 | Energy Meter | 1 | Amazon |
| 9 | 10K Resistor | 1 | Amazon | AliExpress |
| 10 | Zero PCB | 1 | Amazon | AliExpress |
| 11 | 9V Power Adapter | 1 | Amazon | AliExpress |
Hardware Setup & Circuit Diagram
The circuit diagram for GSM Based Prepaid Energy Meter is very simple. The Analog Electricity Energy Meter input terminal connects to 220V AC Power Supply. Its output terminal connects to the output of the single-channel Relay Module. All the loads for electricity also connect to the Relay as shown in the circuit.
The 16×2 I2C LCD Display connects to the I2C Pins of the Arduino UNO Board. We have used SIM800 GSM Module for GMS SMS functions which is the most important part of this project. The GSM has UART Pin as Tx & Rx which connects via Software Serial to digital pins 11 and 12 of Arduino. The GSM Module requires 9V Power Supply. So an external 9V DC power supply like DC Power Adapter can be used. Hence the GSM and Arduino both are powered via 9V DC Adapter.
The Relay, Buzzer, and Limit Switch are connected to D8, D7 & A0 of Arduino. Remember to take precautions as this circuit is dangerous due to AC Mains.
As shown here, you can assemble the circuit in a combined board. The top of the board has only the analog meter and LCD Display. Inside the box, the Arduino Board, GSM Module, Relay, and 4N35 Optocoupler IC are placed together. The Limit switch is placed at the opening of the meter door. It is used to check whether the box is opened or not and can prevent theft.
In this project, you can connect anything to the load such as Fan, Bulb, Heater, and everything that you use at home. To test this system you can connect the whole device directly to the 220V AC power supply.
How to Connect the Analog Meter to Arduino
The most important thing is how do you connect the meter to the Arduino. For this open the meter first. At the back of the meter, there is a Pulse LED or Cal LED terminals which are basically cathode and Anode.
You need to solder two wires to these terminals. After these, connect the anode & cathode terminal of the LED at pin number 1 and pin number 2 of the optocoupler. Now, this optocoupler is connected to digital pin D2 of Arduino.
Project PCB Gerber File & PCB Ordering Online
If you don’t want to assemble the circuit on a breadboard and you want PCB for the project, then here is the PCB for you. I used EasyEDA to design the PCB & Schematic. The Schematic & PCB Board for Prepaid Energy Meter looks something like the below.
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.
You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
You can assemble the components on the PCB Board.
Source Code/program: Arduino GSM Prepaid Energy Meter
The complete program for GSM Based Prepaid Energy Meter using Arduino is given below. The code is mostly formatted for GSM AT Commands to recharge and test the system along with output feedback messages.
|
1 2 |
String phone_no1 = "+91xxxxxxxxxx"; String phone_no2 = "+91xxxxxxxxxx"; |
You need to make changes to the above lines in this code. Replace the mobile number in the following lines of the code with the number you want the SMS to send.
You can copy the code and upload it to the Arduino Board.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
#include <EEPROM.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); #include <SoftwareSerial.h> SoftwareSerial GSM(10, 11); #define buzzer 7 #define relay 8 #define bt_theft A0 #define pulse_in 2 char inchar; int unt_a = 0, unt_b = 0, unt_c = 0, unt_d = 0; long total_unt = 7; int price = 0; long price1 = 0; int Set = 10; int pulse = 0; String phone_no1 = "+91xxxxxxxxxx"; String phone_no2 = "+91xxxxxxxxxx"; int flag1 = 0, flag2 = 0, flag3 = 0; void setup() { Serial.begin(9600); GSM.begin(9600); pinMode(bt_theft, INPUT_PULLUP); pinMode(relay, OUTPUT); pinMode(buzzer, OUTPUT); pinMode(pulse_in, INPUT); attachInterrupt(0, ai0, RISING); lcd.begin(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("WELCOME"); lcd.setCursor(2, 1); lcd.print("Energy Meter"); digitalWrite(buzzer, HIGH); Serial.println("Initializing...."); initModule("AT", "OK", 1000); initModule("ATE1", "OK", 1000); initModule("AT+CPIN?", "READY", 1000); initModule("AT+CMGF=1", "OK", 1000); initModule("AT+CNMI=2,2,0,0,0", "OK", 1000); Serial.println("Initialized Successfully"); delay(100); sendSMS(phone_no1, "Welcome To Energy Meter"); digitalWrite(buzzer, LOW); lcd.clear(); if (EEPROM.read(50) == 0) {} else { Write(); } EEPROM.write(50, 0); pulse = EEPROM.read(10); Read(); if (total_unt > 0) { digitalWrite(relay, HIGH); } } void loop() { if (GSM.available() > 0) { inchar = GSM.read(); if (inchar == 'A') { delay(10); inchar = GSM.read(); if (inchar == 'T') { delay(10); inchar = GSM.read(); if (inchar == 'r') { delay(10); inchar = GSM.read(); if (inchar == 'e') { delay(10); inchar = GSM.read(); if (inchar == 'c') { delay(10); inchar = GSM.read(); if (inchar == 'h') { delay(10); inchar = GSM.read(); if (inchar == '1') { price = 100 / Set; total_unt = total_unt + price; sendSMS(phone_no1, "Your Recharge is Done: 100"); sendSMS(phone_no2, "Your Recharge is Done: 100"); load_on(); } else if (inchar == '2') { price = 200 / Set; total_unt = total_unt + price; sendSMS(phone_no1, "Your Recharge is Done: 200"); sendSMS(phone_no2, "Your Recharge is Done: 200"); load_on(); } else if (inchar == '3') { price = 300 / Set; total_unt = total_unt + price; sendSMS(phone_no1, "Your Recharge is Done: 300"); sendSMS(phone_no2, "Your Recharge is Done: 300"); load_on(); } else if (inchar == '4') { price = 400 / Set; total_unt = total_unt + price; sendSMS(phone_no1, "Your Recharge is Done: 400"); sendSMS(phone_no2, "Your Recharge is Done: 400"); load_on(); } delay(10); } } } } } } else if (inchar == 'D') { delay(10); inchar = GSM.read(); if (inchar == 'a') { delay(10); inchar = GSM.read(); if (inchar == 't') { delay(10); inchar = GSM.read(); if (inchar == 'a') { Data(); } } } } } lcd.setCursor(0, 0); lcd.print("Unit:"); lcd.print(total_unt); lcd.print(" "); lcd.setCursor(0, 1); lcd.print("Price:"); lcd.print(price1); lcd.print(" "); lcd.setCursor(11, 0); lcd.print("Pulse"); lcd.setCursor(13, 1); lcd.print(pulse); lcd.print(" "); if (total_unt == 5) { if (flag1 == 0) { flag1 = 1; digitalWrite(buzzer, HIGH); sendSMS(phone_no1, "Your Balance is Low Please Recharge"); digitalWrite(buzzer, LOW); } } if (total_unt == 0) { digitalWrite(relay, LOW); if (flag2 == 0) { flag2 = 1; digitalWrite(buzzer, HIGH); sendSMS(phone_no1, "Your Balance is Finish Please Recharge"); digitalWrite(buzzer, LOW); } } if (digitalRead (bt_theft) == 0) { if (flag3 == 0) { flag3 = 1; sendSMS(phone_no2, "Theft Alarm"); } } else { flag3 = 0; } delay(5); } void load_on() { Write(); Read(); digitalWrite(relay, HIGH); flag1 = 0, flag2 = 0; } void sendSMS(String number, String msg) { GSM.print("AT+CMGS=\""); GSM.print(number); GSM.println("\"\r\n"); delay(500); GSM.println(msg); delay(500); GSM.write(byte(26)); delay(5000); } void Data() { GSM.print("AT+CMGS=\""); GSM.print(phone_no1); GSM.println("\"\r\n"); delay(1000); GSM.print("Unit:"); GSM.println(total_unt); GSM.print("Price:"); GSM.println(price1); delay(500); GSM.write(byte(26)); delay(5000); } void Read() { unt_a = EEPROM.read(1); unt_b = EEPROM.read(2); unt_c = EEPROM.read(3); unt_d = EEPROM.read(4); total_unt = unt_d * 1000 + unt_c * 100 + unt_b * 10 + unt_a; price1 = total_unt * Set; } void Write() { unt_d = total_unt / 1000; total_unt = total_unt - (unt_d * 1000); unt_c = total_unt / 100; total_unt = total_unt - (unt_c * 100); unt_b = total_unt / 10; unt_a = total_unt - (unt_b * 10); EEPROM.write(1, unt_a); EEPROM.write(2, unt_b); EEPROM.write(3, unt_c); EEPROM.write(4, unt_d); } void initModule(String cmd, char *res, int t) { while (1) { Serial.println(cmd); GSM.println(cmd); delay(100); while (GSM.available() > 0) { if (GSM.find(res)) { Serial.println(res); delay(t); return; } else { Serial.println("Error"); } } delay(t); } } void ai0() { if (digitalRead(pulse_in) == 1) { pulse = pulse + 1; if (pulse > 9) { pulse = 0; if (total_unt > 0) { total_unt = total_unt - 1; } Write(); Read(); } EEPROM.write(10, pulse); } } |
Project Working & Demonstration
When you power on the device, the LCD will display the unit, pulse, and price as zero.
Now we need to send an SMS to operate this device. Before that, we need to recharge this meter as there is no money to operate this device. You can recharge 100, 200, 300 & 400 at a single time. With the recharged money the electricity load will always be active as long as the amount doesn’t reach to zero.
To recharge with 100 balance, type ATrech1 & send. Here 1 means 100. If you want to recharge it with 200 simply replace 1 with 2. You will get a feedback message as an SMS that says “recharge is done”. The LCD will also display the same. Immediately the load will turn on.
As long as the pulse LED blinks, the counting goes on and the pulse count is displayed on LCD Screen. Also, there is a deduction in the recharged amount. We also set the limit to 60. As the amount goes to 60, the GSM will send an SMS saying the balance is low and you need to recharge it again. So basically, it’s an indication as well as a warning.
When the power consumption increases and the price goes further down till the amount reaches zero. In this instance, the load will turn off and there is an electricity cut-off. You will receive an SMS saying the balance is finished and you need to recharge it again.
So you can recharge again. A similar process continues again and again.
This process continues even after there is a power cut. This is because the last pulse count and price value are stored in the EEPROM of the microcontroller.























5 Comments
Hello sir i face a problem in uploading the program
Its show’s error
Did you got solution for the errors
Did you got the solution for your errors.
Please provide report on this project
What is the name of the software to simulate the project.