Introduction: True Power Energy Monitor With Blynk

Recently I have been seeing a number of tutorials detailing how to build energy monitors. However, they all seem to suffer from the same two shortfalls:

  1. They assume that the voltage is constant, which, at least for me is anything but the case. Where I live the supply voltage can swing between 227V and 248V during different times of the day.
  2. They calculate the power being drawn by multiplying the read current with a fixed voltage. This results in "apparent" power which is measured in VA. This is fine for purely resistive loads but not right for inductive loads. For the latter, we need to cater for the power factor resulting from the voltage and current sine waves not being aligned exactly. Using the beer example, you can see that what really matter are the watts.

In this Instructable, I will guide you through the setup of an energy monitor that is more accurate and with the added ability to see its readings from anywhere in the world using your smartphone and the Blynk app.

This is my first Instructable so please bear with me. If you notice something that is incorrect or not clear enough, please let me know in the comments below so I that can correct them. This applies for typos and grammar too!

Step 1: Parts Required

This project utilizes the PECMAC11XXXA integrated voltage/current monitor from controleverything.com which, at the time of writing, is still a prototype but which they tell me will be available on their online shop soon.

Here is the list of the basic items required for this project:

Optional items:

  • PVC Enclosure
  • 2.1mm male power plug
  • 2.1mm female chassis mount power socket
  • Non reversible female chassis mount multi pin connector (at least 4 pins)
  • Matching male plug for above socket

The AC transformer is used for measuring the mains voltage. Make sure that it does not exceed the 9VAC because you might end up damaging the monitor module. The one I used was originally an unregulated DC transformer from which I removed the rectifying components and chose a secondary coil that gave out around 8.75V (just to be on the safe side). The device works with lower input voltages but going too low will decrease the resolution and sensitivity of the voltage reading. No matter what voltage you use, the device will have to be calibrated (more on that later).

Step 2: Setting Up the Particle Photon MCU

If you have not already done so, now is a good time to create a free Particle account. This will be used for managing your Photon MCU and allows you to upload programs to it (among other things).

Once the account is set up, it is time to connect your new Photon to your Particle account. Plug in the Photon to the energy monitor module. Note that the module allows for a number of devices, so just plug the Photon as far to the edge as possible (see picture). Plug in the 12V supply to the power input socket (the one closest to the Photon). You can also use the screw type connector like I did to get power from the chassis mount socket.

Turn on the power and your new Photon will start blinking blue. You can find full instructions regarding how to proceed from here. A word of caution though. I tried setting up the Photon using a Samsung Galaxy S6 but I couldn't because it uses the 5GHz wifi band. Managed to do it with an older Samsung Galaxy S3 Mini though.

Step 3: Setting Up Blynk

Download the Blynk application from the App/Play Store and create an account. Once you are logged in, create a new project. In this project we will place number of labels and a gauge widget that will allow us to view the values being read by the monitor from anywhere in the world. It is also possible to receive notifications for various events, such as the device going offline, but we will not cover that here.

When prompted for the hardware model, choose Particle Photon and then choose WiFi for connection. Then press "Create Project". At this point an AUTH tocken will be sent to the email address you registered with. We will use this code later on in the Photon code.

At this point, you should have a dotted screen on your smart phone. Tap anywhere and you will be shown a list of widgets to place. Choose "Value Display" and a box will appear on screen. Tap the box and name box "Voltage". Tap "PIN" under input and choose "Virtual" from the left column and "V0" from the right column and click continue. Under "reading rate" choose "PUSH". Finally, click on the left pointing arrow at the top left of your screen to save the widget. Repeat the process for True Power, Energy Today, Total Energy and Time using V2, V3, V4 and V5 respectively.

For the current we will use a gauge widget. We will call it "Current" and will assign V1 as input. Change the maximum current to the maximum current you are expecting to read from the current sensor. I set it 20 but it can be anything. Set the label to "/pin.#/A" to show the reading to one decimal point and add the "A" character. Set the reading rate to "PUSH".

Tap the right facing triangle at the top right of your screen and your application will start waiting for signals from the energy monitor.

Step 4: Setting Up the Hardware

Start by unplugging the 12V power from the device. For calibration purposes I set up a power strip with the live, neutral and earth exposed from the outer sheathing so that I can attach the current sensor. The latter is clamped over the live cable. Be extra careful not to have any exposed copper wire. The sensor is not meant to get in direct contact with the live current but simply detect the magnetic field that is generated around the cable. This magnetic field changes intensity depending on the current that is being drawn through the cable and this is how we measure the current.

Attach the black and red sensor cables to the screw type connector on the monitor module taking care not to reverse the polarities. Notice the R and B captions that indicate where the red and black wires need to go. While the sensor can detect the magnetic field no matter how it is connected, note that it is still directional. If you notice you are getting a current reading but not a power reading, just invert the sensor.

Attach the OLED display module to the monitor module using the supplied I2C cable (brown, red, orange, yellow). The OLED module has two sockets - make sure you attach to the IN socket. The other socket can later be used for other devices such as temperature sensors or whatever you can think of, but for the purpose of this tutorial, we will not use it.

Finally, attach the 9V AC plug to the socket near the current connector and the 12V DC plug to the bottom socket (where it was at the time of the Photon setup).

Step 5: Uploading the Photon Program

Login to https://build.particle.io using your Particle account details. Click on the Code button in the left hand side menu ("<>" button) and then on Create New App button. Name your application power_monitor (or anything you like). Copy and paste the code from the attached document over the default code for new applications.

Look up the line with the text that reads "PASTE YOUR BLYNK CODE HERE" and replace the text with the code you received by email from Blynk. Do not share that code with others, unless you want to start receiving signals from other people's devices.

Now we need to "include" the libraries for the Blynk and OLED functionalities. To do so, click on the Libraries icon in the left menu (its under the code button). In the search box type in BLYNK and then click on the BLYNK search result. Click the Include In Project button and then choose the application you created earlier (power_monitor in my example). Repeat the procedure for the Adafruit_SSD1306 library, which is teh one we will use for our OLED module.

This procedure will add the following lines to the top of your code:

// This #include statement was automatically added by the Particle IDE.<br>#include <Adafruit_SSD1306.h><br>// This #include statement was automatically added by the Particle IDE.<br>#include <blynk.h>

Save your code and then click the Verify icon (second one from top left menu).

If everything comes out OK, you can "flash" the code to your Photon using the bolt icon at the top of the left menu.

The led on your Photon will temporarily flash magenta to indicate the code is being written in. Once it is done, the led will start "breathing" cyan and you should start seeing readings on your OLED display and the Blynk app on your smartphone.

Step 6: Calibration and Conclusion

As explained earlier, I used a modified power strip to allow me to read the current. Plug in a resistive load such as a 100W light bulb through the plug through energy monitor. Compare the readings from the plug through energy monitor with the ones on your new energy monitor, specifically the voltage and current readings.

Look up the following two lines in your Photon code and change the 6013 and 30200

values depending on the readings from your monitors:

write_current_calibration(1, 6013);
write_volt_calibration(1, 30200);

For example, if your pass through monitor read 240V and your DIY monitor read 230V, we need to change the 30200 value to:

(240 / 230) x 30200 = 31513

Do the same for the current readings and re-flash the program.

Conclusion

This is just a ball park calibration. The best calibration will be done over a span of time when comparing what your DIY monitor is reading with your utility meter. The power monitor module has the inbuilt ability to record total energy which is saved to non volatile EPROM once every 30 minutes (in case of power failure). To make a more accurate calibration, take a note of the "Total Energy" reading on your monitor and at the same time check the kWh reading on your utility meter. Allow a couple of days to pass and then take a new set of readings. Compare the difference between the new readings and, depending by how much you are off, adjust the current or voltage calibration value (but not both).

Happy making!

Comments

author
bhaskar.anil429 made it!(author)2017-03-15

This looks great.. well done :)

author
OspreyGozo made it!(author)2017-03-18

Thanks! :)

author
Swansong made it!(author)2017-03-15

Thanks for sharing :)

author
OspreyGozo made it!(author)2017-03-18

Glad you like it :)

author
mikenaly made it!(author)2017-03-15

How would this have to be modified to create a truly whole house monitoring system. Id like to measure and add both sides of my house mains to monitor my whole house usage.

author
OspreyGozo made it!(author)2017-03-15

Hi @mikenaly. This project is meant to be a whole house monitoring system and that is why it uses a clamp-on current sensor (as opposed to a pass through currency sensor). All you have to do is place the current sensor over the live cable coming out of the utility meter and the voltage sensor can be plugged to any wall outlet (just choose the nearest/most convenient one).

author
mikenaly made it!(author)2017-03-15

Sorry if i wasnt clear. The thing i was curious about was the changes necessary to be able to monitor both of the hot wires coming in and therefore covering both halves of the breaker box.

author
OspreyGozo made it!(author)2017-03-16

Sorry for the misunderstanding. I am still not sure I understand what what you mean but if you have multiple phases powering your home, it is possible to have two or more power monitoring modules communicating with each other and using a single Photon MCU. The two monitor boards would be connected to each other using the I2C cable and one of the monitor modules would have a IoT Motherboard to Slave Adapter instead of the Photon. It is also possible to power both modules using a single power supply but you would need to short two jumpers on the Salve Adapter. As for the changes to the code, best thing would be to ask in the manufacturer's forums (they are very responsive). I hope I got it right this time.

author
mikenaly made it!(author)2017-03-16

Yes, i have 2 lins comingbin at 120V. They are 180° out of phase giving me a total maximum 240V. I thought this was pretty much standard. To me,after reading your last comment, it almost seems easier to build seperate units and then add the values together.

author
OspreyGozo made it!(author)2017-03-16

Over here in Malta (Europe) we usually get a single 240V phase (as in my case). In case of factories or homes with a high power demand (such as those with elevators) they get a 3 phase supply spaced at 120°. While, as you said, it is probably simpler to have two separate units, combining them will save you an extra Photon while it also sums up the amounts automatically.

About This Instructable

2,947views

85favorites

License:

Bio: I'm a self employed programmer/web developer who builds electronic gadgets mostly for fun but aiming to, one day, start doing it for a ...
More by OspreyGozo:True Power Energy Monitor With Blynk
Add instructable to: