PLC Solution Library · Energy meter simulator
Read your energy meters from a PLC, per machine and per shift
Your main meter tells you how much energy the plant used. It does not tell you which machine used it, in which shift, or while it produced nothing. In this simulator, an ESP32 PLC 21 CORE reads 6 machine meters over Modbus RTU and the main meter over Modbus TCP. It splits the kWh by shift, warns you before a demand peak and raises an alarm when a machine uses power with no production.
Start a shift, cut a meter cable or leave the compressor on over the weekend. You see what your PLC reads, what it calculates and which output it switches.
Choose your scenario
15 min demand, kWlimit 90
Meters and machines
Click a meter to select it. You see its Modbus frame below and you can start, stop or disconnect it on the panel.
Your design choices
Simulation
These choices are explained below. At x1, 1 second is 1 minute of plant time.
Modbus
Request from your PLC
-
Answer from the meter
-
| Register | Raw | Value | Meaning (example map) |
|---|
Example register map: function code 03, 8 registers from address 0. The energy total uses two registers (4 and 5) with 0.1 kWh per count. Your meter manual gives the real map.
Shift report, today
| Meter | ID | Shift 1, kWh | Shift 2, kWh | Shift 3, kWh | Off shift, kWh | Idle, kWh | Max power, kW | Max 15 min demand, kW |
|---|
Your PLC adds each kWh step of each meter to the shift of that moment, with the time from its real time clock. A new production day starts at 06:00. Max power is the highest reading. Max 15 min demand is the highest closed 15 min average of the main meter, the value a demand tariff looks at. est. means a meter was offline at a shift change, so your PLC split the energy of the gap by time.
How does a PLC read several energy meters over Modbus RTU and TCP?
Your PLC acts as the Modbus master. It asks each meter for a block of registers, one meter at a time, and each meter answers with its values. On RS-485 (Modbus RTU), each meter has its own slave address on a shared two-wire bus. On Ethernet (Modbus TCP), each meter has its own IP address.
Each value sits in a register, as the meter's register map defines. Power, voltage and current often fit in one 16-bit register. The energy total (kWh) is a 32-bit counter in two registers. Your PLC joins the two registers in the right word order and applies the scale, for example 0.1 kWh per count.
Read the kWh counter, not only the power. The meter counts energy without gaps. If your PLC adds up power readings, every missed reading is lost energy. If it reads the counter, a meter that was offline for 20 minutes gives you the full 20 minutes when it answers again.
Run the Meter offline scenario and watch your PLC catch up after the outage.
How do you split energy per machine and per shift?
Put one meter on each machine or group of loads that you want to follow. Your PLC adds each kWh step of each meter to the current shift. It takes the shift times from its real time clock, so set that clock from a time server and keep it in sync. The ESP32 PLC 21 CORE has a DS3231 real time clock with a backup battery.
Store each shift total with a time stamp, the meter ID and a quality flag. If a meter was offline at a shift change, your PLC knows the energy of the gap, but not how it split between the two shifts. In this simulator, it splits that energy by time and marks the value est. (estimated).
Add a run signal for each machine, for example a contact from the machine's own control. With it, your PLC can tell energy used for production from energy used while the machine waits.
Run the Shift change scenario and follow the totals in the shift report.
How does a PLC see a demand peak coming?
Many electricity tariffs bill the highest average power in a fixed interval, for example 15 minutes. Check the interval and the limit in your own tariff. The average of an interval only exists at its end, so your PLC projects it: the energy used so far in the interval, plus the present power multiplied by the time left.
projected demand (kW) = (kWh so far + kW now × hours left) ÷ interval length in hours
When the projection goes above your limit, your PLC switches on a warning output. It can also block a load that can wait for a few minutes, for example one heater stage of a dryer, a chiller or a compressor with enough air storage. Choose these loads together with the process owner. In this simulator, blocking dryer stage 3 makes the warm-up slower.
Align your interval with the utility meter. If the utility meter gives an end of interval pulse, wire it to a PLC input. If not, keep the PLC clock in sync and start each interval on the quarter hour. The utility meter is always the reference for the bill. Your PLC gives you the warning in time.
Run the Demand peak scenario twice: with Alarm only and with the dryer block.
What is idle consumption and how does a PLC detect it?
Idle consumption is power that a machine uses while it produces nothing. Common examples are a compressor that keeps running to feed air leaks, heaters held at temperature during a stop, hydraulic pumps left on, and lighting or ventilation in an empty hall.
Your PLC needs two things for each load: a reference signal and an idle threshold. The reference is the machine run signal, or the plant production state for shared loads like the compressor. The threshold, in kW, sits above the normal standby power. If the power stays above the threshold with no production for longer than a delay, your PLC raises an idle alarm. Your PLC counts the idle kWh from the start of the idle condition. The delay only holds back the alarm.
Start with a long delay and with thresholds taken from your own readings, then adjust them. A short delay gives an alarm at every short stop.
Run the Idle weekend scenario and change the idle alarm delay.
A real project
Real case
This simulator follows the pattern of a real project in a knitting plant: one ESP32 PLC per knitting machine reads the machine state and a three-phase power meter on its RS-485 port, and sends the data over MQTT.
Read the case study: knitting machines and energy
Related case: electrical network analysis with a current analyzer on Modbus RTU
Design choices you make
1. Bus wiring and speed
Wire the RS-485 bus as one line from meter to meter (daisy chain), not as a star. Put a 120 Ω termination at both ends of the line. The ESP32 PLC 21 CORE has a 120 Ω termination on its RS-485 port. Every meter on the bus needs the same baud rate and parity, and its own slave address (1 to 247). A standard RS-485 segment takes up to 32 unit loads, so check the unit load of your meters or add a repeater.
The speed sets your poll cycle. In this simulator, your PLC asks each meter for 8 registers. At 9600 baud with even parity, one meter takes about 60 ms, with an example response time of 20 ms in the meter, so 6 meters take about 0.4 s. A meter that does not answer costs a timeout on every try: with 200 ms and one retry, one dead meter adds 400 ms to each cycle. Change the speed in your settings and compare.
2. Register map, word order and scale
Take the register map from your meter manual: the function code (03 or 04), the address of each value, the data type (integer or 32-bit float) and the scale. For 32-bit values, check the word order: some meters send the high word first, others the low word first. A wrong word order gives values that jump by millions. Add a plausibility check: a kWh step can never be bigger than the rated power multiplied by the time since the last good reading.
3. Current transformers
If your meter measures through current transformers, set the CT ratio in the meter or apply it in your PLC, but never in both places. During commissioning, check one reading against a clamp meter.
4. Where the data goes
Your PLC sends the values to your dashboard, SCADA or database, for example over MQTT. Keep the shift totals in the PLC until the receiver confirms them, so a network outage does not leave a gap. For long outages, check the local storage options for your PLC model with our team.
5. Outputs and load blocks
The outputs of the ESP32 PLC 21 CORE are optoisolated 5 to 24 Vdc outputs, not relays. To block a heater stage, drive the coil of an interface relay or contactor in that heater circuit. A load block from the PLC is process logic. The protection of the heater (thermostat, safety limiter) stays in its own circuit.
Learn the protocols
These examples and tutorials cover the parts you need for this pattern.
- Modbus RTU master over RS-485 (PLC Solution Library)
- Read a 32-bit Modbus counter and reset it remotely (PLC Solution Library)
- Modbus TCP to RTU gateway (PLC Solution Library)
- NTP-synced hardware RTC for time stamps (PLC Solution Library)
- Offline-first MQTT data logging (PLC Solution Library)
- Node-RED dashboard for several PLC stations (PLC Solution Library)
- Modbus RTU with Arduino and ESP32 based PLCs
- Modbus TCP with Arduino and ESP32 based PLCs
- RS-485 with Arduino and ESP32 based PLCs
To diagnose timeouts, CRC errors and duplicate addresses on the RS-485 bus, try the Modbus network simulator.
To follow production and downtime on the same machines, try the Machine Monitor simulator. More examples: textile monitoring project pack · PLC Solution Library · all simulators.
ESP32 PLC 21 CORE: the specs that matter here
| Network | Ethernet 10/100 Mbit (RJ45), Wi-Fi 2.4 GHz, Bluetooth LE |
|---|---|
| Serial | RS-485 half duplex with 120 Ω termination, RS-232 and TTL selectable by DIP switch, I2C, SPI |
| Inputs | 13: 6 analog/digital (0-10 V, 11-bit) and 7 digital optoisolated, 5 to 24 Vdc, 2 with interrupt |
| Outputs | 8: 3 analog/digital/PWM (0-10 V, 12-bit) and 5 digital optoisolated, 5 to 24 Vdc. No relay outputs. |
| Real time clock | DS3231 with backup battery |
| Power supply | 12 to 24 Vdc with polarity protection |
| Mounting | DIN rail TS35, IP20, inside a cabinet |
| Programming | Arduino IDE with the Industrial Shields ESP32 boards package, over USB or Ethernet |
| Expansion | Up to 127 I2C expansion modules. The CORE version ships without an expansion board. The FLEX version takes one board: 4G LTE-M/NB-IoT, LoRa or CAN. |
In this example, your PLC uses the RS-485 port for 6 machine meters, Ethernet for the main meter and the data link, 3 digital inputs for run signals, 4 digital outputs for the alarms and the load block, and the real time clock for the shifts. Meters with a pulse output (S0) can go to the digital inputs: use the interrupt inputs for fast pulses, and check the input ratings in the ESP32 PLC family datasheet. Full specs: ESP32 PLC 21 CORE · ESP32 PLC family.
FAQ
How many energy meters can one PLC read on one RS-485 bus?
Modbus RTU uses slave addresses 1 to 247. A standard RS-485 segment takes up to 32 unit loads, and many meters use less than one unit load, so check your meter datasheet. In practice, your limit is often the poll cycle, because every meter adds its request and answer time. In this simulator, 6 meters at 9600 baud need about 0.4 s per cycle.
Modbus RTU or Modbus TCP for energy meters?
Both work, and one PLC can use both at the same time. Modbus RTU runs over RS-485 and suits several meters in one cabinet or along one line. Modbus TCP runs over Ethernet and suits meters that are far away or already on the plant network. In this simulator, 6 machine meters use Modbus RTU and the main meter uses Modbus TCP.
Why read the kWh counter and not add up the power readings?
The meter counts energy without gaps, even when your PLC does not ask. If you add up power readings, every missed reading is missing energy, and the result depends on your poll cycle. With the counter, a meter that was offline gives you the full energy of the outage as soon as it answers again.
How does the PLC predict a demand peak?
It adds the energy used so far in the present interval to the present power multiplied by the time left. If this projected average is above your limit, it switches on a warning output and can block a load that can wait. Your tariff sets the interval length and the limit. The simulator uses 15 minutes.
What counts as idle consumption?
Power that a machine uses while it does not produce: a compressor feeding air leaks, heaters held at temperature, pumps or lighting left on. Your PLC compares the power of each load with an idle threshold while the run signal is off, and raises an alarm after a delay. It counts the idle kWh from the start of the condition.
What happens to the readings if a meter or the network fails?
If a meter does not answer, your PLC marks it as faulty after a few tries and switches on an alarm output. The meter keeps counting, so your PLC gets the missing energy from the counter when the meter answers again. If the link to your server fails, keep the shift totals in the PLC until the server confirms them.
Do I need to program in C++ to build this?
You program the ESP32 PLC in C++ with the Arduino IDE. The Modbus parts have public tutorials and examples, linked above. If you prefer, an integrator can write the program for you from your meter list and register maps.
Send me this metering architecture
Tell us about your meters, your machines and your shifts. Our team replies with a proposed architecture for your plant. Your simulator settings go with the request.