Measure your energy consumption with Arduino

Measure your energy consumption with Arduino

Published on: 01-02-2014 15:39 - Lees in het Nederlands

Please note: this article was semi-automatically translated from Dutch, translation errors may occur, links will lead to Dutch websites, you are welcome to comment in English.

Nowadays, you see them everywhere: energy meters. As a standalone device, as a 'gift' from your energy supplier, or as part of a home automation solution. But what if you do not want to pay a monthly fee for "just" logging your energy consumption? Do you really like that the energy company gets such a detailed understanding of your usage? Why not build an energy meter yourself?

Calculations with the kWh counter

Virtually every home is equipped with a Ferrarismeter, also called kilowatt hour meter or electricity meter. In this electricity sensing device a metal disk with a black line on it rotates. The C-value of your kilowatt hour meter indicates what a single rotation means. If the C-value is for example 375, this means that you have consumed. 1 kWh after 375 laps.

kWh = n/C

By counting the revolutions of the disc you can keep track of your total energy consumption. To find out what your current energy consumption is you need to divide the kWh by time:

kWh/h = kW

The shortest possible time we can determine is the time between two turns of the Ferraris disk. With the following formula we calculate the current energy consumption in Watts for a given pulsetime, that's one rotation.

W = (1/C) / (tpuls/3.600.000) x 1000

This simplifies to:

W = 3.600.000 / (C x tpuls) x 1000

Now we know the formulas to calculate what we consumed in kWh and what our actual usage in Watts is, it is a piece of cake to put it in the Arduino!

Connecting your Arduino

The energy conmpany does not like it when you open up your kWh-meter to connect wires to it. The only legitimate way (in the Netherlands) is to read the dial contactless, through the housing, and no, it is not possible to influence the meter readings in this way!

Read your kWh-meter with Arduino

In this case I use an optical sensor, it's self made ​​of a blue LED and a LDR. The blue LED shines through the enclosure on the reflective disk of the Ferraris meter. The LDR captures the reflected light and sends it to an analog input of the Arduino. If the black stripe passes on the disk there will be less light from the LED reflected back to the LDR, what we see in the Arduino as a lower value on the analog input. The only drawback of this cheap DIY sensor is that it uses visible light, and therefore it can be influenced by opening the cupboard door.

You can also use a ready-made sensor that works with infrared light, such as a TCRT5000, a CNY 70 or recycle one from an old tapedeck. These sensors generally have three connections, like the DIY sensor, a +5V, a ground, and the sensor output that connects to an analog input on your Arduino.

Connecting a TCRT5000 sensor to an Arduino

Above you see the wiring diagram for a TCRT5000. The LED has a series resistor needed (RLED), which you calculate as in the article on the LED-matrix display with Ohm's Law. The voltage and LED-current can be obtained from the datasheet of the TCRT5000.

R = (5 - 1,25) / 0,06 = 62,5 Ohm

Because the datasheet describes absolute maxima you better take a slightly greater resistance for safety, for example, 100 ohms

The sensor output, the collector of the IR sensor in this case, connects to any analog input of the Arduino. The Arduino input now receives a value of 0 when the sensor detects a reflection, but if there is no reflection detected, the input gives random values. This is because we disconnected the input from ground: the input will 'float'.

The solution to this problem is the pull-up resistor. This Rpull connects the analog input of the Arduino via a large resistor (10 kilo ohms) to +5 Volts. As a result, the decoupled input is pulled to +5 Volts (pull-up). The result is a stable value on the Arduino input, depending on the measured reflection somewhere between 0 and 255.

Programming the Arduino

The heart of the software consists of the following code:

if (sensor < treshold) {
  pulse = true;
if (sensor > treshold && pulse == true) {
  pulse = false;
  pulseTime = (millis() - prevMillis);
  prevMillis = millis();
  totalkWh = pulseCount / C;
  curWatts = (3600000 / (C * pulseTime) * 1000;

In the first if-statement the black line is detected, the value of the light sensor then drops below the threshold, which is experimentally determined. To avoid having a single pulse counted multiple times we wait nicely until the black line is passed through: the second if-statement. Then we reset the pulse, increase the pulse counter, calculate the time between two pulses in milliseconds, reset the prevMillis value for the next measurement, and we calculate the total kWh consumed and the current consumption in Watts.

You can send these value to your computer using the Serial() function. It is really interesting when you save the measured values ​​in a database. You can then draw graphs and get more insights into your energy consumption.

Extending the Arduino energy sensor

Now that you have this knowledge you can actually take measurements of everything. For example, in the same way I read my gas and water consumption. The gas meter has a reflective patch on the first dial, and the water meter has a rotating silver notch, which comes in handy when reading with an optical sensor. Obviously, the formulas must be slightly modified to give the consumption in dm3 per hour or liters per minute.

Graphical interface of the home-made Arduino energymeter

Of course it is even better if you can monitor your energy consumption without your laptop physically connected to the Arduino. This can be done using the Ethernet Shield. On you will find several guides on how the ethernet shield works. For instance you can send data from the Arduino to a remote Web server, and there build a database. But you can also, as I have done myself, run a Web server on the Arduino itself, and store the data locally. For this I used the Webserver tutorial at

You can also use the IoT Dataplatform of EngineerAtHome! Go to and learn how to add a sensor and log your data to our servers.

Time to get to work yourself! Please leave a comment if your Arduino power meter works!

09-05-2015: This is the complete Arduino code for logging your gas-, water- and power-meter to an SQL-database. More on databases in this article.

59 comments on this article »

More articles like this one