Fareed Mohmed← All projects

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

Mains supplyEnergy meterpulse outputArduinocounts pulsesRelaycuts the loadLoad (lamp)Keypad / RFIDrechargeArduinoLCDbalance and unitsBuzzerlow balance warning

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

#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

PartWhat to look for
Single-phase energy meter with pulse output (3200 imp/kWh)Certified, installed by an electrician
Arduino UnoInterrupt pin 2
Relay module, 10 AContact rated above the load
LCD 16x2 I2CShows the balance
Keypad 4x4 or RFID RC522For recharging
Closed box, fuse, earthMains safety

Do and do not