Estação de recarga de energia elétrica com medidor de energia pré-pago usando Arduino

Electricity charging station with prepaid energy meter using Arduino

Households typically have post-paid electricity connections. On the consumer side, postpaid connections have the disadvantage that electricity consumption is not monitored by consumers and they are often shocked when they receive high bills. The cause of high bills is usually not high electricity rates, but unconscious excessive use of electricity. Prepaid electrical connections are often suggested as a viable solution to this problem. In a prepaid electricity connection, the consumer would need to recharge the amount of electricity they want to consume. In such a system, household electricity meters need to be equipped with a system that can be recognized by the quantity recharged by the consumer and can count the electricity consumption from the recharged quantity to zero. When the meter reaches zero, the main power will be automatically cut off and can only be restarted 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 an electricity recharging station and an additional circuit that could be integrated into regular household energy meters and capable of counting down the energy consumption and cutting off the main supply when the usage counts down. energy reaches zero. As an alternative to the smart card, a memory card is used that will store the charging information from the charging station and can be connected to the integrated circuit of the energy meters to regulate the main power supply. Protótipo de estação de recarga de eletricidade pré-paga baseada em Arduino
Fig. 1: Arduino-based prepaid electricity charging station prototype
The charging station will also send a confirmation message to the consumer's registered mobile number after each recharge. The charging station and the prepaid energy meter are shown connected to each other via RF module in the project so that the prepaid energy meter can send an alert of exhausted charging amount to the charging station and the charging station can send an SMS to the consumer to top up again soon. Therefore, from a hardware point of view, this prepaid electrical system consists of the following devices – 1) Electricity Charging Station – An embedded device that can record charging information into a memory system. To put it simply, the memory system used is a memory chip. A commercial version of the system created here could have smart cards to facilitate electricity recharges. The charging station also uses a GSM/GPRS module to send a confirmation message on every successful charging and is connected to the prepaid energy meter via RF module to receive alert about the exhausted charging amount and the station can send an SMS to recharge soon. A commercial version of the system can have a charging station and prepaid energy meter connected via the internet. Unfortunately, currently the Internet is not available everywhere nor is it free to provide such a resource in a commercial avatar of such a system. 2) Smart device to store the amount of recharge – The project uses a memory card to demonstrate the operation of a smart recharge device. A commercial version of the system may have smart cards. 3) Prepaid Energy Meter – An embedded device that can be integrated into common household meters to read the recharge amount and track energy consumption in descending order until it reaches zero. The device is capable of cutting off the main sources by regulating the main sources through a relay circuit. In the project, the electricity charging station is built around Arduino UNO and the prepaid energy meter is built around Arduino Mega. The memory card used as an alternative to the smart recharge card is the AT2402. The AT2402 is a 2Kb memory card that connects to any microcontroller on the I2C interface. The Arduino IDE is used to write the Arduino sketches for the charging station and prepaid power meter and the AVR Dude is used to write program codes on the microcontroller boards. Required components – To build a charging station, you will need the following components – • Arduino UNO • GSM module •HT12D • 433 KHz RF Module • 4-switch keyboard • LCD • 7805/7812 voltage regulators. • 12-0.2Amp transformer • 1K ohm resistors • 47K ohm resistor • Diode IN4007 • 4700uF, 25V capacitor • Electric wire • Two-pin plug AT2402 memory card is used as smart charging device. To build prepaid energy meters, you will need the following components – • Arduino Mega • LCD • Encoder – HT12E • 433 KHz RF Module • 3,200 imp/kwh energy meter • LM358 comparator • LEADED • 12v relay • BC547 transistor • Diode IN4007 • 1k ohm resistors • 1M ohm resistor • Upload to test • Terminal block • Electric wire • Two-pin plug Block diagram Diagrama de blocos da estação de recarga de eletricidade pré-paga baseada em Arduino
Fig. 2: Block diagram of Arduino based prepaid electricity charging station
Circuit Connections Charging Station The charging station is built into the Arduino UNO. It has an LCD display and 4-switch keyboard for human interaction. The memory card that stores the recharge information can be connected to the Arduino board through the I2C protocol implemented on Arduino pins A4 and A5. The card is connected to a GSM module to send SMS confirmation of successful recharges and alert messages for the next recharge. The board is interfaced with the RF receiver circuit so that it can connect to the prepaid energy meter and detect low energy balance. The circuit that works as a charging station has different components and modules connected to the Arduino board as follows – 16X2 LCD Display – The LCD display is used to provide an interface for human interaction and 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. LCD RW pin is grounded. Tabela de listagem de configuração de pinos da EEPROM externa AT24C02
Fig. 3: Table listing circuit connections between Arduino Uno and Character LCD

The open source standard library for interfacing LCD with Arduino UNO is used in the project. The library works as expected and does not need any changes or modifications.

4-Switch Keyboard – Tactile switches are used to form the keyboard. There are four switches on the keyboard which are connected to the following pins with certain functions assigned to them – Tabela listando os pinos do Arduino e suas funções na estação de recarga de eletricidade pré-paga
Fig. 4: Table listing the Arduino pins and their functions on the Prepaid Electricity Charging Station
The switches are connected between ground and the Arduino pins. Arduino pins by default are connected to VCC and receive HIGH logic. When pressing a tactile button, the respective Arduino pin is short-circuited to ground and receives a logic LOW. GSM Module – The GSM module has four pins – Tx, Rx, Vcc and GRND. The Tx and Rx pins are connected to pin number 9 and 10 of the Arduino UNO respectively. Pins 9 and 10 are declared as virtual serial port in the Arduino sketch to communicate data with the module. The VCC and Ground pins of the module are connected to the 5V DC and GRND pin of the Arduino UNO board. An external 18V power supply is used to power the GSM module. RF Receiver – The RF receiver is used to receive a low energy balance alert from prepaid energy meters. The RF receiver module has 8 pins and the following pin configuration – Tabela de listagem de configuração de pinos do receptor RF
Fig. 5: Table listing RF receiver pin configuration
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 power balance alert is detected by the RF receiver and passed to the HT12D decoder. It converts serial data back to parallel data after separating data and addresses. The HT12D belongs to the 212 series of decoders and can be paired with the 212 series of encoders with the same number of addresses and data format. The HT12D is capable of decoding 12 bits, of which 8 are address bits and 4 are data bits. The address byte of the decoder IC must be the same as that of the encoder IC to match the transmitter and receiver circuits. In the design, the address byte of the receiver and transmitter modules is set to 0x00. A 47 KΩ resistor is connected between pins 14 and 15 of the decoder IC to match the RF frequency. Pin 17 is called valid transmission and has an LED connected to it through a 1 KΩ resistor to indicate whether the Prepaid Energy Meter RF transmitter is paired with the receiver or not. Only the D0 data bit of the decoder is tracked to detect the warning signal. The D0 bit of the decoder IC is connected to pin 7 of the Arduino UNO. External EEPROM – AT24C02 is the external EEPROM used as smart charging device. The 8-pin IC has the following pin configuration – Tabela de listagem de configuração de pinos da EEPROM externa AT24C02
Fig. 6: Table listing the pin configuration of the AT24C02 external EEPROM
Pins 5 and 6 of the IC EEPROM connect to pins A4 and A5 of the Arduino, where A4 is configured for SDA and A5 is configured for SCL. Pins 1, 2 and 3 of the IC EEPROM are connected to ground, as at any given time the charging station will only have a single EEPROM connected. Pins are used to address 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 using a full bridge rectifier and a 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 the Arduino UNO board. The 18V DC is supplied to the GSM module. All other ICs and modules are powered by 5V DC from the Arduino board. Smart charging device The IC EEPROM AT24C02 serves as the smart charging device in the project. To put it simply, it is used as an alternative to smart cards. The IC EEPROM stores the recharging information and can be connected to the charging station and prepaid energy meter. Prepaid energy meter The developed circuit must be connected between the loads and the neutral output of a common electrical energy meter. When a load is turned on and starts consuming electricity, current will also pass through the prepaid power meter. The device will have an LDR circuit set to sense electricity consumption by detecting the blinking of the Imp/kWh LED on the front panel of the Electronic Energy Meter and will trigger a relay circuit to cut off the supply to the neutral wire end when the balance of recharge power usage is exhausted. The device will have slot to connect EEPROM to read and decrease the recharge balance and will have an LCD display to show the current power usage balance decreasing with power consumption. The device has an RF transmitter circuit to connect to the charging station to send the alert of low remaining usage balance. The circuit is built on Arduino Mega and has different components and modules connected to the board as follows – 16X2 LCD Display – The LCD display is used to show the remaining balance of power 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. LCD RW pin is grounded. Conexões de circuito de listagem de tabelas entre Arduino Uno e LCD de caracteres
Fig. 7: Table listing circuit connections between Arduino Uno and Character LCD
The open source standard library for interfacing LCD with Arduino MEGA is used in the project. The library works as expected and does not need any changes or modifications. External EEPROM – The external EEPROM will be connected to the device and connected to the Arduino MEGA on the two-wire interface. Pins 5 and 6 of the IC EEPROM connect to pins 20 and 21 of the Arduino Mega respectively, where pin 20 of the board is configured for SDA and pin 21 is configured for SCL. Relay Circuit – A 12V 2A relay will be used to control the main sources. The loads will be connected between the phase wire and the NO pin of the relay. The neutral wire will be connected back to a normal electricity meter through the COM point. When the power usage balance is exhausted, the microcontroller will send a logic HIGH to the BC547 switching transistor circuit. The transistor circuit will short-circuit one end of the coil to ground, while the other end of the coil receives 12V supply, tripping the relay to the NC point. LDR Sensor – The LDR sensor will be placed together before the Imp/kWh LED on the regular EEM front panel. An LDR sensor changes its resistance according to the intensity of the light. When light falls on the LDR, its resistance remains low, while when there is no light, its resistance is high. The LDR sensor is connected to the non-inverting pin 2 of the LM358 voltage comparator, while the voltage at the inverting pin 3 of the LM358 is passed through a variable resistance. The Imp/KWH LED on the front panel of the EEM flashes a certain number of times according to the Impulse/KWH rating when the electricity consumption read by the meter exceeds 1KWH at a time. By default, the LDR has low resistance and when the Imp/kWh LED on the EEM front panel flashes, its resistance is increased. The difference between the inverting and non-inverting voltage is passed from output pin 1 of the comparator to analog pin A0 of the Arduino. RF Transmitter – The RF transmitter will be used to transmit low power balance warning message to the receiving circuit. The RF transmitter module is a small PCB subassembly. The pin configuration of the transmitter module is as follows: Tabela de listagem de configuração de pinos do transmissor RF
Fig. 8: Table listing RF transmitter pin configuration
The encoder serialized data is received at pin 2 of the module and passed to the antenna from pin 4 of the module. HT12E IC – The HT12E IC converts the parallel data into serial data to pass it to the RF transmitter. The IC HT12E encoder belongs to the 212 series of encoders. It is paired with 212 series decoders with the same number of addresses and data format. The HT12E is capable of encoding 12 bits, of which 8 are address bits and 4 are data bits. Thus, the encoded signal is a 12-bit serialized parallel data composed of 4-bit data to be transferred appended to the address byte. To set the frequency of the oscillator, a 1MΩ resistor is connected between pins 15 and 16 of the HT12E encoder IC. Only the D0 data bit of the encoder needs to be used to send low power balance alert to the charging station. So bit D0 of encoder IC is connected to pin 7 of Arduino MEGA. Power supply – A step-down transformer is used to convert 230V AC to 18V AC and using a full bridge rectifier and a 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 the Arduino UNO board and the relay. The 18V DC is converted to 5V DC using the 7805 voltage regulator that is supplied to the rest of the components. How the project works A consumer first needs to recharge energy. It has EEPROM IC as smart power recharging device. To recharge, he must connect the memory card to the Charging Station and press the button interfaced to pin A2 on the Arduino UNO. Upon pressing the button, the consumer will be prompted to select a top-up amount via flashing messages on the LCD screen. There will be seven recharge packs available worth 2, 5, 7, 9, 12, 15 and 17 rupees. The consumer can navigate to the ascending order of recharge packs by pressing the button connected to the A1 pin of the Arduino UNO, while they can navigate to the descending order of the recharge packs by pressing the button connected to the A0 pin of the Arduino UNO. When navigating to the desired recharge package, the consumer can confirm the recharge by pressing the button connected to pin A3 of the Arduino UNO. As the user presses the button connected to pin A3 of the Arduino UNO, the recharge value is saved in location 1 of address B01010000 in the EEPROM and the electrical power units are recharged in terms of the number of blinks of the Imp/kWh LED on the front panel of EEM are saved. A message is sent to the consumer confirming the recharge information through the GSM module. The consumer needs to remove the memory card and charge it to connect the prepaid energy meter. Once the memory card is connected to the prepaid power meter, the Arduino MEGA control meter circuit reads the recharge amount from the EEPROM and resumes supplying power by switching the relay. The top-up balance is shown on the LCD panel of the prepaid energy meter. The available electrical energy consumption is calculated by the number of blinks of the Imp/KWH LED on the EEM. The Arduino Mega waits for the Imp/kWh LED on the EEM front panel to blink and with each blink it compares the analog voltage detected at its A0 pin, which is converted to a digital measurement with a calibrated value. The calibrated value for comparison with the ADC value was set to 300 during design testing. Whenever the Imp/kWh LED on the EEM front panel blinks, the LDR resistance is increased in the potential divider circuit by increasing the non-inverting voltage and higher voltage is detected at pin 1 of the LM358 comparator IC. Thus, as the detected and digitized voltage of the A0 of the Arduino MEGA exceeds the reference value 300, a single blink of the Imp / kWh LED on the EEM front panel is registered and a variable in the program code containing the number of units recharged in the form The number of blinks or pulses is decreased by one. EEMs ​​come with an Impulse/KWH rating. This rating means that the EEM's Imp/kWh LED will flash for the indicated number of times when 1 KWH or 1 unit of electricity is consumed. As if there is a 100 Watt load, it will consume 100 Watts 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 a rating of 1600 pulses/KWH, at consumption of 1 KWH or 1 unit of electricity, its Imp/kWh LED on the front panel will flash 1600 times. The regular EEM used in the design tests had a rating of 3,200 thrust/KWH. This rating can range from 800 impulse/KWH to 3600 impulse/KWH. However, meters rated at 1000 pulses/KWH are gaining popularity nowadays. The meter rating must be confirmed and well known to write the Arduino code for calculating power consumption and deducting the balance. To test the actual impulse/KWH rating of the meter, a fixed wattage load must be connected to the meter and supplied with power for one minute. The number of flashes in one minute during supply to the load must be calculated. The load power is related to the meter rating by the following formula – Load Power in KW = 3600/(Meter Rating in Impulse/KWH * Seconds per Flash) Seconds per flash are related to blinks per minute as follows – seconds per flash = 60/blinks per minute Then, Load Power in KW = (3600 * Flashes per Minute)/ (Meter Rating in Impulse/KWH * 60) Load Power in KW = (60* flashes per minute)/Meter Rating in Impulse/KWH If the power of the load is known in Watts, then, Load Power in Watts = (60* flashes per minute*1000)/Meter Rating in Impulse/KWH From the above equation, the meter rating can be confirmed by the formulas – Meter rating in impulse/KWH = (60* flashes per minute*1000)/ Load power in Watts The EEM used during design testing had a rating of 3,200 pulses/KWH mentioned on it. When turning on a 100 Watt lamp for 1 minute intervals, an average of 5,333 blinks were received. Putting the values ​​in the equation above – Meter Rating in Impulse/KWH = (60 * 5.333 * 1000)/100 = 3199.8 Therefore, the meter rating was confirmed to be 3,200 pulses/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 the consumption of each 1 kWh or unit of electricity in 3,200 blinks or pulses. When the available electricity consumption is left at 30 percent, the Arduino Mega increases the D0 bit of the RF decoder, sending a low power balance confirmation to the charging station. Upon detecting the high D0 bit in the RF encoder, the Arduino UNO at the charging station frames itself and sends an alert message to the consumer using the GSM/GPRS module. The consumer needs to recharge before the available energy balance runs out. If the available energy balance is exhausted, the Arduino Mega triggers the relay contactor to the NC point cutting off the main power supply. Main power resumes as the energy balance is recharged and read by the meter from the reloaded EEPROM. Programming guide Arduino sketch of the charging station The program code will run on the Arduino UNO. In the program code, Arduino standard open source libraries are first imported for interfacing with LCD, virtual serial port and serial communication. #include #include #include An LCD class object is declared and mapped with Arduino pins. The virtual serial port is made on pins 9 and 10 of the Arduino. The pins where the tactile switches are connected are assigned to variables b1, b2, b3 and b4. The pin that interfaces with the D0 bit of the RF decoder is assigned to the variable RFin. Variables bs1, bs2, bs3, bs4, bs5 are declared to maintain the status of Arduino pins. An array containing the recharge values ​​is declared. A set of counter variables are declared and an array to store bitmap for custom rupee characters 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 intb1=A0; //Button used as * and < on pin A0 int b2 = A1; //Button used as > on pin A1 int b3 = A2; //Button used as EXIT on pin A2 int b4 = A3; // Button used as # and saved on pin A3 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 }; An eeprom_i2c_write function is defined that writes data to a specific EEPROM address. Inside the function, the Wire library's BeginTransmission method is used to initiate serial communication. The write method is used to write data and the 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; } An eeprom_i2c_read function is defined to read data from a specific EEPROM address. Inside the function, the Wire library's BeginTransmission method is used to initiate serial communication. The write method is used to write the address location and the endTransmission method is used to close the transmission. Data from a memory address is requested using the requestFrom method and, if available, checked by the available method, is read using the read method. otherwise, data reading will be 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; other return 0xFF; } A setup function is called in which the baud rate for virtual serial port and serial data transmission to the LCD is set to 9600 bits per second using the functions mySerial.begin and Serial.begin respectively and communication over TWI is initialized using the Wire.Begin method. The pins where the tactile switches and the D0 bit of the decoder IC are connected are configured for digital input. The LCD is initialized using the LCD.begin function and initial messages indicating the project name appear on the screen. empty configuration { 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 Workshop”); lcd.setCursor(0,1); lcd.print(”PREPAID IN“); delay(3000);lcd.clear; } A loop function is called in which the digital input of the tactile switches and the D0 bit of the decoder IC are read using the digitalRead function. A message prompting the user to recharge the power balance flashes on the LCD. If the user presses the button connected to pin A2, the pos variable will be set to 20 and the LCD screen will be turned off. If the user presses the button connected to pin A0, the recharge balance in rupees and pulses is read from the EEPROM and saved in the res variables respectively. The current available balance is shown on the LCD. If the D0 bit of the decoder IC is set to HIGH, a low balance alert message will be shown on the LCD screen and the function to send SMS alert will be called. empty loop { bS1 = digitalreading(b1); bS2 = digitalreading(b2); bS3 = digitalreading(b3); bS4 = digitalreading(b4); bS5 = digitalreading(RFin); digitalWrite(RFin,0); lcd.setCursor(0,0); lcd.print(“**TO RELOAD**”); lcd.setCursor(0,1); lcd.print(”PRESS YES*“); if(bS3==LOW){ pos=20; lcd.clear ;} if(bS1==LOW){ lcd.claro; int r = eeprom_i2c_read(B01010000, 1); ints = eeprom_i2c_read(B01010000, 2); lcd.setCursor(0,0); lcd.print(“RELOADED AMOUNT”); lcd.setCursor(6,1); printDigits2(r); lcd.setCursor(9,1); printDigits2(s); while(1){ delay(3000);delay(3000); lcd.claro; to break; } } if(bS5==HIGH){ lcd.setCursor(0,0); lcd.print(“LOW QUANTITY DETECTION”); lcd.setCursor(0,1); lcd.print(”PLS RELOAD“); low alertSMS; lcd.claro; } If the pos variable is set to 20, the digital input from the buttons will be read and a message indicating the recharging process will be shown on the LCD. The user can increase or decrease the recharge pack by pressing the buttons connected to A0 and A1 pins of Arduino and on pressing the button connected to A3 pin, the selected recharge is shown on the LCD and the recharge information is saved in the EEPROM in terms of ruppes also as pulses. A successful recharge message is sent to the user's number by calling the rechagreAlertSMS function. The number of recharged units is calculated by dividing the recharge value maintained by the variable r by 6. Recharge units are converted to number of pulses by multiplying by 3,200, which is the impulse/KWH rating of the EEM. while(pos==20){ bS1 = digitalreading(b1); bS2 = digitalreading(b2); bS3 = digitalreading(b3); bS4 = digitalreading(b4); lcd.setCursor(0,0); lcd.print(” RECHARGE VALUE “); 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){ me++; delay(400); } } lcd.setCursor(8,1); printDigits2(teriff(i)); if(bS4==LOW && pos==20){ lcd.claro; 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 = digitalreading(b3); bS4 = digitalreading(b4); if(bS3==LOW && pos==1){ eeprom_i2c_write(B01010000, 1, teriff(i)); delay(200); pos=30; lcd.claro; to break; } if(bS4==LOW && pos==1){ lcd.claro; to 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)); reloadAlertSMS; pulse=(3200*r)/6; //6 rupees per UNIT guess eeprom_i2c_write(B01010000, 2, pulses); Serial.print(puls); for(j=0;j<16;j++){ lcd.setCursor(j,1); lcd.print(“*”); delay(500); } lcd.setCursor(0,1); lcd.print(”COMPLETED!!!“); delay(3000);delay(3000); lcd.claro; pos=40; to break; } } A printDigits2 n function is used in the loop function to format strings carrying numbers into a zero-padded format. void printDigits2 (integer digits) { if(digits <10) { lcd.print(“0”); lcd.print(digits); } other { lcd.print(digits); } } The lowAlertSMS function is used to send low power balance message to the user. Standard commands from the GSM module are passed to it through the virtual serial port. The message is sent to an imaginary number 91xxxxxxxxxx which can be replaced with any real cell phone number. void lowAlertSMS { delay(100); mySerial.println(“AT+CMGF=1”); //Configures the GSM Module in Text Mode delay(1000); // Delay of 1000 milliseconds 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); link ; } The rechargeAlertSMS function is the same as the lowAlertSMS function, except the message text is different. Again, the message is sent to an imaginary number 91xxxxxxxxxx which can be replaced with any real cell phone number. void rejectAlertSMS { delay(100); mySerial.println(“AT+CMGF=1”); //Configures the GSM Module in Text Mode delay(100); // Delay of 1000 milliseconds 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, Arduino standard open source libraries are first imported for interfacing with LCD, virtual serial port and serial communication. #include #include #include An LCD class object is declared and mapped with Arduino pins. The virtual serial port is made on pins 9 and 10 of the Arduino. The pins where the tactile switch, D0 bit if Encoder IC and relay are connected are assigned to variables b1, RFin and relay. A variable to store the analog value of the LDR sensor is declared. A set of counter variables are declared and an array to store bitmap for custom rupee characters 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 intb1=A0; //Button used as * and < on pin A0 int RFin=7; internal 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 }; An eeprom_i2c_write function is defined that writes data to a specific EEPROM address. Inside the function, the wire library's BeginTransmission method is used to initiate serial communication. The write method is used to write data and the 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; } An eeprom_i2c_read function is defined to read data from a specific EEPROM address. Inside the function, the wire library's BeginTransmission method is used to initiate serial communication. The write method is used to write the address location and the endTransmission method is used to close the transmission. Data from a memory address is requested using the requestFrom method and, if available, checked by the available method, is read using the read method. otherwise, data reading will be 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; other return 0xFF; } A setup function is called in which the pin where the tactile switch is connected is defined as digital input, while the pins connecting the D0 bit of the RF encoder and the relay coil are defined as digital output. The relay and bit D0 of the RF encoder are set to logic LOW by default. The baud rate for serial data transmission to the LCD is set to 9600 bits per second using the Serial.begin function and communication via TWI is initialized using the Wire.Begin method. Some initial messages appear on the LCD screen. empty configuration { pinMode(b1, INPUT); pinMode(RFin, OUTPUT); pinMode(relay, OUTPUT); digitalWrite(relay,LOW); digitalWrite(RFin,DOWN); Wire.begin ; Serial.begin(9600); lcd.begin(16,2); lcd.setCursor(0,0); lcd.print(“Engineers Workshop”); lcd.setCursor(0,1); lcd.print(”PREPAID IN“); delay(3000); lcd.setCursor(0,0); lcd.print(”PREPAID IN“); lcd.setCursor(0,1); lcd.print(" "); } A loop function is called in which the recharge balance is read from the EEPROM memory locations and the recharge balance is shown on the LCD screen. The recharged power units are saved in variable pulses and the relay is triggered to resume main power. The analog voltage at pin A0 is read and converted to digital reading using the analogRead function. If the sensor value exceeds 300, the pulse variable will be decremented by one and the reduced pulse balance will be written back to the EEPROM. If the pulse variable is left at 30 percent, i.e. 70 percent of the energy balance is consumed, the D0 bit of the RF encoder is set to HIGH. Whether a valid reload is made or not is checked by if-else logic. empty 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.claro; delay(2000); digitalWrite(relay, HIGH); digitalWrite(RFin,DOWN); byte r = eeprom_i2c_read(B01010000, 1); byte s = eeprom_i2c_read(B01010000, 2); pulse=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,DOWN); sensorValue =analogRead(A0)*(5.0/1023.0)*100; if(sensorValue>=300){ me++; pulse-; delay(500); lcd.setCursor(12,1); printDigits2(i); //eeprom_i2c_write(B01010000, 1, i); eeprom_i2c_write(B01010000, 2, pulse); } Lpulses=ss*.3; if(i==Lpulses){ lcd.setCursor(0,0); lcd.print(“LOW QUANTITY DETECTION”); lcd.setCursor(0,1); lcd.print(”PLS RELOAD“); delay(4000); digitalWrite(RFin,HIGH); while(1){ sensorValue =analogRead(A0)*(5.0/1023.0)*100; if(sensorValue>=300){ lcd.claro; to 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 SHUT DOWN “); delay(3000);delay(3000); l=0; s=0; to break; } if(r>250){ to break; } } } other{ lcd.setCursor(0,0); lcd.print(“INVALID AMOUNT “); lcd.setCursor(0,1); lcd.print(”PLS RELOAD“); digitalWrite(relay,LOW); while(1){ byte r = eeprom_i2c_read(B01010000, 1); byte s = eeprom_i2c_read(B01010000, 2); if(s>1){ to break; } } } } A printDigits2 n function is used in the loop function to format strings carrying numbers into a zero-padded format. void printDigits2 (integer digits) { if(digits <10) { lcd.print(“0”); lcd.print(digits); } other { lcd.print(digits); } } This ends the Arduino sketch for prepaid energy meter.

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;

 pulse=(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 rejectAlertSMS {

 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

Circuit-Diagram-Arduino-Based-Electricity-Charging Station-Prepaid Energy Meter

Back to the blog

Leave a comment

Comments need to be approved before publication.