Usually the households have post paid electricity connections. On the consumer side, post paid connections have drawback that the consumption of electricity is not tracked by the consumers and many times they are shocked, when they receive high bills. The cause of getting high bills is usually not the high electricity rates but is the unconscious overuse of electricity. Prepaid electricity connections are usually suggested as the viable solution to this problem. In a prepaid electricity connection, consumer would need to recharge the amount of electricity they want to consume. In such a system, the household electricity meters need to be equipped with a system that could be acknowledged of the amount recharged by the consumer and could count down the electricity consumption from the recharged amount to zero. Once the meter reaches zero, the main supply would be automatically cut off and could be resumed only after the next recharge.
This project is an attempt to realize a similar system. In this project a circuit is designed that would work as electricity recharge station and an additional circuit is designed that could integrate with the regular household energy meters and capable of counting down energy usage and cut off the main supply once the energy usage countdown reaches zero. A memory stick is used as an alternative to smart card which will store the recharge information from the recharge station and could be plugged to the circuit integrated to energy meters for regulating main supplies.
Fig. 1: Prototype of Arduino based Prepaid Electricity Recharge Station
The recharge station will also send a confirmation message to the registered mobile number of the consumer on every recharge. The recharge station and prepaid energy meter are shown connected to each via RF module in the project so that prepaid energy meter could send an alert of exhausting recharge amount to the recharge station and the recharge station could send an SMS to the consumer to make a recharge soon again. Therefore, from hardware perspective, this prepaid electricity system consist of the following devices –
1) Electricity Recharge Station – An embedded device that could write recharge information to a memory system. For simplicity, the memory system used is a memory chip. A commercial version of the system realized here can have smart cards for facilitating electricity recharges. The recharge station also uses a GSM/GPRS module to send a confirmation message on every successful recharge and is connected to the prepaid energy meter via RF module to receive alert of exhausting recharge amount and the station could send an SMS to recharge soon. A commercial version of the system can have recharge station and prepaid energy meter connected via internet. Alas, currently internet is neither available at all places nor is it free to provide such feature in a commercial avatar of such system.
2) Smart device to store recharge amount – The project uses a memory stick to demonstrate functioning of a smart recharge device. A commercial version of the system can have smart cards instead.
3) Prepaid Energy Meter – An embedded device that could integrate with regular household meters for reading recharge amount and tracing energy consumption in a descending order until it reaches zero. The device is made capable to cut off the main supplies by regulating the main supplies through a relay circuit.
In the project electricity recharge station is built on Arduino UNO and prepaid energy meter is built around Arduino Mega. The memory stick used as alternative to the smart recharge card is AT2402. The AT2402 is 2Kb memory stick that connects with any microcontroller on I2C interface. The Arduino IDE is used to write the Arduino sketches for recharge station and prepaid energy meter and AVR Dude is utilized to burnt program codes to the microcontroller boards.
Components Required –
For building recharge station, following components will be required –
• Arduino UNO
• GSM module
• HT12D
• 433 KHz RF module
• 4-Switch keypad
• LCD
• 7805/7812 voltage regulators.
• Transformer 12-0,2Amp
• 1K ohm resistors
• 47K ohm resistor
• IN4007 Diode
• 4700uF,25V capacitor
• Electrical wire
• Two pin plug
The AT2402 memory stick is used as the smart recharge device. For building prepaid energy meter, following components will be required –
• Arduino Mega
• LCD
• Encoder- HT12E
• 433KHz RF module
• 3200 imp/kwh Energy Meter
• LM358 comparator
• LED
• 12v Relay
• BC547 transistor
• IN4007 diode
• 1k ohm Resistors
• 1M ohm resistor
• Load to test
• Terminal Block
• Electrical wire
• Two pin Plug
Block Diagram
Fig. 2: Block Diagram of Arduino based Prepaid Electricity Recharge Station
Circuit Connections
Recharge Station
The recharge station is built on Arduino UNO. It has an LCD display and a 4-switch keypad for human interaction. The memory card storing the recharge information can connect to the Arduino board via I2C protocol implemented on A4 and A5 pins of the Arduino. The board is connected to a GSM module for sending confirmation SMS of successful recharges and alert messages for next recharge. The board is interfaced to RF receiver circuit so that it could connect with the prepaid energy meter and detect low energy balance. The circuit working as recharge station has different components and modules connected to Arduino board in the following manner –
16X2 LCD display – The LCD display is used to provide an interface for human interaction and it displays messages guiding the user to recharge electricity usage. It is connected to the Arduino board by connecting its data pins to pins 3 to 6 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino UNO respectively. The RW pin of the LCD is grounded.
Fig. 3: Table listing circuit connections between Arduino Uno and Character LCD
The standard open-source library for interfacing LCD with Arduino UNO is used in the project. The library works as expected and needs no changes or modifications.
4-Switch Keypad – The tactile switches are used to form the keypad. There are four switches in the keypad that are connected to the following pins with given functions assigned to them –
Fig. 4: Table listing Arduino pins and their functions in Prepaid Electricity Recharge Station
The switches are connected between ground and the Arduino pins. The Arduino pins by default are connected to VCC and receive HIGH logic. On pressing a tactile switch, the respective Arduino pin gets short-circuited to ground and receives a LOW logic.
GSM Module – The GSM module has four pins – Tx, Rx, Vcc and GRND. The Tx and Rx pins are connected to the pin number 9 and 10 of Arduino UNO respectively. The pins 9 and 10 are declared as the virtual serial port in Arduino sketch to communicate data with the module. The VCC and Ground pins of the module are connected to 5V DC and GRND pin of the Arduino UNO board. An external power supply of 18V is used to power the GSM module.
RF Receiver – The RF receiver is used to get an alert of low energy balance from the prepaid energy meters. The RF receiver module has 8 pins and has following pin configuration –
Fig. 5: Table listing pin configuration of RF Receiver
The serial data output of the RF receiver is connected to pin 16 of the HT12D decoder IC.
HT12D decoder IC – The signal carrying low energy balance alert is detected by the RF receiver and is passed to the HT12D decoder. It converts the serial data back to the parallel data after separating data and addresses. HT12D belongs to the 212 series of decoders and can be paired with 212 series of encoders having the same number of addresses and data format. HT12D is capable of decoding 12 bits, out of them 8 are address bits and 4 are data bits. The address byte of the decoder IC should be same as of the encoder IC to match the transmitter and receiver circuits. In the project, address byte of both the receiver and transmitter modules is set to 0x00. A 47 KΩ resistor is connected between the pins 14 and 15 of the decoder IC to match the RF frequency. The pin 17 is called valid transmission and has an LED connected to it through 1 KΩ resistor to indicate if the RF transmitter on the Prepaid Energy Meter is paired with the receiver or not. Only the D0 data bit of the decoder is tracked to detect the alert signal. The D0 bit of the decoder IC is connected to the pin 7 of Arduino UNO.
External EEPROM – AT24C02 is the external EEPROM used as the smart recharge device. The 8-pin IC has the following pin configuration –
Fig. 6: Table listing pin configuration of AT24C02 External EEPROM
The pins 5 and 6 of the EEPROM IC connect to the A4 and A5 pins of the Arduino where A4 is configured to SDA and A5 is configured to SCL. The pins 1, 2 and 3 of the EEPROM IC are connected to ground as at any time the recharge station will have only single EEPROM plugged in. The pins are used for addressing individual EEPROMs when multiple EEPROMs connect to a single microcontroller at the same time.
Power Supply – A step down transformer is used to convert 230v AC to 18v AC and by using a full bridge rectifier and capacitor it is converted to 18V DC. This 18V DC is converted to 12v DC using a 7812 voltage regulator and is supplied to the Vin pin of Arduino UNO board. The 18V DC is provided to the GSM module. All the other ICs and modules are powered by 5V DC from the Arduino board.
Smart Recharge Device
The AT24C02 EEPROM IC serves as the smart recharge device in the project. For simplicity, it is used as an alternative to the smart cards. The EEPROM IC stores the recharge information and is pluggable to the recharge station and the prepaid energy meter.
Prepaid Energy Meter
The circuit developed should connect between the loads and neutral output of a regular electricity meter. When a load will be switched ON and start consuming electricity, current will also pass through the prepaid energy meter device. The device will have an LDR circuit assembly to detect electricity consumption by detecting blink of Imp / kWh LED on front panel of Electronic Energy Meter and will drive a relay circuit to cut off the supply from neutral wire end once the recharge energy usage balance is exhausted. The device will have slot to plug in EEPROM to read and decrease recharge balance and have an LCD display to show current energy usage balance decreasing with the energy consumption. The device has an RF transmitter circuit to connect with the recharge station for sending the alert of low usage balance remaining. The circuit is built on Arduino Mega and has different components and modules connected to the board in the following manner –
16X2 LCD display – The LCD display is used to show remaining energy usage balance. It is connected to the Arduino board by connecting its data pins to pins 3 to 6 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino UNO respectively. The RW pin of the LCD is grounded.
Fig. 7: Table listing circuit connections between Arduino Uno and Character LCD
The standard open-source library for interfacing LCD with Arduino MEGA is used in the project. The library works as expected and needs no changes or modifications.
External EEPROM – The external EEPROM will be plugged to the device and connects with the Arduino MEGA on two-wire interface. The pins 5 and 6 of the EEPROM IC connect to the pin 20 and 21 of the Arduino Mega respectively where pin 20 of the board is configured to SDA and pin 21 is configured to SCL.
Relay Circuit – A 12V 2A relay will be used to control the main supplies. The loads will be connected between the phase wire and the NO pin of the relay. The neutral wire will connect back to a regular electricity meter through the COM point. When the energy usage balance will be exhausted, the microcontroller will send a HIGH logic to the BC547 switching transistor circuit. The transistor circuit will short circuit one of the coil end to ground while the other coil end is provided 12V supply tripping the relay to NC point.
LDR sensor – The LDR sensor will be placed in an assembly before the Imp / kWh LED of the front panel of regular EEM. An LDR sensor changes its resistance according to the light intensity. When light falls on LDR, its resistance remains low while when there is absence of light its resistance is high. The LDR sensor is connected to non-inverting pin 2 of LM358 voltage comparator while voltage at inverting pin 3 of LM358 is passed via a variable resistance. The Imp / kWh LED of the front panel of EEM blinks t a certain number of times according to impulse/KWH rating when the electricity consumption read by the meter crosses 1KWH each time . By default, the LDR has low resistance and but when the Imp / kWh LED of the front panel of EEM blinks, its resistance is increased. The difference between the inverting and non-inverting voltage is passed from the output pin 1 of the comparator to analog pin A0 of the Arduino.
RF transmitter – The RF transmitter will be used to transmit alert message of low energy balance to the receiver circuit. The RF transmitter module is a small PCB sub assembly. The pin configuration of transmitter module is as follows-
Fig. 8: Table listing pin configuration of RF Transmitter
The serialized data from encoder is received at pin 2 of the module and passed on to the antenna from pin 4 of the module.
HT12E IC – The HT12E IC converts the parallel data into serial data for passing it to the RF transmitter. HT12E encoder IC belongs to the 212 series of encoders. It is paired with 212 series of decoders having the same number of addresses and data format. HT12E is capable of encoding 12 bits, out of them 8 are address bits and 4 are data bits. Thus the encoded signal is a serialized 12-bit parallel data comprising of 4-bit data to be transferred appended with the address byte. To set the oscillator frequency, a resistor from 1MΩ is connected between pin 15 and 16 of the HT12E encoder IC. Only D0 data bit of encoder needs to be used for sending alert of low energy balance to the recharge station. Therefore, the D0 bit of the encoder IC is connected to the pin 7 of Arduino MEGA.
Power Supply – A step down transformer is used to convert 230v AC to 18v AC and by using a full bridge rectifier and capacitor it is converted to 18V DC. This 18V DC is converted to 12V DC using a 7812 voltage regulator and is supplied to the Vin pin of Arduino UNO board and the relay. The 18V DC is converted to 5V DC using 7805 voltage regulator which is supplied to rest of the components.
How the project works
A consumer first needs to make an energy recharge. He has the EEPROM IC as the smart energy recharge device. For making the recharge, he has to plug in the memory card to Recharge Station and press button interfaced to A2 pin of Arduino UNO. On pressing the button, consumer will be prompted to select a recharge amount by flashing messages on the LCD screen. There will be seven recharge packages available worth 2, 5, 7, 9, 12, 15 and 17 rupees. The consumer can navigate to ascending order of recharge packages by pressing button connected to A1 pin of Arduino UNO while can navigate to descending order of recharge packages by pressing button connected to A0 pin of Arduino UNO. Once navigating to a desired recharge package, consumer can confirm recharge by pressing button connected to A3 pin of the Arduino UNO. As the user presses the button connected to A3 pin of Arduino UNO, the recharge amount is saved to location 1 on address B01010000 on EEPROM and the units of electricity recharged in the terms of number of blinks of the Imp / kWh LED of the front panel of EEM are saved. A message is sent to the consumer confirming the recharge information using the GSM module.
The consumer needs to plug out the memory card and carry it to plug in the prepaid energy meter. Once the memory card is plugged in the prepaid energy meter, the Arduino MEGA controlling meter circuit reads the recharge amount from EEPROM and resumes the power supply by switching the relay. The recharge balance is shown on the LCD panel of the prepaid energy meter. The available electricity consumption is calculated by the number of blinks by the Imp/KWH LED of the EEM. The Arduino Mega waits for the blink of Imp / kWh LED of the front panel of EEM and on every blink compares the detected analog voltage at its A0 pin which is converted to a digital measure with a calibrated value. The calibrated value for comparison with the value from ADC was set to 300 during project testing. Whenever Imp / kWh LED of the front panel of EEM blinks, the resistance of LDR is increased in the potential divider circuit increasing the non-inverting voltage and greater voltage is detected from pin 1 of the LM358 comparator IC. So, as the voltage detected and digitized from A0 of Arduino MEGA exceeds the reference value 300, a single blink of Imp / kWh LED of front panel of EEM is recorded and a variable in the program code holding the number of recharged units in the form of number of blinks or pulses is decremented by one.
The EEMs come with an Impulse/KWH rating. This rating means that the Imp / kWh LED of the EEM will blink for the indicated number of times when 1 KWH or 1 unit of electricity will be consumed. Like there is a load of 100 Watt, it will consume 100 Watt in an hour. In 10 hours, it will consume 1 KW of electricity. Therefore, in 10 hours, a 100 Watt load will consume 1KWH or 1 unit of electricity. If an EEM is indicated with 1600 impulse/KWH rating, on consumption of 1 KWH or 1 unit of electricity, its Imp / kWh LED on front panel will blink for 1600 times. The regular EEM used in the project testing had a rating of 3200 impulse/KWH. This rating can vary from 800 impulse/KWH to 3600 impulse/KWH. However, meters with 1000 impulse/KWH rating are gaining popularity nowadays.
The meter rating should be confirmed and well known to write Arduino code for calculation of energy consumption and balance deduction. For testing the real impulse/KWH rating of the meter, a load of fixed wattage should be connected with the meter and supplied power for a minute. The number of blinks in a minute during running supply to the load should be calculated.
The wattage of load is related to meter rating by the following formula –
Wattage of load in KW = 3600/(Meter rating in impulse/KWH * Seconds per Flash)
The seconds per flash are related to blinks per minute in the following way –
seconds per flash = 60/Blinks Per Minute
So,
Wattage of load in KW = (3600 * Blinks Per Minute)/ (Meter rating in impulse/KWH * 60)
Wattage of load in KW = (60* Blinks Per Minute)/Meter rating in impulse/KWH
If wattage of load in known in Watts then,
Wattage of load in Watts = (60* Blinks Per Minute*1000)/Meter rating in impulse/KWH
From the above equation, the meter rating can be confirmed by the formulae –
Meter rating in impulse/KWH = (60* Blinks Per Minute*1000)/ Wattage of load in Watts
The EEM used during project testing had a rating of 3200 impulses/KWH mentioned on it. On running a 100 Watt bulb for 1 minute intervals, on average 5.333 blinks were received. Placing the values in above equation –
Meter rating in impulse/KWH = (60 * 5.333 * 1000)/100
= 3199.8
So the meter rating is confirmed to be 3200 impulse/KWH. The same number of blinks will be equivalent to 1 KWH or 1 unit of electricity consumption.
The Arduino sketch of the prepaid energy meter detects the blinks and runs a counter in descending order measuring consumption of each 1 KWH or unit electricity by 3200 blinks or pulses. When the available electricity consumption is left 30 percent, the Arduino Mega raises the D0 bit of the RF decoder high sending an acknowledgement of low energy balance to the recharge station. On detecting D0 bit high on RF encoder, the Arduino UNO on the recharge station frames and sends an alert message to the consumer using GSM/GPRS module. The consumer needs to make a recharge before the available energy balance is exhausted. If the available energy balance is exhausted, the Arduino Mega drives the relay contactor to NC point cutting off the main supplies. The main supply is resumed as the energy balance is recharged and read by the meter from recharged EEPROM.
Programming Guide
Arduino Sketch of Recharge Station
The program code will run on the Arduino UNO. In the program code, first the standard open-source libraries of Arduino for interfacing LCD, Virtual Serial port and serial communication are imported.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <Wire.h>
An object of LCD class is declared and mapped with the Arduino pins. The virtual serial port is realized at pins 9 and 10 of the Arduino. The pins where tactile switches are connected are assigned to variables b1, b2, b3 and b4. The pin interfacing with the D0 bit of RF Decoder is assigned to variable RFin. The variables bs1, bs2, bs3, bs4, bs5 are declared to hold the status of Arduino pins. An array holding the recharge amounts is declared. A set of counter variables is declared and an array to hold bitmap for custom rupee character is declared.
LiquidCrystal lcd(13, 12, 6, 5, 4, 3);// Pins used for RS,E,D4,D5,D6,D7
SoftwareSerial mySerial(9, 10); // RX, TX
int b1 = A0; // Push button used as * and < at A0 pin
int b2 = A1; // Push button used as > at A1 pin
int b3 = A2; // Push button used as EXIT at A2 pin
int b4 = A3; // Push button used as # and save at A3 pin
int RFin=7;
int bS1 = 0;
int bS2 = 0;
int bS3 = 0;
int bS4 = 0;
int bS5 = 0;
int teriff[7] = { 2,5,7,9,12,15,17};
int i=0,j=0,k=0,l=0,m=0,puls=0,pos=0;
byte rupees[8] ={ 0b00000,
0b11111,
0b00100,
0b11111,
0b00100,
0b01000,
0b00100,
0b00010
};
A function eeprom_i2c_write() is defined which writes data to a specific address of the EEPROM. Inside the function beginTransmission() method from wire library is used to initiate serial communication. The write() method is used to write data and endTransmission() method is used to close the transmission.
void eeprom_i2c_write(byte address, byte from_addr, byte data) {
Wire.beginTransmission(address);
Wire.write(from_addr);
Wire.write(data);
Wire.endTransmission();
}
A function eeprom_i2c_read() is defined to read data from a specific address of the EEPROM. Inside the function beginTransmission() method from wire library is used to initiate serial communication. The write() method is used to write address location and endTransmission() method is used to close the transmission. The data from a memory address is requested using requestFrom() method and if available checked by available() method, is read using read() method. else, the data read is set to 0xFF.
byte eeprom_i2c_read(int address, int from_addr) {
Wire.beginTransmission(address);
Wire.write(from_addr);
Wire.endTransmission();
Wire.requestFrom(address, 1);
if(Wire.available())
return Wire.read();
else
return 0xFF;
}
A setup() function is called in which the baud rate for virtual serial port and serial transmission of data to the LCD is set to 9600 bits per second using mySerial.begin() and Serial.begin() functions respectively and communication over TWI is initialized using Wire.Begin() method. The pins where tactile switches and D0 bit of Decoder IC are connected are set to digital input. The LCD is initialized using LCD.begin() function and initial messages indicating name of the project are flashed on the screen.
void setup() {
mySerial.begin(9600);
Wire.begin();
Serial.begin(9600);
pinMode(b1, INPUT);
pinMode(b2, INPUT);
pinMode(b3, INPUT);
pinMode(b4, INPUT);
pinMode(RFin, INPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“Engineers Garage”);
lcd.setCursor(0,1);
lcd.print(” PRE PAID EM “);
delay(3000);lcd.clear();
}
A loop() function is called in which the digital input from the tactile switches and D0 bit of decoder IC are read using digitalRead() function. A message prompting user to recharge energy balance is flashed on LCD. If user presses button connected to A2 pin, the pos variable is set to 20 and LCD screen is cleared. If user presses button connected to A0 pin, the recharge balance in rupees and pulses is read from the EEPROM and saved to r and s variables respectively. The current available balance is shown on the LCD. If D0 bit of decoder IC is set HIGH, an alert message of low balance is shown on LCD screen and function to send SMS alert is called.
void loop()
{
bS1 = digitalRead(b1);
bS2 = digitalRead(b2);
bS3 = digitalRead(b3);
bS4 = digitalRead(b4);
bS5 = digitalRead(RFin);
digitalWrite(RFin,0);
lcd.setCursor(0,0);
lcd.print(“**TO RECHARGE**”);
lcd.setCursor(0,1);
lcd.print(” PRESS YES* “);
if(bS3==LOW){
pos=20; lcd.clear();}
if(bS1==LOW){
lcd.clear();
int r = eeprom_i2c_read(B01010000, 1);
int s = eeprom_i2c_read(B01010000, 2);
lcd.setCursor(0,0);
lcd.print(“AMOUNT RECHARGED”);
lcd.setCursor(6,1);
printDigits2(r);
lcd.setCursor(9,1);
printDigits2(s);
while(1){
delay(3000);delay(3000);
lcd.clear();
break;
}
}
if(bS5==HIGH){
lcd.setCursor(0,0);
lcd.print(“LOW AMOUNT DETCT”);
lcd.setCursor(0,1);
lcd.print(” PLS RECHARGE “);
lowAlertSMS();
lcd.clear();
}
If pos variable is set to 20, digital input from buttons is read and a message indicating recharge process is shown on LCD. The user can increase or decrease recharge package by pressing buttons connected to A0 and A1 pins of Arduino and on pressing button connected to A3 pin, selected recharge is shown on the LCD and the recharge information is saved to the EEPROM in terms of ruppes as well as pulses. A message of successful recharge is sent to user’s number by calling rechagreAlertSMS() function. The number of units recharged are calculated by dividing by 6 the recharge amount held by variable r. The recharge units are converted to number of pulses by multiplying by 3200 which is the impulse/KWH rating of EEM.
while(pos==20){
bS1 = digitalRead(b1);
bS2 = digitalRead(b2);
bS3 = digitalRead(b3);
bS4 = digitalRead(b4);
lcd.setCursor(0,0);
lcd.print(” RECHARGE AMOUNT “);
lcd.createChar(1,rupees);
lcd.setCursor(6,1);
lcd.write(1);
if(bS1==LOW && pos==20){
if(i>0){
i–;
delay(400);
}
}
if(bS2==LOW && pos==20){
if(i<6){
i++;
delay(400);
}
}
lcd.setCursor(8,1);
printDigits2(teriff[i]);
if(bS4==LOW && pos==20){
lcd.clear();
pos=1;
lcd.setCursor(3,0);
lcd.print(“AMOUNT”);
lcd.createChar(1,rupees);
lcd.setCursor(10,0);
lcd.write(1);
lcd.setCursor(12,0);
printDigits2(teriff[i]);
lcd.setCursor(0,1);
lcd.print(” YES* NO# “);
delay(500);
while(pos==1){
bS3 = digitalRead(b3);
bS4 = digitalRead(b4);
if(bS3==LOW && pos==1){
eeprom_i2c_write(B01010000, 1, teriff[i]);
delay(200);
pos=30;
lcd.clear();
break;
}
if(bS4==LOW && pos==1){
lcd.clear();
break;
}
}
}
}
while(pos==30){
byte r = eeprom_i2c_read(B01010000, 1);
lcd.setCursor(0,0);
lcd.print(“RECHARGE “);
lcd.createChar(1,rupees);
lcd.setCursor(10,0);
lcd.write(1);
lcd.setCursor(12,0);
printDigits2(teriff[i]);
rechagreAlertSMS();
puls=(3200*r)/6; //6 rupees per UNIT assumption
eeprom_i2c_write(B01010000, 2,puls);
Serial.print(puls);
for(j=0;j<16;j++){
lcd.setCursor(j,1);
lcd.print(“*”);
delay(500);
}
lcd.setCursor(0,1);
lcd.print(” DONE !!! “);
delay(3000);delay(3000);
lcd.clear();
pos=40;
break;
}
}
A printDigits2() functionn is used in the loop() function to format the strings carrying numbers to a zero padded format.
void printDigits2(int digits)
{
if(digits < 10)
{
lcd.print(“0”);
lcd.print(digits);
}
else
{
lcd.print(digits);
}
}
The lowAlertSMS() function is used to send message of low energy balance to user. The standard commands of the GSM module are passed to it using virtual serial port. The message is sent to an imaginary 91xxxxxxxxxx number which can be replaced with any real mobile number.
void lowAlertSMS(){
delay(100);
mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println(“AT+CMGS=”+91xxxxxxxxxx”r”);
delay(100);
mySerial.println(“LOW BALANCE PLEASE RECHANGE”);// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
loop();
}
The rechargeAlertSMS() function is same as the lowAlertSMS() function except that the message text is different. Again, message is sent to an imaginary 91xxxxxxxxxx number which can be replaced with any real mobile number.
void rechagreAlertSMS(){
delay(100);
mySerial.println(“AT+CMGF=1”); //Sets the GSM Module in Text Mode
delay(100); // Delay of 1000 milli seconds or 1 second
mySerial.println(“AT+CMGS=”+91xxxxxxxxxx “r”);
delay(100);
mySerial.print(“Rechange Done, MRP:Rs.”);// The SMS text you want to send
delay(100);
mySerial.print(teriff[i]);
delay(100);
mySerial.print(“n”);
delay(100);
mySerial.println(“Use electricity wisely to avoid rising costs.”);
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
This ends the Arduino sketch for Recharge Station.
Arduino Sketch for Prepaid Energy Meter
The program code will run on the Arduino Mega. In the program code, first the standard open-source libraries of Arduino for interfacing LCD, Virtual Serial port and serial communication are imported.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <Wire.h>
An object of LCD class is declared and mapped with the Arduino pins. The virtual serial port is realized at pins 9 and 10 of the Arduino. The pins where tactile switch, D0 bit if Encoder IC and relay are connected are assigned to variables b1, RFin and relay. A variable to hold analog value from LDR sensor is declared. A set of counter variables is declared and an array to hold bitmap for custom rupee character is declared.
LiquidCrystal lcd(13, 12, 6, 5, 4, 3);// Pins used for RS,E,D4,D5,D6,D7
SoftwareSerial mySerial(9, 10); // RX, TX
int b1 = A0; // Push button used as * and < at A0 pin
int RFin=7;
int relay=24;
int sensorValue=0;
int i=0,j=0,k=0,l=0,m=0,Lpuls=0,puls=0;
byte rupees[8] ={ 0b00000,
0b11111,
0b00100,
0b11111,
0b00100,
0b01000,
0b00100,
0b00010
};
A function eeprom_i2c_write() is defined which writes data to a specific address of the EEPROM. Inside the function beginTransmission() method from wire library is used to initiate serial communication. The write() method is used to write data and endTransmission() method is used to close the transmission.
void eeprom_i2c_write(byte address, byte from_addr, byte data) {
Wire.beginTransmission(address);
Wire.write(from_addr);
Wire.write(data);
Wire.endTransmission();
}
A function eeprom_i2c_read() is defined to read data from a specific address of the EEPROM. Inside the function beginTransmission() method from wire library is used to initiate serial communication. The write() method is used to write address location and endTransmission() method is used to close the transmission. The data from a memory address is requested using requestFrom() method and if available checked by available() method, is read using read() method. else, the data read is set to 0xFF.
byte eeprom_i2c_read(int address, int from_addr) {
Wire.beginTransmission(address);
Wire.write(from_addr);
Wire.endTransmission();
Wire.requestFrom(address, 1);
if(Wire.available())
return Wire.read();
else
return 0xFF;
}
A setup() function is called in which the pin where tactile switch is connected is set to digital input while pins connecting D0 bit of RF encoder and relay coil are set to digital output. The relay and D0 bit of RF encoder is set to LOW logic by default. The baud rate for serial transmission of data to the LCD is set to 9600 bits per second using Serial.begin() function and communication over TWI is initialized using Wire.Begin() method. Some initial messages are flashed on the LCD screen.
void setup() {
pinMode(b1, INPUT);
pinMode(RFin, OUTPUT);
pinMode(relay, OUTPUT);
digitalWrite(relay,LOW);
digitalWrite(RFin,LOW);
Wire.begin();
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“Engineers Garage”);
lcd.setCursor(0,1);
lcd.print(” PRE PAID EM “);
delay(3000);
lcd.setCursor(0,0);
lcd.print(” PRE PAID EM “);
lcd.setCursor(0,1);
lcd.print(” “);
}
A loop() function is called in which the recharge balance is read from the EEPROM memory locations and recharge balance is shown on the LCD screen. The recharged energy units are saved to a puls variable and relay is tripped to resume main supplies. The analog voltage at A0 pin is read and converted to digital reading using analogRead() function. If the sensor value exceeds 300, the puls variable is decremented by one and reduced balance in pulses is written back to EEPROM. If the pulse variable is left 30 percent that is 70 percent of energy balance is consumed the D0 bit of RF encoder is set to HIGH. If a valid recharge is done or not is checked by if-else logic.
void loop()
{
byte r = eeprom_i2c_read(B01010000, 1);
byte s = eeprom_i2c_read(B01010000, 2);
if(s>1 && s<100){
lcd.setCursor(0,0);
lcd.print(” YOUR ACCOUNT “);
lcd.setCursor(0,1);
lcd.print(“RECHARGE “);
lcd.createChar(1,rupees);
lcd.setCursor(10,1);
lcd.write(1);
lcd.setCursor(11,1);
printDigits2(r);
delay(3000);
lcd.clear();
delay(2000);
digitalWrite( relay, HIGH );
digitalWrite(RFin,LOW);
byte r = eeprom_i2c_read(B01010000, 1);
byte s = eeprom_i2c_read(B01010000, 2);
puls=s;
while(1){
lcd.setCursor(0,0);
lcd.print(” DEVICE ON TIME “);
lcd.setCursor(1,1);
printDigits2(s);
lcd.setCursor(5,1);
lcd.print(“PULSES”);
digitalWrite(RFin,LOW);
sensorValue =analogRead(A0)*(5.0/1023.0)*100;
if(sensorValue>=300){
i++;
puls–;
delay(500);
lcd.setCursor(12,1);
printDigits2(i);
//eeprom_i2c_write(B01010000, 1, i);
eeprom_i2c_write(B01010000, 2, puls);
}
Lpuls=s-s*.3;
if(i==Lpuls){
lcd.setCursor(0,0);
lcd.print(“LOW AMOUNT DETCT”);
lcd.setCursor(0,1);
lcd.print(” PLS RECHARGE “);
delay(4000);
digitalWrite(RFin,HIGH);
while(1){
sensorValue =analogRead(A0)*(5.0/1023.0)*100;
if(sensorValue>=300){
lcd.clear();
break;
}
}
}
if(i==s){
eeprom_i2c_write(B01010000, 1, 0);
digitalWrite( relay, LOW );
lcd.setCursor(0,0);
lcd.print(” ZERO BALANCE “);
lcd.setCursor(0,1);
lcd.print(“DEVICE SHUTDOWN “);
delay(3000);delay(3000);
i=0;
s=0;
break;
}
if(r>250){
break;
}
}
}
else{
lcd.setCursor(0,0);
lcd.print(“INVALID AMOUNT “);
lcd.setCursor(0,1);
lcd.print(” PLS RECHARGE “);
digitalWrite(relay,LOW);
while(1){
byte r = eeprom_i2c_read(B01010000, 1);
byte s = eeprom_i2c_read(B01010000, 2);
if(s>1){
break;
}
}
}
}
A printDigits2() functionn is used in the loop() function to format the strings carrying numbers to a zero padded format.
void printDigits2(int digits)
{
if(digits < 10)
{
lcd.print(“0”);
lcd.print(digits);
}
else
{
lcd.print(digits);
}
}
This ends the Arduino sketch for Prepaid Energy Meter.
You may also like:
Project Source Code
###
//Program to #include#include #include LiquidCrystal lcd(13, 12, 6, 5, 4, 3);// Pins used for RS,E,D4,D5,D6,D7 SoftwareSerial mySerial(9, 10); // RX, TX int b1 = A0; // Push button used as * and < at A0 pin int b2 = A1; // Push button used as > at A1 pin int b3 = A2; // Push button used as EXIT at A2 pin int b4 = A3; // Push button used as # and save at A3 pin int RFin=7; int bS1 = 0; int bS2 = 0; int bS3 = 0; int bS4 = 0; int bS5 = 0; int teriff[7] = { 2,5,7,9,12,15,17}; int i=0,j=0,k=0,l=0,m=0,puls=0,pos=0; byte rupees[8] ={ 0b00000, 0b11111, 0b00100, 0b11111, 0b00100, 0b01000, 0b00100, 0b00010 }; void eeprom_i2c_write(byte address, byte from_addr, byte data) { Wire.beginTransmission(address); Wire.write(from_addr); Wire.write(data); Wire.endTransmission(); } byte eeprom_i2c_read(int address, int from_addr) { Wire.beginTransmission(address); Wire.write(from_addr); Wire.endTransmission(); Wire.requestFrom(address, 1); if(Wire.available()) return Wire.read(); else return 0xFF; } void setup() { mySerial.begin(9600); Wire.begin(); Serial.begin(9600); pinMode(b1, INPUT); pinMode(b2, INPUT); pinMode(b3, INPUT); pinMode(b4, INPUT); pinMode(RFin, INPUT); lcd.begin(16,2); lcd.setCursor(0,0); lcd.print("Engineers Garage"); lcd.setCursor(0,1); lcd.print(" PRE PAID EM "); delay(3000);lcd.clear(); } void loop() { bS1 = digitalRead(b1); bS2 = digitalRead(b2); bS3 = digitalRead(b3); bS4 = digitalRead(b4); bS5 = digitalRead(RFin); digitalWrite(RFin,0); lcd.setCursor(0,0); lcd.print("**TO RECHARGE**"); lcd.setCursor(0,1); lcd.print(" PRESS YES* "); if(bS3==LOW){ pos=20; lcd.clear();} if(bS1==LOW){ lcd.clear(); int r = eeprom_i2c_read(B01010000, 1); int s = eeprom_i2c_read(B01010000, 2); lcd.setCursor(0,0); lcd.print("AMOUNT RECHARGED"); lcd.setCursor(6,1); printDigits2(r); lcd.setCursor(9,1); printDigits2(s); while(1){ delay(3000);delay(3000); lcd.clear(); break; } } if(bS5==HIGH){ lcd.setCursor(0,0); lcd.print("LOW AMOUNT DETCT"); lcd.setCursor(0,1); lcd.print(" PLS RECHARGE "); lowAlertSMS(); lcd.clear(); } while(pos==20){ bS1 = digitalRead(b1); bS2 = digitalRead(b2); bS3 = digitalRead(b3); bS4 = digitalRead(b4); lcd.setCursor(0,0); lcd.print(" RECHARGE AMOUNT "); lcd.createChar(1,rupees); lcd.setCursor(6,1); lcd.write(1); if(bS1==LOW && pos==20){ if(i>0){ i--; delay(400); } } if(bS2==LOW && pos==20){ if(i<6){ i++; delay(400); } } lcd.setCursor(8,1); printDigits2(teriff[i]); if(bS4==LOW && pos==20){ lcd.clear(); pos=1; lcd.setCursor(3,0); lcd.print("AMOUNT"); lcd.createChar(1,rupees); lcd.setCursor(10,0); lcd.write(1); lcd.setCursor(12,0); printDigits2(teriff[i]); lcd.setCursor(0,1); lcd.print(" YES* NO# "); delay(500); while(pos==1){ bS3 = digitalRead(b3); bS4 = digitalRead(b4); if(bS3==LOW && pos==1){ eeprom_i2c_write(B01010000, 1, teriff[i]); delay(200); pos=30; lcd.clear(); break; } if(bS4==LOW && pos==1){ lcd.clear(); break; } } } } while(pos==30){ byte r = eeprom_i2c_read(B01010000, 1); lcd.setCursor(0,0); lcd.print("RECHARGE "); lcd.createChar(1,rupees); lcd.setCursor(10,0); lcd.write(1); lcd.setCursor(12,0); printDigits2(teriff[i]); rechagreAlertSMS(); puls=(3200*r)/6; //6 rupees per UNIT assumption eeprom_i2c_write(B01010000, 2,puls); Serial.print(puls); for(j=0;j<16;j++){ lcd.setCursor(j,1); lcd.print("*"); delay(500); } lcd.setCursor(0,1); lcd.print(" DONE !!! "); delay(3000);delay(3000); lcd.clear(); pos=40; break; } } void printDigits2(int digits) //this void function is really useful; it adds a "0" to the beginning of the number, so that 5 minutes is displayed as "00:05:00", rather than "00:5 :00" { if(digits < 10) { lcd.print("0"); lcd.print(digits); } else { lcd.print(digits); } } void lowAlertSMS(){ delay(100); mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS="+917357187588"r"); delay(100); mySerial.println("LOW BALANCE PLEASE RECHANGE");// The SMS text you want to send delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000); loop(); } void rechagreAlertSMS(){ delay(100); mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(100); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS="+917357187588"r"); delay(100); mySerial.print("Rechange Done, MRP:Rs.");// The SMS text you want to send delay(100); mySerial.print(teriff[i]); delay(100); mySerial.print("n"); delay(100); mySerial.println("Use electricity wisely to avoid rising costs."); delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000); } ###
Circuit Diagrams
Filed Under: Arduino Projects, Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.