meterN meterN
« Home energy metering & monitoring »
This guide explain how to turn pulses meters into a valid output format using an Arduino board.

   It involve to know a bit of technical and software knowledge.

Material :

Now i will explain how to monitor electric, gas and water meters using simples 'pulse' sensors. For the interface, you'd be fine to use an Arduino. This platform have the avantage to be cheap, simple, open-sourced and you'll be able to find many sort of sensors that'll surely fits your needs.

If you own any electric production system you will need an additional meter on the consommation side. If you choose a pulse counter, choose one that have a S0 output that output a pulse per Wh or more.

Since years, i've been using a Eastron's SDM meter that have a RS-485 interface, there are cheap, precise and more convenient.

 Modifying your electrical installation need to be done by a qualified person. I am not joking on that, it involve high-voltage that can cause serious damage for you or to your house !

For the gas meter, i used a cheap IR barrier sensor to detect the reflective part on the hole of the 6 digit (It may be sometimes in the 9 or in the 0). Adjusting the potentiometer to the good sensitivity was a game of patience !..
Though, i faced many issues with this method, especially when the temperature rise the resistor vary and lead to false pulses. Also i got sometimes wrong pulses if there was sunlight reflecting the sensor.

Then i found a really sensitive hall sensor that detect the magnet and perfectly fit my need, the Allegro A3213EUA-T or A3214. This one are precise, it can detect both polarization (North/South) and my counter don't drift anymore !

For the water meter, i use a sensible and expensive (cough) reed-switch buyed to my water distribution provider.

Choosing an adequat sensors is essential, some may not be sensitive enough. Overhall, the principle is to count On/Off information. Be also be carefull when you do your cabling, it have to be done properly.

Communication :

 Poolmeters is given as example, it is not part of meterN project.

Since each installation is different, i sadly can't make a portable application so, you have to build it by yourself. But don't be afraid, here's some theory ;)

The Arduino board must be dedicated to counting. The Leonardo have 4 hardware interrupts, it is strongly advisable to use interrupts for fast pulses meters rather than digital inputs as it make sure it detect the pulses rather than doing something else.
When the interrupt detect a pulse, it stop the current code to do something more important: counting! Each interrupt have also priority, the lower the interrupt number, the higher the priority.
Your faster meter must then be on int. 0 and i will use it for an electrical meter. Beware the int. number don't correspond to the pin number.

For the gas meter, the pulses are slows, i then use a digital input to measure valid pulse time's width.

If you use a open contact circuit like an S0 output, you need to put a pulldown resistor. If you don't, your cable will behave as an antenna and the arduino is sensible enough to detect really low voltage level.
If your sensor need to be disconnected, don't ever leave the input circuit open, you'll need to 'ground' it or you may had constant interrupt.
Some sensors need a pullup resistor like the hall effect sensors.

The 'poolmeters.ino' code detect the interrupt count falling edges for an electrical meter, digital inputs for water and gas ones.

Some pulses may not be perfect and since the arduino is fast enough, it may detect several falling edges in a one. One trick is to use a RC circuit or, simplier, detect the pulses larger than a certain time. An electric meter pulses are around 50ms large, i put a 30ms threshold.

If your sensor is noisy, like my reed switch for water pulses is, you also may use an opto-isolator or a schmitt trigger to filter signals.

You've understand the hardest part ! Now, all it need is to communicate, the output format understable by meterN is describe in the how-to.

The Main pooling :

Since the counter should always increase until it pass-over and can't return to zero (after a surge or if the arduino is reseted), the solution is to read the last recorded value in the daily csv and increment this record with the counting during the 5 min pooling period. Then, put to zero the arduino counter and so on..
It mean that even if meterN or the logger is stopped, the counter will always be increased and metered as long as the arduino is powered !
This is what the 'pooler.php' example script does.

The Dashboard pooling :

Meter that increase frequently like an electric S0 output can send a time between two pulses. This time can be extrapolate to another value: The lower the time is, the more your consume.
Eg for an electrical meter: A time of 1716ms also give (1000*3600)/1716 =~ 2098W !
Be aware that if you don't consume much, the refreshing time between two pulses can be long. On a 1000pulse/kWh counter, it update to around a second with a 3500W consumption to ~3,6 sec with 1000W and only each ~36sec with 100W.

If your meter is slow and don't update frenquently like a gas meter, it can't really be usefull to know the average values for a long time.
If you counter receive a pulse recently, it mean than your device is running. So, the value may return 'On' or 'Off' if the last pulse is too old.


All that things above should be coded according to your installation

To talk with the computer I use pyserial, a python module that ease the access to serial port. Check out the readme in poolmeters example for more details.

meterN