Whole House energy monitor

0 8256 Medium

Whole house energy monitor that monitors a split phase 120/240 service and publishes to blynk.

projectImage

Things used in this project

Hardware components

HARDWARE LIST
1 Arduino UNO
1 100 Amp current transformer
1 Arduino uno ethernet shield
1 Resistor 10k ohm
2 Capacitor 10 µF
1 Project Box
1 3.5mm female headphone jacks
1 My custom shield for CT hookup

Software apps and online services

Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Solder Wire, Lead Free  
Drill / Driver, Cordless
Plier, Side Cutting 

Story

 

I've been wanting to create a whole home energy monitor for my house for awhile now. I could not find a project anywhere for a split phase north American style service so I finally muttled together one and am quite happy with the results.

 

Most of my favorite projects with an Arduino now involve Blynk. If you haven't used Blynk in any of your projects yet I suggest you look into it because it is a very versatile IOT server with an app for most smart phones that opens endless possibilities.

 

I hope you all bear with me because I'm quite novice when it comes to arduino and this is the first project I will be uploading. There seems to be a lack of projects for energy monitors for a split phase service so I thought I would share it.

 

First of all I used Blynk for this project because its easy to code and publish the readings to my phone for easy monitoring. Now there is two ways you can do this. You can either sign up for a free account using the "NEW" blynk app and have some minor limitations that can be avoided with in app purchases or you can use the old Blynk app 0.1 legacy version and run your own server where it is 100% free. I opted to run the server on a windows machine in my house since I have numerous projects all running blynk because its a lot of fun and running my own server is 100% free. Before I get started on how to set up blynk this is what it looks like all said and done...

projectImage

You can see in the app if shows me real time current draw at the top on both line 1 and line 2.

 

In the middle it draws a line graph of the history of both line 1 and line 2. The history can be live, show you hour by hour, 6 hours at a time, day by day, month by month and for the last three months.

 

The bottom shows the kwh usage for both line 1 and line 2 combined and it has the same history options as the current draw graph above. The only difference with the kwh graph is I have it reset every night at midnight so you can compare your daily kwh usage.

 

So aside from the basic arduino supplies you will need two current transformers I chose two 100 amp current transformers and I will explain below why. But here is the two transformers I used...

projectImage

Now the reason I used 100 amp current transformers is because my house has a 100 amp service. Being a split phase service you need two of them, one for each line coming into the house. Choosing a current transformer can be interesting because the voltage they create only goes from 0 to 1 volt AC. So if you choose a 100 amp current transformer that means 0 volts is 0 amps, 0.5 volt is 50 amps and 1 volt is 100 amps. If you think your house may only use 50 amps at its peaks you would be better off to pick something like a 60 amp current transformer because you have the same 0-1 volt scale but 0-60 amps instead making it a little more accurate then if you had a 0-100 amp current transformer. Me personally I'm not terrible concerned with huge accuracy, I'm more interested out of curiosity what roughly my energy consumption is I chose a 0-100 amp current transformer so I can read the full spectrum of my potential hydro service. The last thing I will say about these current transformers is, there is two different styles, they sell them with a burden resistor and without burden resistor. I chose a current transformer, "CT" for short, with a burden resistor for two reason. One they are safer because any power the CT is creating is being taken up by the burden resistor even when not connected to anything, and two because it is one less thing you have to include in your circuit when creating this project. So if you plan on using my guide make sure you buy a CT with a burden resistor, the easiest way you know your buying the right one is look for 0-1 volt in the description. If the CT your looking at buying has a current spec like 0-50ma you know you are looking at a CT without a burden resistor and it will not work in this tutorial.

 

Now getting into the wiring. The interesting thing about the CT is because it is measuring current on an A/C service it outputs an A/C voltage. The Arduino will not measure a voltage below 0, it is incapable of reading a negative voltage. This is easy to overcome by biasing the ground voltage above 0. In the wiring diagram you will notice two 10k ohm resistors in series and the ground for the CT is wiring in between them. Because the resistors go between the ground terminal and the 5 volt terminal of the Arduino this means that the ground of the CT will not be zero but rather will be 2.5 volts. I have put in a 10uf capacitor in there just to help smooth the voltage. Because the CT is now grounded with 2.5 volts and not 0, that means now when the A/C voltage goes to dip down below 0 volts the Arduino can still read the output. Thanks to the biased ground the output voltage of the CT will now be a sine wave between 1.5 volts and 3.5 volts which all can be read by the Arduinos analog inputs. Other then a couple of resistors and a capacitor the wiring is quite easy. You can use jumper leads or hook-up wires if you like but I opted to have a shield created for easy wiring, see below...

projectImage

I will most likely put these board up on Ebay for a reasonable price to make it easy for people to complete the project.

 

Once you have the circuit all wired up the it will be time to install the CT's on to your service wires. The CT's easily split apart and clamp on to the wires coming in. To gain access to the wires you most likely will need to take the cover off your electrical panel. Most panels will also have a secondary cover over the main breaker, this will also need to be removed. There really isn't a whole lot of risk involved here if you are cautious and think about what you are doing before you do it. You should see three large cables which are your service wires. Colour coding can vary but they should be one white and two black, possibly one white one black one red. The CT's will clamp on the two black wires or possibly the black and the red wire depending on your service, but never the white one. Just be very cautious not to touch anything metal inside the panel. I take zero responsibility to any damage or harm that comes of people working around inside their panel.

 

Once you have clamped on your CT's find a knockout plug on the side of your panel that you can route the CT's leads outside the panel and close up the panel. Here is what my finished product looks like...

projectImage

对于这个项目,我决定使用以太网而不是 Wifi。我最初使用带有 ESP 板的 Wifi,但我发现过度轮询实际上可能会降低网络上其他设备的 Wifi 性能。下面是一张图片或我的 Arduino Uno 带有以太网板和我的 CT 定制屏蔽

projectImage

Once I had it all clipped together I solder on some leads to go to the female 3.5mm headphone ports for a tidy little unit. When your using a four channel headphone port you will be soldering to pins 1 and 2. Pins 3 and 4 are not used for the CT.

 

After everything is connected and tested I installed everything in to a compact little project box...

projectImage

Now lets take a look at the sketch. Starting from top to bottom...

 

The first field of interest is "char auth[] = "**********";" This field is where you are going to put your authentication token that you receive from Blynk when you set up your project. I will explain all about Blynk near the bottom.

 

The second field of interest it "double calibration = 0.32;" This number is the multiplication factor that you will use to calibrate the sketch for the different CT's. I used my electric car that has an onboard energy monitor to calibrate my Arduino making sure it was the only thing using my hydro and slowly adjusted this number until the Arduino was outputting the same watts that my electric car was reporting. 0.32 was pretty close to bang on for a 0-100amp CT and should be similar to you. I plan on experimenting with other CT's and will report my calibration number for other CT's as I confirm their operation.

 

The third field of interest it "int Volts = 121.2;" This field is what voltage your service runs at. You will need to use a multimeter and find out the voltage on an outlet in the house. This can vary anywhere from 105 all the way up to 130. It's not a huge deal to have this accurate because it doesn't affect your amps display. However s will affect your kwh totals if it is not accurate.

 

The last field you have to worry about it " Blynk.begin(auth, IPAddress(***, ***, ***, ***), 8080);". Depending on if you are running a local server or running off of blynks cloud servers this line will change. I will get further into this later when we start setting up blynk.

 

BLYNKSETUP

 

This could be a fairly long subject. I will cover setting up the project with a local Blynk server. You can use Blynk's cloud server but some of the downfalls of the cloud server is every widget you add to your project costs "blynk energy" blynk does give you a certain amount of "blynk energy" for free but if you use it all up you have to have an in-app purchase to add more. The other downfall of the cloud server is I have my project pushing the energy information quite frequently, pretty well every second. I did not want that much traffic to have to go out over my pretty poor internet connection.

 

So that being said we will begin by installing the blynk server. I am not going to cover this as there is a very in depth tutorial already that you can find here...

 

https://osoyoo.com/2021/01/15/how-to-install-a-local-blynk-server-in-your-pc-and-get-a-local-blynk-token/

 

This tutorial every shows you how to find the blynk token for your device once you have created a new project. Once you have that token place it in the following field "char auth[] = "place token here";" on line 6 of the sketch.

 

Now that the token is in the sketch you are done with the arduino. It can be plugged into your ethernet and CT sensors and powered up. Now I will cover how to built the project on your phone. First by opening the blynk app on your phone, you should already have a new project created and it will look just like a blank grid...

projectImage

Click anywhere on the blank grid, it will open a list of widgets that you can select...

projectImage

At the end of the day you can build this project anyway you want but I will show you what I did. Select Gauge. This will place a gauge on the grid

projectImage

Click on the now blank gauge, it will bring up a list of options.

projectImage

The first option we are going to change is the name. The very top field is the name. I edited it to be called "L1" for line 1 of my service.

projectImage

The second option we are going to change is "PIN". Once you click that it will open an option with some fields to change. Select "Virtual" and then "V0" It should look something like this...

projectImage

Select OK and that option window will close. Now "PIN" should have changed to V0. Next where is says "0" directly to the right can stay "0" however change the "1023" to the max current of the CT you selected, in my case it will be 100 for my 100 amp CT. Your setting should look something like this with the exception of the max current might be different based on your CT...

projectImage

Now click OK at the top right of the gauge settings and that should complete your gauge for Line 1. Now follow those exact same instructions again to create a second gauge. Two things you will change about the instructions is name it "L2" instead of "L1" and select PIN "V1" instead of "V0". So your gauge settings for the second gauge should look like this...

projectImage

And you project should look like this...

projectImage

Next lets create away so we can graph and track the current your house is using. So once again click on an empty spot of your project. When the Widget box opens up select "SuperChart" instead of gauge. It should place a blank chart under the two gauges you just made. Click the chart to bring up the settings. The SuperChart settings should look like this...

projectImage

I did not bother with a name for the chart. Click "Name" just above "Add DataStream". Label it "L1" for line 1 of your service. Then direct to the left of it there is a setting button that looks like three sliders. Select it to bring up the PIN you want to graph...

projectImage

Select "PIN" and once again select "Virtual" "V0"...

projectImage

Your DataStream should look like this...

 

Select OK, then hit the back arrow just to the left of DataStream at the top. You should now be back to you SuperChart settings. Click "Add DataStream". It will bring up another field, follow the same instructions above that you used for L1 but Label it L2 and select "PIN" "Virtual" "V1". Your SuperChart settings should look like this...

projectImage

I kept all other settings the default. You can now select "OK" at the top right of the screen to finish your super chart. Your project should now look like this...

 

projectImage

Now that graph is finished. Lets create a chart to monitor how many kwh's we use in a day. So again click on an empty spot of the project. Select SuperChart again. Once the new chart is placed on your project. Select the new chart to edit its settings. In the SuperCharts settings page select the data stream name and call it "kwh" Directly to the right of the name select the settings toggle again. This time at the top I selected a bar graph as I find it more visually appealing. Then for "PIN" select "Virtual" V2"...

projectImage

Your DataStream settings should look like this...

projectImage

And your SuperChart settings should look like this...

projectImage

Select the ok button at the top right to finish your KWH chart. Your project should now look like this...

projectImage

Now the very last thing you have to add is a Real-time clock. This give your Arduino the time of day. This allows your Arduino to reset the kwh counter at midnight at every day. So again select an empty spot of your project to bring up the Widget Box. Select the "Real-time clock" widget under other. It will place a small clock widget in your project. Select it and input your time zone. Now that you have completed your project you have to start it by selecting the play button in the top right corner. Now if I have created my instructions properly and you followed them correctly, it should look something like this...

projectImage

我花了很多时间打字这个项目。我希望我没有错过任何东西,但我会监控以防万一有人遇到问题。

示意图

 

projectImage

Code

Sketch

Arduino

Arduino Energy Monitor Code

CODE
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] = "your blynk token here"; // Put the token from your blynk project here
double calibration = 0.32; // Modify this to calibrate your sensor o.32 should be accurent for a 100 amp CT
double kilos0;
double kilos1;
double peakkilos;
unsigned long startMillis;
unsigned long endMillis;
double RMSCurrent0;
double RMSCurrent1;
int RMSPower0;
int RMSPower1;
int peakPower0;
int peakPower1;
int TotalRMSPower;
int current0 = 0;
int maxCurrent0 = 0;
int minCurrent0 = 1000;
int current1 = 0;
int maxCurrent1 = 0;
int minCurrent1 = 1000;
int zero0 = 516;
int zero1 = 516;
int Volts = 121.2; // Change this field to the voltage your house is supplied with
BlynkTimer timer;
WidgetRTC rtc;

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, IPAddress(***, ***, ***, ***), 8080); //Replace the astrics with the IP address of your local blynk server
  setSyncInterval(10 * 60);
}

void loop()
{
  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
    rtc.begin();
    timer.run();
  } else {
    Blynk.connect();
  }
  readPhase();
  displayKilowattHours();
  displayCurrent();
  displayPower();
  if (hour() == 23 && minute() == 59) {
    kilos0 = 0;
    kilos1 = 0;
  }
  delay(100);
  readPhase();
  delay(100);
  readPhase();
}

void clockDisplay()
{
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.println(currentTime);
}

void readPhase ()
{
  maxCurrent0 = zero0;
  minCurrent0 = zero0;
  maxCurrent1 = zero1;
  minCurrent1 = zero1;
  for (int i = 0 ; i <= 200 ; i++)
  {
    current0 =  analogRead(A0);
    current1 =  analogRead(A1);
    if (current0 >= maxCurrent0)
      maxCurrent0 = current0;
    else if (current0 <= minCurrent0)
      minCurrent0 = current0;
    if (current1 >= maxCurrent1)
      maxCurrent1 = current1;
    else if (current1 <= minCurrent1)
      minCurrent1 = current1;
  }
  zero0 = ((maxCurrent0 - minCurrent0) / 2) + minCurrent0;
  zero1 = ((maxCurrent1 - minCurrent1) / 2) + minCurrent1;
  RMSCurrent0 = (maxCurrent0 - zero0) * calibration;
  RMSCurrent1 = (maxCurrent1 - zero1) * calibration;
  RMSPower0 = Volts * RMSCurrent0;
  RMSPower1 = Volts * RMSCurrent1;
  TotalRMSPower = RMSPower0 + RMSPower1;
  endMillis = millis();
  unsigned long time = (endMillis - startMillis);
  kilos0 = kilos0 + (((double)RMSPower0 / 1000) * ((double)time / 3600000));
  kilos1 = kilos1 + (((double)RMSPower1 / 1000) * ((double)time / 3600000));
  peakkilos = kilos0 + kilos1;
  startMillis = millis();
}

void displayKilowattHours()  //Displays all kilowatt hours data
{
  Serial.print(kilos0);
  Serial.print("kWh          ");
  Serial.print(kilos1);
  Serial.println("kWh");
  Serial.print(peakkilos);
  Serial.println("kWh");
  Blynk.virtualWrite(V2, peakkilos);
}

void displayCurrent()      //Displays all current data
{
  Serial.print(RMSCurrent0);
  Serial.print("A          ");
  Serial.print(RMSCurrent1);
  Serial.println("A");
  Blynk.virtualWrite(V0, RMSCurrent0);
  Blynk.virtualWrite(V1, RMSCurrent1);
}

void displayPower()      //Displays all watts
{
  Serial.print(RMSPower0);
  Serial.print("W          ");
  Serial.print(RMSPower1);
  Serial.print("W          ");
  Serial.print(TotalRMSPower);
  Serial.println("W");
}

The article was first published in hackster, November 21, 2021

cr: https://www.hackster.io/Corymacs/whole-house-energy-monitor-ac018b

author: Corymacs

License
All Rights
Reserved
licensBg
0