Info page · no simulation · Arduino and electronics
Prepaid Energy Meter (Learning Model)
How a prepaid meter counts pulses from an energy meter, deducts money from a balance and cuts the supply with a relay, shown with a safe model.
This topic cannot be run safely or meaningfully in the simulator, so this page explains it with diagrams, calculations and sample code instead. Everything here is original.
What you will learn
- How pulses from a meter become kilowatt-hours
- How a balance is reduced and a relay switches off at zero
- How interrupts count fast pulses
In short
Many energy meters have a pulse LED or an S0 output. It blinks a fixed number of times for each kilowatt-hour (for example 3200 pulses per kWh). The Arduino counts the pulses, turns them into units and money, subtracts the cost from the balance and opens the relay when the balance is zero. A recharge adds to the balance.
Try this next
- Add an RFID card or keypad to add money.
- Add a GSM module that sends an SMS at 10 percent balance.
- Store the balance in EEPROM so that it survives a power cut.
Caution: this is a learning model. A real prepaid meter is a certified device installed by the electricity board. Do not replace a utility meter. Use a certified energy meter with a pulse output, wire it through a qualified electrician, and test the Arduino part with a button or LED that simulates the pulses. The relay contact carries mains voltage, so use a closed box, a fuse and a proper earth.
Block diagram
The pulse output is an isolated transistor (open collector). It is wired to an interrupt pin of the Arduino with the internal pull-up resistor. Each pulse pulls the pin to GND for a short time.
The calculation
- Energy (kWh) = pulses / pulses per kWh.
- Cost = energy x rate (rupees per kWh).
- New balance = old balance - cost.
- Example: 3200 pulses per kWh. 160 pulses = 0.05 kWh. At 8 rupees per kWh that costs 0.40 rupees.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const float PULSES_PER_KWH = 3200.0; // printed on your meter
const float RATE = 8.0; // rupees per kWh (example)
const int PULSE_PIN = 2; // interrupt pin
const int RELAY_PIN = 7;
volatile unsigned long pulses = 0;
float balance = 50.0; // rupees
LiquidCrystal_I2C lcd(0x27, 16, 2);
void countPulse() { pulses++; }
void setup() {
pinMode(PULSE_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PULSE_PIN), countPulse, FALLING);
pinMode(RELAY_PIN, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop() {
noInterrupts();
unsigned long p = pulses;
pulses = 0;
interrupts();
if (p > 0) balance -= (p / PULSES_PER_KWH) * RATE;
if (balance < 0) balance = 0;
digitalWrite(RELAY_PIN, balance > 0 ? HIGH : LOW); // supply on only with credit
lcd.setCursor(0, 0);
lcd.print("Balance Rs ");
lcd.print(balance, 2);
lcd.print(" ");
delay(500);
}Parts list
| Part | What to look for |
|---|---|
| Single-phase energy meter with pulse output (3200 imp/kWh) | Certified, installed by an electrician |
| Arduino Uno | Interrupt pin 2 |
| Relay module, 10 A | Contact rated above the load |
| LCD 16x2 I2C | Shows the balance |
| Keypad 4x4 or RFID RC522 | For recharging |
| Closed box, fuse, earth | Mains safety |
Do and do not
- Do test with a button pressed by hand before you connect a real meter.
- Do save the balance in EEPROM at intervals.
- Do keep the low-voltage and mains wiring apart.
- Do not rely on a relay alone for safety: add an MCB.
- Do not tamper with a utility meter. It is illegal.