Introduction: DIY Real Energy Meter With Arduino and ESP8266

About: I'am an Electronics student that really enjoy making new things from garbage, and DIY projects. I am here to share my knowledge with you, and learn with you too.

It is not a mystery that we usually have doubts about the energy consumption records presented by the bills.

For this reason I set out to create my own energy meter to be sure of what is really happening, if we are being lied to and if we are really being deceived.

Here I leave you a tutorial with all the information so you can make your own version.

If you are a visual learner I know that a video worth more than 1000 words, so here is a 2 parts Tutorial video. (I am a Spanish speaker, so please consider turning on English subtitles):

Step 1: Skills Required:

This project may seem difficult or very complex, but it is definitely not completely, since you will have all the guidance for the construction, it was difficult for me to design it to make life a little easier for you. Any conceptual doubt, you are free to ask it without problems.

You should have an understanding of:

  • Basic electronics. (We are going to be using some electronics principles that are good to know to understand how this meter works).
  • Handling of cutting tools and drills.
  • How to solder. (To place the components we need).
  • How to use a meter intruments as multimeters and clamp meters.
  • Writing code in C. (if you want to make any modification to the main code that is provided).

Step 2: Components and Parts List

Step 3: Circuit Diagram

Here is the Circuit Diagram of our project:

It has all the internal conections of the circuit that will us allow to create the PCB design later.

I also attached the PDF of the Schematics so you can see it better.

Step 4: PCB Design and Ordering

For the implementation of a good project we need a reliable assembly for the circuit that makes it up, and there is no better way to do it than with a good PCB.

Here you can download the Gerber, BOM and Pick & Place Files, the ones you need to order your PCB on your PCB manufacturing company.

I suggest JLCPCB:

📦$2 for 5 PCBs & cheap SMT (2 Coupons)

Un Zip de .rar file with a software like WinRar or any other.

Step 5: 3D Base for the Circuit

We are going to put (well, in my case), the circuit inside the Breakers box of my house, so I designed a plastic protection base for the circuit to be apart of the metal parts and wires that are inside the panel.

You can download the STL file to print your own if you have a 3D printer o Hand make it with plastic, cardboard or something that isolate electricity.

Step 6: Programming the Arduino Board and the ESP8266

We are using an Arduino nano because of it ADC pins, pins that we don't have on the ESP, so we first need to upload the program into the Arduino board that will be reading the data from the sensors and making all the maths that will allow us to get the Real Power, Power factor, Current, Voltage, and on.

1- To program the Arduino we need to connect it directly to our PC through the USB cable, open the Code "Arduino-Code", install the libraries that I also attached and click on upload.

2- To program the ESP8266 we need to place the jumper on (PROG position), connect the USB to TTL converter to our PCB on it respectives pins and then to our PC, install the libraries and then upload. (Need to have the ESP8266 Packaje installed on your IDE).


Step 7: Install the APP and Set It

  1. Go to Google Play Store and install the app (Just for Android by now, Apple Developer Fee is high for me).
  2. Open it and it will show you a big blue button (Config), click on it.
  3. Select your Ubidots Plan.
  4. Intro your Ubidots Token.
  5. Write the name of your device ("This device will be created automaticaly on Ubidots when you hit save button").
  6. Intro your Electric rates. (it's in dominican pesos by now because I don't know how other countries count your consumtion of energy, let me this in the comments about your country for an App Update).
  7. Place the Alarm Kwhs number and activate the toggle button (when the energy used this day exceed this number, you will get a notification).
  8. You will be able to see all your configurations down in the screen, and you are able to change it or delete it swiping the configs to the left and clicking "delete".

Step 8: Turning the Meter On

Before turning on the device, change the prog-use jumper to use mode.

The board is powered by the micro usb arduino connector. (connect it to a 5v usb adapter).

The board will automaticaly generate a Wifi network called ESP#######, click on it, and a WiFi manager will appear.

Scan and select your house network and you will be able to see that the screen will start showing data, and the App too.

They won't be real measurements because we don't have our sensors connected yet.

Step 9: Placing the Device

  1. Measure and drill some holes to the metal cover of the breakers panel.
  2. Screw the board with the 3D printed protector, place the sensors inside the box and connect them to the board.

Step 10: Ubidots Enviroment

Once you have installed the app and set all your credentials, "TOKEN" and "Device Name".

In your Ubidots device section will appear the device you called before and a bunch of 8 variables organized as you can see in the picture (It's important tha they are in this order).

There are 3 especial variables, the Green ones, that won't be green in your screen, but you will need to click on them, take note of their "api label", delete them and click on "add variable" > "synthetic" > name it as the green ones I showed you, and in the synthetic expression textbox add the text you see in the pictures in the respective textbox.

For kwlm = sum( {{kwh}}, "1M" )

For kwm = sum( {{kwh}}, "1M" )

For kwt = sum( {{kwh}}, "1D")

Note if this changes mess up the order of the variables, please delete them all and start creating them in order:

  1. "irms" (Raw).
  2. "kwlm" (synthetic). = sum( {{kwh}}, "1M" )
  3. "kwm" (synthetic). = sum( {{kwh}}, "1M" )
  4. "kwt" (synthetic). sum( {{kwh}}, "1D")
  5. "kwh" (Raw).
  6. "pf" (Raw).
  7. "potencia" (Raw).
  8. "voltios" (Raw).

Then you can create an Ubidots Dashboard with the charts and widgets you want, showing the data of your variables.

Step 11: Testing It

Here you can see that we have the measurments made by real instruments and the data showed by our device and they are plenty the same, that means that our system is doing a great job.

During the days the device is working and taking notes of the consumption data, you will be able to watch it in the app like the pictures shows.