Arduino

Simple Arduino Home Energy Meter

arduino-energy-meter-high-consumption

I was walking through the hardware store the other day and I walked past an energy meter which clips onto your home’s electricity mains and then provides you with information on your power consumption and cost estimates for the month. I thought it looked really cool until I saw the price, it was almost five times what I thought it would be! So I decided to try and build my own and Arduino was the perfect platform for it.

I had a look around online at what others had done but they all seemed to be a bit over complicated for a simple home application. Sure, for perfectly accurate measurements you need to monitor both the supply voltage and current but for simple household monitoring which gives estimates cost to the closest few cents, why not keep things simple.

So this meter measures the supply current to your home through a CT (current transformer) and then does a couple of calculations to give you your current, power, maximum power and kilowatt hours consumed. Its also really easy to add your local tariff and display the cost of electricity used to date.

Update: Follow this guide is if you are wanting to build a 3 phase energy meter.

This project assumes you know the basics of Arduino programming, otherwise read our article on getting started with Arduino, and that you know how to connect an LCD screen to an Arduino.

What You Will Need For A Home Energy Meter

How To Make The Energy Meter

First you need to start by assembling the components onto the CT or onto your breadboard in order to create your current sensor which produces a signal which your Arduino can understand. An Arduino only has analogue voltage inputs which measure 0-5V DC, so you need to convert the current output from the CT into a voltage reference and then scale the voltage reference into a 0-5V range.

Assemble the Components

If you are going to be installing your power meter somewhere permanently then you may want to solder the resistors and capacitor directly onto the CT so that they cannot come loose. If you are simply trying this project for fun then a breadboard is perfect.

The basic circuit for the connection of the CT to the Arduino is shown below:

energy-meter-wiring-diagram

The LCD screen shield already picks up on the analogue inputs but only A0 is used by the shield. Simply solder the three leads from your current sensor onto the pin headers on the shield and use A1 as your sensor input as shown below.

current-sensor-connections

Once you have connected all of your components, you need to connect your sensor onto what you want to monitor. If you are wanting to monitor a couple of appliances then you should connect the CT onto the input lead of a multi-plug, anything you plug into the multi-plug with then be counted.

Alternately, you can connect the CT directly onto your home’s mains supply and monitor the whole houses usage as has been done here. Either way, you need to put the CT around one of the supply cables, preferably the red “live” cable. Be sure to only put it around 1 as it will not work if it is around both and it can’t be connected around the earth wire (yellow, green stripped wire) as energy is not drawn through this wire. If you are connecting it to your mains, connect it to one of the output wires after the main breaker as shown below.

ct-on-mains-feed

NB – Be careful when connecting the power meter to you homes mains and make sure that the power to your board is switched off before doing anything in the mains box. Do not remove any wires or remove any screws before checking with your local authority, you may require a certified electrician to install the CT for you.

Choosing Different Components

There are essentially four components which need to be chosen or correctly sized for you energy meter.

Choosing A Current Transformer

The first is the CT or current transformer. The one used here is the Talema AC1030 which can sense 30A nominal and 75A maximum current. At 220VAC, it can theoretically sense up to 16.5kW for short periods of time but it is sized to continuously sense 6.6kW which is suitable for a small household. To calculate how many amps yours needs to sense, take the maximum  continuous power your are expecting to sense and divide that by your voltage (usually 110V or 220V depending on your country).

Sizing The Burden Resistor

Next you need to size your burden resistor R3, this converts your CT current into a voltage reference. Start by dividing your primary current (the maximum as used above) by your CT’s turns ratio (available on the data sheet). This should be around 500-5000 to 1. This article worked on 42A with a turns ratio 0f 1000:1 giving a secondary current of 0.042A or 42mA. Your analogue reference voltage to the Arduino is 2.5V so to determine the resistance you use R=V/I  – R=2.5/0.042=59.5Ω. The closest standard resistor value is 56Ω, so this was used.

Here are some options on different CTs and their ideal burden resistors (in standard sizes):

  • Murata 56050C – 10A – 50:1 – 13Ω
  • Talema AS-103 – 15A – 300:1 – 51Ω
  • Talema AC-1020 – 20A – 1000:1 – 130Ω
  • Alttec L01-6215 – 30A – 1000:1 – 82Ω
  • Alttec L01-6216 – 40A – 1000:1 – 62Ω
  • Talema ACX-1050 – 50A – 2500:1 – 130Ω
  • Alttec L01-6218 – 60A – 1000:1 – 43Ω
  • Talema AC-1060 – 60A – 1000:1 – 43Ω
  • Alttec L01-6219 – 75A – 1000:1 – 33Ω
  • Alttec L01-6221 – 150A – 1000:1 – 18Ω
  • CTYRZCH SCT-013-000 – 100A – Built In Burden Resistor – Buy Here
  • TOOGOO SCT-013-000 – 100A – Buy Here

The capacitor used is 10µF which should be sufficient for most CT ranges for household applications.

Finally you need two dividing resistors to get the 2.5V reference voltage from the Arduino. They must be the same value, so R1=R2 and we don’t need much current so this articles uses two 100K resistors.

Upload the Sketch

Now you can upload your sketch onto your Arduino, if you haven’t uploaded a sketch before then follow this guide on getting started.

Update – The code has since been modified to make use of the millis() function, see end of section for updated code.

Here is the link to download the Meter code.

Because your setup, CT , resistors and input voltage may be different, there is a scaling factor in the sketch which you will need to change before you will get accurate results, see below for calibration. If your LCD is connected to the same pins as used here and your CT is connected to the same input pin, you should at least get the screen populated with some figures although these will most likely be incorrect and some may be negative.

If you don’t want to use or don’t have an LCD screen, you can also modify the sketch to output to the Arduino IDE’s serial window as shown below.

Here is the link to download the Meter Serial Output code.

Code Update

The original Energy Meter code made use of a fixed time period for calculating the kilowatt hours consumed, this was based on a 2050ms cycle time and was fairly accurate.

The code has since been modified to make use of the built in millis() function which calculates the exact cycle time for each cycle in order to improve the accuracy. It only makes around a half a percent improvement in the accuracy of the calculation but its the better way to do it.

Here is the improved code:

Here is the link to download the updated Millis Meter code.

For those of you who have read that the millis() function goes into overflow after about 49 days, the code deals with the rollover automatically by making use of the unsigned long variable. For example, if the overflow happens at 10000, the start millis was 9987 and the end millis was 2031, the difference would be 2031-9987=-7956 but the value can’t be negative as it is unsigned so it becomes -7956+10000=2044 which is the correct duration.

Calibrate the Current Reading

As mentioned above, because your setup, CT , resistors and input voltage may be different, there is a scaling factor in the sketch which you will need to change before you will get accurate results.

To calibrate your energy meter, your need to be sure that the current that your meter says is being drawn is what you expect is actually being drawn. In order to do this accurately, you need to find a calibrated load. These are not easy to come by in a normal household so you will need to find something which uses an established and consistent amount of power. I used a couple of incandescent light bulbs and spot lights, these come in a range of sizes and their consumption is fairly close to what is stated on the label, ie a 100W light bulb uses very close to 100W of real power as it is almost entirely a purely resistive load.

Plug in a small light bulb (100W or so) and see what load is displayed. You will now need to adjust the scaling factor uses in the calculation line:

double RMSCurrent = ((maxCurrent – 516)*0.707)/11.8337

In this case it was 11.8337, it may be higher or lower depending on your application. Either use linear scaling to calculate this figure or, if you’re not good with math, play around with different values until the load you have plugged in is shown on the energy meter’s screen.

Once you have your energy meter calibrated, you reset it and leave it to do its job. Below are two images of it in use, both with a low power input and a high power input.

arduino-energy-meter-low-consumption

The first number displayed is the instantaneous current followed by the instantaneous power. On the bottom line, the kilowatt hours used since reset and then the maximum recorded power since reset.

arduino-energy-meter-high-consumption

And a video of startup:

Autodesk Circuits Diagram & Simulator

Please note that Autodesk Circuits doesn’t support a current transformer. A signal generator has therefore been used to generate an example signal however it is not really suitable for the application, therefore the displayed energy consumption is erratic.

How did this project go for you? What have you used it to monitor? Let us know in the comments section below, we may even put some of your work into our article to help others. Also feel free to post any questions or queries you may have, if you are asking, chances are someone else is wondering as well.

103 Comments

  1. Dani

    Great article!!! You have writing talent.

    Where did you buy your Current Sense Transformers (CT)?

    • The DIY Life

      Hi Dani,
      Thank you. I picked up the CT from a local electronics supplier. They are available on eBay, probably Radio Shack as well. There are a number of online suppliers around.

  2. Richard Westhed

    Good work! Thanks.

    I tried this but extended it with 2 extra CTs, one for all three phases. I do not know why, but all three give me exact same values and they do not change a bit. So, I figure this has to do with the “if (maxCurrent <= 517) maxCurrent=516". Were does this number 516 come from? (Surely a dum question to you… 🙂 ).

    Best regards Richard

    • The DIY Life

      Hi Richard,
      Great to hear you’ve tried this out on a three phase installation.
      You essentially need to triplicate lines 22 to 42, or run a loop three times (one for each phase). Make sure that you change line 27 where you read the analogue input to currentPin1, currentPin2 and currentPin3 so that the Arduino is reading inputs from the three different CT’s. Unless your code is overwriting variables incorrectly you should always land up with different figures for each phase this way.
      To answer your question, we are only looking at the top half of each phases sine wave. The Arduino’s analogue map function maps from 0 to 1024. 512 is therefore the middle/zero line of the sine wave in an ideal environment, in my case 516 was the “calibrated” zero line. The line of code you mention is simply throwing out the negative half of the sine wave so it is unlikely to be giving you problems.
      If you still run into problems, email your code through to me: admin(at)the-diy-life.com and I’ll have a look at it.
      Hope this helps!
      Best Regards

    • The DIY Life

      Hi Richard,

      I have just published a guide on how to make a 3 phase energy meter – go have a look at it http://www.the-diy-life.com/simple-3-phase-arduino-energy-meter/

      Hope it helps!

  3. Mike

    Greetings,

    Thank you for your article. It has been very helpful to me.
    I have a couple of novice questions.
    I had started building an energy monitor based on what I had read on openenergymonitor.org.
    I am using an Arduino Uno Rev 2, and four SCT-013-030 CTs. My main goal is to calculate kw used by my heat pump (Condenser, AHU and heat strips) and my hot water tank.
    I stumbled onto your project and I have been using your Arduino sketch, because you have the kwh calculated.
    I have yet to do calibration on the kwh, but I did adjust to get the current fairly accurate.
    I can’t figure out what the 2.05 is on line 43. Can you explain to me how you are coming up with kwh?
    How are you calculating kw measured over time?

    Thanks,
    Mike

    • The DIY Life

      Hi Mike,

      Great, thank you. It’s always good to see people are trying this project out. It sounds like you are doing quite a nice adaptation by monitoring multiple appliances/devices.

      To calculate the kilowatt hours, you multiply your amp reading by the supply voltage and then by the time period converted into hours, that will be watt hours and then divide by 1000 to get kilowatt hours.

      The line in the code you are referring to is doing the unit conversions, from seconds to hours and into kilowatts, as described above and the 2.05 is the time period (in seconds) I am referring to. The delay in the code is 2000 milliseconds and the loop through the code takes the Arduino about 50 milliseconds to run through so the time period is 2050 milliseconds or 2.05 seconds.

      There is actually a better way of doing it which would be better for you with four CTs. Using the millis function, record the start millis and finish millis, calculate the difference and that is your time period. It’s more accurate but I just haven’t had the time to change it in the code.

      Hope this helps, let us know how it goes!

  4. Marius

    Firstly id like to say Great write up
    Been looking for someone to explain as good as you did for a few months now 🙂
    Hi just a silly question
    what voltage must the 10uf capasitor be?

    Thanks

    • The DIY Life

      Hi Marius,

      Thank you, happy to hear we could help. The capacitor only sees around 2.5V so you can use a small 10V capacitor.

      Best regards.

  5. Marius

    Hi

    I have managed to put it together using a 33ohm burden resistor because i have the sct-013-010 current transformer and saw that i must use a 33 ohm burden dont know if this is correct

    I also used the R1 and R2 100k resistors and getting some values back .. so happy with that
    But my question now is this sound correct?
    I have also tried now running a small heater with 2000w but the numbers goes up and down and i really dont know what to do from here
    is there anything i am doing wrong? or am i doing everything wrong
    Just trying to figure this out and get it solved lol

    Thanks again

    • The DIY Life

      Hi Marius,

      From what I can tell, there are two possible reasons you are getting fluctuating values:
      The first is the CT, the sct-013-010 has a built in burden resistor so you should remove your burden resistor and connect the one wire from the CT to Arduino A1 and the second to the middle of your two 100K divider resistors.
      The second depends on your location and local supply voltage. If you live in the USA then the supply voltage is 110VAC, your CT can only measure up to 10A so (very simplistically) you can’t measure any device which uses more than 110×10=1100w. You will burn your CT and its burden resistor out. If you live in a 220VAC area then you should be able to measure 2200w so you won’t have a problem with your heater.

      Hopefully this helps. We were all there once so keep trying and you’ll come right!

  6. Marius

    I tested it today again and seems alot better only thing now is the calibration could you perhaps explain the calibration for me i am in a 220vac area
    If i start say the heater it shows a 6000w out and if i then stop that and start a laptop charger it still give me the 6000w

    I am not sure as what to change here “double RMSCurrent = ((maxCurrent – 516)*0.707)/11.8337;”
    Oh Forgot to mention that my CT i the SCT 013-000 the 100a max and 50ma

    It feels so close now but yet so far 🙂

    • The DIY Life

      Hi Marius,

      There seems to be a problem with your input, a laptop charger and a heater should give you substantially different figures. If you plug something of low power in does the 6000W drop? Does it drop down when you unplug the heater?

      If your sensor is the SCT 013-000, then it is a current output sensor and it will indeed need a burden resistor. The ideal burden resistor size would be R=2.5/0.05=50Ω, you’ll have to use a 51Ω or 56Ω standard resistor. This is probably the reason for the above reading of 6000W, you are overloading the Arduino input.

      The scaling figure in the line you are looking at is the 11.8337. If you are plugging a 2000W heater in and it is displaying 6000w then you need to divide the figure by three (6000/3=2000), so you’ll put 3.9445 into the line instead of 11.8337. Your display should now show 2000W.

      You’re almost there!

      • Marius

        Hi

        I eventually got it working Yay
        I realized that it did not want to work on my breadboard so i made a pcb and soldiered everything an and bobs your uncle all working

        Now for the display i have the IIC / I2C 1602 lcd and it needs the 5v on the arduino
        Do you suggest i reconfiggure the code to use the 3.3v for the energy monitor and the 5v output for the lcd?

        Or is there another way?

        I saw when using the 3.3v with the lcd the contrast is verry light can hardly see anything on the lcd

        And thanks again for all your help would not have been able to do without your help

        • The DIY Life

          Hi Marius,

          That’s great, well done!

          To connect the LCD screen, have a look at our LCD screen connection guide, it should work for your display. You don’t have to reconfigure anything in the code, there is no reason why you can’t connect both the LCD and the energy meter to the Arduino’s 5V pin. The screen should still work on the 3.3V pin, the backlight will just be dim. The contrast issue you are referring to can be adjusted by turning the pot outlined in our guide, this adjusts the contrast. By default the contrast will be extremely light.

          No problem at all, we’re glad you’ve managed to build one of our projects!

  7. Marius

    Hello

    I have managed to get the project fully working with the LCD and it is really awsome
    The last thing id like to ask is how do i set it up for 3 Fase do i replicate the setup x 3 and replicate the code 3 times and add the 3 together?
    I dont know anything about 3 fase :p
    Thanks again

    • The DIY Life

      Hi Marius,
      That’s great! Could you possibly send us a photo to put up?
      Yes, for a 3 phase setup you just replicate the CT circuit 3 times and then triplicate the current measurement lines of code. You’ll need to add to the display as well, possibly edit the layout to show all three kWh on one screen and the powers on the next?

      • Marius

        HI

        I will indeed mail you a pic once i am completely done with the project it does not look too good at the moment with wires everywhere …hahah

        regarding the 3 phase can i connect all 3 ct’s on the 5V input on the arduino with the lcd?
        and do i connect the ct’s on each analog port ex A1, A2 , A2 ?

        Just want to make sure before i blow something up :p

        Thanks

        • The DIY Life

          Hi Marius,
          Great, thank you.
          Yes, you can connect all of the CTs to the 5V output. The CTs just use the voltage as a reference, the circuit draws very little power from the Arduino.
          Yes, connect each CT to it’s own Arduino analog input A1, A2 and A3 and then modify the code to take readings from the three different inputs.

    • The DIY Life

      Hi Marius,

      I’ve just published a guide to make a 3 phase energy meter, have a look at it – http://www.the-diy-life.com/simple-3-phase-arduino-energy-meter/

      Hope it helps!

  8. This is indeed a great article. I was able to construct the meter based on your instructions to measure the energy use at a remote cottage we have. One modification I am hoping to accomplish is to use it to trigger the inverter for my battery bank when there is a power interruption. I was able to build the circuit with a relay that will get triggered once the monitor indicates no power. I am stuck though on how to pass the parameters from your program to the subroutine that would trigger the relay to switch the inverter and have the screen to say”Now running from batteries.” This “loop” would have to be active as long as there is no power. I tried to use IF and WHILE functions but couldn’t get it working (it’s been a while since I have worked in C). Could you give me a suggestion on what is the best way to achieve that task?

    • The DIY Life

      Hi Pawel,

      Thank you and its great to hear that you’ve managed to build the energy meter.

      The problem I can see with what you are trying to achieve is not with the code but with the actual hardware and the operation of the CT. You won’t have a problem triggering the relay to turn on the inverter when the monitor indicates no power. Once the relay is triggered however, you will be switching your home’s load onto the inverter and this means that even if your home’s mains comes back on, the load will still be on the inverter so there will be no “flow” of electricity through the mains CT and therefore your energy monitor won’t know that the power has come back on.

      My suggestion would be to put a small AC relay directly onto your mains with one of the normally open contacts supplying the Arduino’s 5V circuit back to an input pin. This input would then always give you a reliable “mains on” or “mains off” signal regardless of the current through the CT and this could then be used to change the display and trigger the inverter both on and off.

      Once you’ve got the hardware right, the WHILE loop is the correct thing to use to change to the inverter loop. Something like – WHILE (digitalRead(relayInput) == LOW) will run the inverter loop until the mains picks up again and the mains relay contacts the Arduinos 5V back onto its relayInput.

      If you put the CT in after the inverter and mains changeover relay you could even add a second screen to the energy monitor which tells you how much power has been used from the mains and how much has been used from the inverter.

      I hope I am on the right track with what you are trying to achieve!

      • Thanks for a quick reply. Actually the inverter we have (WAGAN Tech 3000) works independently from the main power line. Unlike the more advanced grid inverters, we have to physically flip a remote button to turn it on when the power goes down and click it again to turn it OFF when it is back. So the CT will actually detect that there is “juice’ back in the supply lines. In order to make sure that the monitor/switch can can run off the 12V battery power when the power is down I have added a small DC to DC power supply to the circuit.
        My programming problem was with the WHILE loop, as I wasn’t sure how to get the information about the amount of current flowing in the main supply line to a subroutine/function that would evaluate that there is no power and activate the inverter switch relay. Can it be done?

        • The DIY Life

          Ok great, you should definitely be able to do the change with the energy meter but it’s a bit more involved than you might initially think.

          When the power dies at your home and you turn on your inverter, what isolates the inverter circuit from the mains circuit so that you are not feeding power back into the grid and to your neighbours homes for example?

          I still see a problem in the way you need the CT to detect “juice” back in the supply line. If you’ve changed all of your electrical demand onto your inverter, there will be nothing to draw power from the mains when the power does come back on. The CT doesn’t measure if there power available, it can only measuring power flowing through it. With nothing trying to draw power from the mains, the CT will still register no reading even when the mains comes back on. You need something which will continuously be trying to draw power from the mains (a light bulb for example) so that when it comes back on, the CT starts reading energy usage and can then turn the inverter off and change the supply back to the mains.

          Once your code has detected no current, use a WHILE (maxCurrent == 516) loop to keep checking that the current is still 0. Put lines 25 to 36 of the original code into the loop to keep reading the current with a delay of say 1 second – delay(1000) between checks. The value of 516 is the middle of the current waveform and hence 0 current.

          There’s no reason why that shouldn’t work to turn the inverter on and off, now you’ll just have to manage how you switch between the mains supply and inverter supply, this can also be automated by the Arduino.

          • Thanks for your suggestions Michael. I was able to figure it out based on your recommendation. I had to add an extra line to the WHILE loop (if (maxCurrent > 517) break;) to break out of the loop.

            while (maxCurrent == 516)
            {

            int current = 0;
            int maxCurrent = 0;
            int minCurrent = 1000;

            for (int i=0 ; i= maxCurrent)
            maxCurrent = current;
            else if(current <= minCurrent)
            minCurrent = current;
            }
            if (maxCurrent 517) break;

            if(current >= maxCurrent)
            maxCurrent = current;

            To answer your last comments: the system we have already has an automatic line disconnect by POWERMAX, which switches from the line power to battery power. Unfortunately it does not have a low voltage relay in it to turn the inverter on and off. My original idea was to add one to it but I hate mucking around with high voltage. That’s why I was interested in your meter. Other than disconnecting and reconnecting two panel feeds it involves only low currents and as an added bonus we will know how much power we are using when the emergency system is on. Thanks again!

          • The DIY Life

            That’s great, let me know if you manage to get it all working!

  9. Kevin A.

    Good day,

    First of all, this was a really great article and the best one yet for similar projects that me and my colleagues have found. We were actually looking for projects like this to integrate into our own project. I was wondering if it is possible to use your project for any devices such as air conditioning units, refrigerators, etc? Also, can you recommend any cheap clamp on CTs? Or some other way to utilize the through hole CT for the wires without modifying the device itself? Modifying as in cutting the wire or removing the plug to insert the CT.

    • The DIY Life

      Hi Kevin,

      Thank you for the great feedback. It depends what you are wanting to achieve with the energy meter and how modern the AC or refrigerator is. More modern ones tend to have better power factors and will work better with this energy meter. Older ones, especially refrigerators have really bad power factors so the reading won’t be that accurate.

      As far as decent and reasonably priced clip on CT’s, your best bet is with the SCT013 range. They are reliable and some versions come with the burden resistor built in already. You can’t really modify a CT to get it over the wire, you’ll need to loosen the wire at the terminal and thread the CT through if it is not a split type.

  10. mico

    do you use a current sensor here an acs712??

    • The DIY Life

      Hi Mico,

      The acs712 is a hall effect transducer, so it works a bit differently and the sensor requires a hard wired, in line connection to the load which is what I was trying to avoid with this. The connections to the Arduino are the same without the resistors and capacitor 1, one connection to Gnd, one to 5V and one to analogue. The code is also fairly similar.

  11. karthi

    bro i have problem when i upload the code to arduino
    i get response like 0.00kwh
    but current is calculated but the kwh finding not working
    kilos = kilos + (RMSPower * (time/60/60/1000000)); this line get zeroed after execution
    plz help

    • The DIY Life

      Hi Karthi,

      Are all of the other three fields on your display showing the correct values?

      Remember that there is a time delay on the kWh and this field will take some time to start increasing depending on your load. For example, if you’re drawing 200W, its going to take about 3 minutes for 0.01kWh to show up on the display.

      If this still does not work then try the first version of the code and see if that works on your energy meter? It’s a bit simpler and has been tested by far more people.

      Let me know if you come right.

      • Anonymous

        thanks lot

      • karthi

        thank you for your reply
        the first code work properly it display the correct value
        but the 2nd code only kwh line zeroed power=200w
        time value 2050; and (time/60/60/1000000))= 5.69444444e-7* power
        after serial print show zero kwh iam waited for 30 minutes it show only zero

        • The DIY Life

          Hi Karthi,

          Thank you for the feedback. There may be a problem with the way the Arduino handles the different data types, being int, double and unsigned long.

          Try this line: kilos = kilos + ((double)RMSPower * ((double)time/60/60/1000000));

          Let me know if that works otherwise I’ll have a look at it in more detail.

  12. mico

    hi, what do you mean for “RMS”current andd “RMS”power

    • The DIY Life

      Hi Mico,
      RMS is the root mean square. RMS current is the peak current multiplied by 0.7071 or divided by the square root of 2. RMS power is the apparent power or VA in this case.

  13. mico

    hi sir.. in this project i used ACS712 instead of CT and i havnt change any codes i till follow what input their .. and when i runned it the peak power and RMSpower are the same out put which is 6663W.. i use a 9v battery as well as an LED light.. to test it it apperas 6663w both the peakpower and RMSpower and 30.29A in RMScurrent and yet i runned it for almost 1 hr then their is no changes in kWh..
    can you please help to figure this out..
    Thanks sir..

    • The DIY Life

      Hi Mico,
      I am not too familiar with the ACS712 but it appears to be a scaled Hall effect sensor. It gives you a scaled voltage output proportional to the input voltage so there is no need for the voltage divider, burden resistor or the capacitor, you can connect it directly to the Arduino and the zero line of the sine wave should be Vcc/2.

      Your second problem is that a 9V battery and an LED light are DC, this software is written to measure AC power. To calculate DC power you can simply multiply the measured battery voltage by the measured current through the ACS712.

      Lastly, the voltage you are using seems high for an LED but assuming its a large LED and the voltage is correct, it would likely only draw around 20-40mA. A kilowatt hour is a huge unit of measurement for an LED, you’d have to leave the LED connected for around 28 hours to register 0.01kWh. Rather consider using watt hours or more commonly amp hours for small DC circuits.

  14. tesla

    Cool project

  15. Alay

    hey it’s a amazing work you guys really awesome i just want to know i’m from India and here we have 50hz 10amp 230v in regular home supply so AS-103 is good for me or AC -1030 is good

    • The DIY Life

      Hi Alay,
      Thanks for the positive feedback! If you maximum current is 10A then use the AS-103, you’ll get better resolution. The AC-1030 will also work but it is quite a bit bigger than you need for your supply.

  16. MICO

    hi sir can ask how do you get this "maxCurrent <= 517" and "maxCurrent = 516;" wer did you get this and what formula did you use??
    in my case i use SCT-013 100A:0.05

    (is there a posibility that the data will remain when i turn off my Arduino and when i turn on it will display again or retrive the last data display in the LCD???

    and why is it when i remove the CT or turn off the load there is a continous reading in my Arduino ??
    please help me for my concern .. thank you..

    • The DIY Life

      Hi Mico,

      The figure maxCurrent = 516 is used to filter out only the top half of the sine wave. In my case, just under 516 happens to be the zero line of the sine wave. If you’ve used the correct divider resistors yours should be similar.

      The Arduino doesn’t permanently store any variable data, if you turn it off then you loose all your recorded data. To store the data you’ll need to use an SD card shield or provide a battery backed up power source so that the Arduino never loses power.

      If you’re getting a reading with your CT removed then you haven’t set your calibration factors correctly. I suspect that your circuit isn’t giving you a sine wave zero line at 516, therefore it is “reading current” even though nothing is connected. Try adjust 516 upwards until you get zero when the CT is removed. Note that only the CT should be removed, not the capacitor and burden resistors.

      Hope this helps.

  17. MICO

    okay thank you for the help sir.. what if am going to use sim900a is their a posibility that the flow of current will affect .. in may case when i use the sim900a is connected with the breadboard where the capacitor, resistors and CT pinned there is a change in displaying or sensing current in my LCD

  18. Rikky

    Hi Sir

    I am using Talema 1060 Current transformer instead of 1030.
    Burden resistor = 39ohm.
    What should be the calibration factor so that I can get accurate power for different loads.

    I tried to calibrate using 100wt load and got the correct result but when i changed the load (200wt) didn’t get correct output.Please Suggest me the proper way to calibrate this CT.

    • The DIY Life

      Hi Rikky,

      Your burden resistor is fine although it is slightly undersized, you should probably go with a 43Ω resistor just to make sure you don’t overload the CT when you are working at its upper limit (around 60A). If you aren’t really measuring anything close to 60A then its not a problem and 39Ω is fine.

      The calibration factor cannot be calculated beforehand, it depends on a number of factors and is different for each setup. The only easy way to calibrate it is to take readings from the screen for a few known loads (it appears that you have done this) and then calculate the calibration factor using a linear best fit. What are you using as your 100W and 200W loads, how accurate are they? What did you get for the 200W load?

  19. ProfessorSP

    Hi

    Great and detailed tutorial.
    How would you save the information onto a SD card.
    And how would you connect this to your devices.

    Thanks

    • The DIY Life

      Hi ProfessorSP,

      Thank you for the great feedback.

      To save the information onto an SD card, you’d simply need to add an SD card reader. The Arduino library already has a number of functions built in for reading and writing to SD cards, these are available on the Arduino forum. If you do a search on Ebay, there are a number of SD card breakout boards which you could use, these typically require a bit of circuitry to connect to the Arduino though. If you are looking for a more simple solution, the standard Arduino Ethernet shield has an SD card reader built in. The only problem is the the Ethernet Shield & this LCD shield share a common pin 10 and pin 4. You could however just rewire/jumper the 10 and 4 pins to free pins (0,1,2,3) and this would solve the problem.

  20. Stas

    Hi DIY Life,
    thanks for idea. I made such meter and it works, yet need some calibration. Please inform the time taken for reading raw data. Here is just 200 reads by Arduino sampling frequency:
    for (int i=0 ; i<=200 ; i++) //Monitors and logs the current input for 200 cycles to determine max and min current
    I guess at least 2 full AC sine waves should be monitored for max and min. That is AnalogRead should work for 40ms period. Or maybe I am wrong in a shape of input signal at pin? Thanks

    • The DIY Life

      Hi Stas,
      The time taken to read the data is around 50ms depending on the Arduino’s processing speed. This is why the original code uses a time of 2.05 seconds in line 43, a 2000 millisecond delay and the 50 millisecond sample time. You are correct, if your supply frequncy is 50Hz, you’ll need 40ms to measure two full AC sine waves. So this code samples about 2.5 full sine waves.
      Hope this helps.

  21. Stas

    Got it well. Thanks a lot!

  22. ashar

    hi sir,
    i am using sct-013-000 100A-50mA in this project .. i have read your code and place a lcd also 16×2 but i am not getting different symbols on lcd and on serial monitor it did not show anything.i have used 56 ohm burden resistor and 2x10k ohm divider resistors.
    what to do??:(

    • The DIY Life

      Hi Ashar,
      Your burden resistor and divider resistors are correct. Is your LCD at least displaying the text you’ve sent it (current, power etc.) so you know that it is connected correctly? If no values are being displayed then it’s likely that the current transformer isn’t connected to the correct Arduino pin or you’re not measuring any significant current. What are you measuring with your CT?

      • Ashar

        I have connected my ct on the red wire of my extension and i have connected the load to the extension which is my laptop charger and my laptop. .
        Is this the right load?

        • The DIY Life

          That’s all correct but the load is probably too little to register. You CT is setup to measure 100 amps which at 110V equates to around 11000 watts. You laptop charger is probably only around 60 watts which is not even half a percent of the maximum, the voltage generated by the CT is probably not high enough for the Arduino to detect. Try a larger load or a smaller CT, a 5 amp CT is enough for a laptop charger.

          • ashar

            yeah. the purpose of my project is definitely measure the main current and power but i just want to know that my ct is working on small loads and give me accurate readings (watts), or not before clipping on the mains thats why i use smaller load. and there is 220v in my region so what load or how much load i should attached to my ct so that i will know that i m getting the right values in my lcd display.

          • The DIY Life

            Ok that’s great although even for a large household that CT is a bit oversized, especially on 220V. It could theoretically measure around 22000 watts and in my experience, a household typically draws around 6000 watts maximum. You’ll get better accuracy from a smaller CT. On 220V the laptop charger definitely won’t even register as the current halves again. Try connecting the CT to a large heater or stove or kettle etc, something that draws a lot of power.

  23. Ashar

    thanks for your kind response, that really helps..
    so i have to buy sct-013-030 30A max..30×220=6600watt. got it 🙂

    RMSCurrent = ((maxCurrent – 516)*0.707)/12;
    kilos = kilos + (RMSPower * (2.05/60/60/1000));
    can u explain these factors please and i just want to know that, these factors are fixed or i have to change them according to the ct??

    • The DIY Life

      Yes, a 30A CT would give you more accurate results.

      All of those factors are constants with the exception of the 12 in the RMSCurrent line, this was actually 11.8337 in my code. You’ll need to adjust this value up or down until your meter displays the correct load. Plug it into a known load, like a 200W light bulb for example and adjust this value until your meter reads 200W.

      • Ashar

        Thanks. that means alot.. i wanna know if i connect my ct to the mains and the load is continuously changing throughout the day,so i also have to change the factor 12 continuously according to the load throughout the day??
        Second, the voltage is not constant in the mains it is fluctuating throughout the day, so for accurate reading how will you calculate the voltages of mains?
        Thanks in advance..

        • The DIY Life

          No you won’t need to constantly change it. The Arduino uses this factor as a reference for future loads. It compares the varying load to this factor in order to determine the actual power being used. You only have to do this calibration once.

          I’m not sure where you live but your voltage really shouldn’t be fluctuating significantly enough to have an effect on the readings. If that is the case then you’ll need to incorporate an AC voltage measurement module onto one of the Arduino’s inputs. This will then get fed into the RMS power calculation line.

          • Ashar

            Thanks for the positive response,so i have to adjust the factor one time with the specific load then after getting accurate power i can put on more loads and then it will also give me accurate power. Is that right?
            Secondly,i live in 220v region and it is different place to place for example if 210 v coming in my house, it not coming in my friends house it has 190v in his house .. thats why i need to calculate accurate voltages as well,so i want to know voltages of main without cutting the wire just like i calculate current with ct .. can u help me in this?

          • The DIY Life

            Yes that’s correct. That factor will remain the same for a higher or lower load.

            If the voltage varies per house then I’d suggest you measure it once off at each house with a multimeter and set that voltage in the Arduino for the duration that it is installed at the house. If the voltage continually changes with time as well then you’ll have to install a voltage monitoring circuit onto the mains as well. You don’t have to cut the wires but you’ll need a physical connection to both wires, possibly at the circuit breaker. As far as I know, there is no way to monitor voltage with a CT. Check your local regulations first though as tampering with your electrical supply without a qualification may be illegal and can be dangerous.

          • Ashar

            Thanks sir it definitely helps me alot,can i check the factor 12 with the load of iron which has 1100watt approx?

            And for Ac voltage calculation,can i use Ac-Ac 9v adaptor with some resistor and capacitor then connect it with the arduino?

            And can i calculate the bill using the kwh or units?

          • The DIY Life

            Yes, you should be able to do the calibration with an iron although it would be better to do it with a load which is slightly more accurate such as a 100W light bulb.

            Yes you can use an AC to AC adaptor but you’ll need to either us one with a 5V output or cut the voltage down to below 5V. The Arduino analog inputs can only handle up to 5V.

            Yes, multiply the kilowatt hours by the price per kilowatt hour and set that to display on the screen to see your bill.

          • Ashar

            Ok so i finally understand the solution of the factor problem..thank you sir

            And for voltage ,as you said that arduino can handle upto 5v so it is 5v ac or dc..?should i use Ac to Ac or Ac to Dc,I have Ac-Dc adaptor which stepdown 220-4.5v 100mA .. can i directly connect it to the arduino? What is the current limit of arduino?

  24. Rudder2

    Thank you for this great project! I was wandering how to measure a United States home with this at the Main. We have 2x 110 legs that when combined are 220. All my major appliances run on 220 but the minor ones 110. At the box the breakers alternate legs as they go down meaning that not all 110 devices run on the same leg. I’m afraid if I hook up to both 110 Main Legs it would double the reading of the 220 devices, which are the most power hungry of my devices like my Air Conditioning, Stove, Clothing Dryer, etc, but read the 110 devices correctly. If I only hook up to one of the legs coming in it would read 1/2 of my 110 devices and the 220 devices correctly. Do you have a way so confiscate for this or am I over thinking it.

    GREAT PROJECT! Thank you for the information!

    • The DIY Life

      It sounds like you’ve got quite an interesting supply to your home. Could you perhaps send a photograph or a sketch of the configuration? I’m not sure I completely understand how it’s all connected and I’ve never heard of 110 and 220 in the same house. Fundamentally, if you trace it back as far as possible, you should only have two wires coming into your home’s supply board (three with earth) and this should either be 110V or 220V depending on your location. You’ll need to hook up the CT to one of these two wires and set the voltage in the Arduino, then it doesn’t matter what happens down the line or how it is split up, everything being fed off of your home’s mains will be monitored.

      Thanks for the great feedback and good luck!

      • Rudder2

        This is the normal supply in the United States. We use 220V for power hungry appliances and 110V for the smaller stuff. We have the two legs that come in and supply 220V and a Neutral that returns to the power company. If you hook up to either of the Legs to the neutral you have 110V if you hook the two legs together you get 220V. The 110V in the house is balanced between the two legs. At 220V you can have 200 Amps At 110 you can run 400 Amps, 200 Amps per leg.

        Here is a picture. The example only uses one leg of the incoming for 110V when in reality homes alternate legs when they supply 110V.
        http://hyperphysics.phy-astr.gsu.edu/hbase/electric/imgele/hse.gif
        We don’t have access to the transformer because it’s on the power poll and it’s illegal to tamper with it. Hope this explains it better.

  25. Florens

    Hello
    Best regards, I have trouble entering program code for LCD display 1602 with I2C support, in order to save usage of input cable in Arduino Uno.
    My question, Do you have a sample code program using this I2C LCD display ,, ?? Please help,,!!

  26. Tim

    I have built the circuit using the SCT-013-000 with IC2 LCD. The wattage stays at 3331W with or without the CT connected. I have ohm the CT , 102 ohms. I’m not sure what the correct value is.

    • The DIY Life

      Hi Tim,
      There is most likely something wrong with your voltage divider circuit. What resistors did you use and double check that the connections are correct. If you’ve used the code as is (without changing any values) then 3331W means you are reading around 3.7V on your Arduino analogue input instead of the midpoint 2.5V which should be given by the circuit. What burden resistor did you use for the CT? You should be using around a 50 ohm resistor.

  27. Tim

    Thanks for the reply. I got the hardware sorted out (using digital pin not analog) . I cant seem to get it calibrated correctly. If i match the wattage with my “kill a watt” meter at ~750.0 w then its off at ~1500 w by about ~300.0 w. reading about ~1800. i can’t get the output to be linear. my midpoint is ~1.63 v (NODEMCU) 3.3v max Vin burden resistor is ~47 ohms which gives me about ~50% of the max amps (50A). A 72 w light doesn’t register on the LCD. What is the best way to embodied this into my mains since i’m US and the breaker box has 2 120v lines so i have 120v and 220v items being powered at the same time. ie AC (220v)and lights(120v).

  28. Anonymous

    i want Code to logg the data and store it , can i get code for it

    • The DIY Life

      Yes this is possible but you’ll need a different shield for this. You need an Ethernet shield which has a built in micro SD card reader, this can then be used for data logging. It is also possible to use both the Ethernet and LCD shield but you’ll need to reallocate some of the pins as the shields both use a few of the same pins.

  29. jawad

    Hello:
    sir i use YHDC 100a CT ..put burden resistor is 33ohm capacitor is 10micro,set the calibration value 60 according to calculation but still did not get the correct result..please help

    • The DIY Life

      Hi Jawad,

      How did you size your burden resistors? Using the formula above R = 2.5/0.05 = 50 ohms. What load are you trying to calibrate your meter with? Your CT measures up to 100A which is quite a lot for a domestic load, you need to calibrate it with a load of around 8kW for a 110V supply or 16kW for a 220V supply.

  30. Steven

    What is the purpose of the capacitor in the circuit? Since you are sensing a sin wave I would think that this introduces an error.

  31. De Smedt

    Measuring AC power is somewhat different then the way it is done in this post !
    This setup only works for resistive loads.
    -> not OK for electronic loads (non linear load) (computers, LEDs, …)
    -> not OK for inductive loads (microwave oven – fluorecent lamps, …)
    -> not OK for capacitive loads
    My next arduino project will be a true AC power meter, I didn’t find anything appropriate with arduino on the Internet.

    • The DIY Life

      Hi De Smedt,

      Thanks for your comment. You are correct, this meter only gives accurate results for resistive loads, as I’ve said in previous comments.

      A meter you are looking for requires voltage measurements to be taken as well, which can only be achieved with a galvanic connection to your mains. Since this meter is meant for DIY enthusiasts and not electricians, I steered away from a direct connection as there are a number of risks and legal implications.

      Good luck with your project!

      • Steven

        Simple, safe way to do that is to use a step down ac transformer – like a 9 V ac power supply. It will be in phase with your mains and give you the phase shift and therefore the load factor. If it is just a simple transformer and not a high quality power supply it will also show you the variations in voltage level.

        • The DIY Life

          Yes, you’re correct. This does however require a galvanic connection to be made to your mains, in most countries this is illegal unless you’re a qualified electrician.

          • Steven

            It doesn’t take any thing more than plugging it into an outlet and reading the 9V supply

          • A transformer secondary is galvanically isolated from its primary, hence using a transformaer is a safe way to obtain a voltage sample.

            The main issues with a transformaer are the phase shift and distortion it induces to the waveform .

            For more info see https://learn.openenergymonitor.org/electricity-monitoring/voltage-sensing/measuring-voltage-with-an-acac-power-adapter

          • The DIY Life

            Thanks Bill, will have a look at the article.

            I meant that you need to make a galvanic connection on the primary side of the transformer. You need to connect it to your mains supply and this is illegal in most countries if you are not qualified/certified to do so. As Steven has said, you could get one which plugs into an outlet and use that, provided you have an outlet near your distribution board.

  32. Pita

    Hi great job on the post
    pls can i use something else instead of the current transformer.
    maybe some resistors and LM385 to step down the voltage instead

    • The DIY Life

      Hi Pita,
      The current transformer is used to convert the main current into a voltage reference. You proposal is to measure voltage, not current.

  33. Marvin

    Good day sir…i am using a 20A SCT013 with a built in burden resistors.. i use ur code with the serial monitor as my display and not lcd..my problem is all the four lines reads 0.. my load is a 300w rice cooker..can u please help me?

    • The DIY Life

      Hi Marvin,
      If you are getting all zeros then there is most likely something wrong with your circuit. Have you checked that you get a reference voltage of 2.5V on the analogue input with no load? Also check that you are reading from the correct analogue input.

      • marvin

        Thank you for the reply sir..please bare with since im new to this diy thing..correct me if im wrong..but from what i understand the voltage output of the ct will vary depending on the load the ct is connected to.. how can i measure the voltage if there is no load sir? I sorry again im a novice for this kind of things.

        • The DIY Life

          You are partially correct, the CT produces current which is passed through the burden resistor to produce a voltage between -2.5V and 2.5V with 0 as the no load voltage. The voltage divider lifts this voltage to a signal beween 0 and 5V with 2.5V as the no load voltage. You should therefore be able to measure 2.5V at the Arduino input with no load if the divider circuit is working correctly.

          • Marvin

            Thank you again sir.gai will try your advice..i will update you soon..hope it will work this time..fingers cross..tnx again sir

  34. ismet

    what is the aim of finding minCurrent?

    • The DIY Life

      Hi Ismet,
      minCurrent was used during my initial testing and debugging to check that the full sine wave was being read. It was displayed on the Serial monitor. In the code for the LCD display version, it is not used for any calculations and may be removed if you’d like to shorten it.

  35. Edward

    But you didn’t add cost for the month?

    • The DIY Life

      I haven’t added costing to the code, its optional. Almost every country, country and region has different tariffs, free portions and methods of charging for electricity so it’s difficult to just create a generic “cost”. If you can make and program this meter then it really should be easy for your to add an extra item onto the display to show your monthly costing.

  36. Carlos Steven

    Hello, Hi great job on the post.

    I have a question, I am using an Arduino Uno R3, and one SCT-013-000, could you perhaps explain the calibration for me i am in a 110vac area.

    what changes need to made in the code?

    Thanks

    • The DIY Life

      Hi Carlos,

      Thanks for the feedback!

      Firstly you’ll need to change your voltage in the code. If you’re using the updated code, change the 220 in line 43 to 110.

      Now try running your meter with (for example) three 100W light bulbs connected and the display should read 300W. It is very unlikely to read correctly initially so you’ll need to change the calibration number in line 42 – 11.8337. Adjust it up or down depending on what is displayed until you get 300W.

      Your meter will then be ready to use. Good luck!

  37. khaydir

    what the blue color on auto desk simulator ?

    • The DIY Life

      Are you referring to the round blue component on the breadboard? This is the capacitor.

Leave a Reply

ALL RIGHTS RESERVED

Close