Arduino Energy Meter - V2.0

113,477

497

33

Introduction: Arduino Energy Meter - V2.0

About: I am a DIY hobbyist by passion and Power Engineer by profession. Most of my works are related to Solar Energy and Arduino. Apart from Electronics I love 3D printing, Woodworking and to make crafts from used …

Hello friend, welcome back after a long break. Earlier I have posted an Instructables on Arduino Energy Meter which was mainly designed to monitor the power from the solar panel (DC Power) in my village. It became very popular on the internet, lots of people all over the world have built their own. So many students have made it for their college project by taking help from me. Still, now I am receiving emails and messages from people with questions regarding hardware and software modification for monitoring AC Power consumption.

So In this Instructables, I am going to show you how to make a simple wifi enabled AC Energy Meter by using Arduino/Wemos board. By using this Energy Meter, you can measure the power consumption of any home appliances. At the end of the project, I made a nice 3D printed enclosure for this project.

The goal of creating more awareness about energy consumption would be optimization and reduction in energy usage by the user. This would reduce their energy costs, as well as conserve energy.

Of course, a lot of commercial devices already exist for energy monitoring, but I wanted to build my own version which shall be simple and low cost.

You can find all of my projects on : https://www.opengreenenergy.com/

Step 1: Parts and Tools Required

Components Required:

1. Wemos D1 mini pro (Amazon / Banggood )

2. Current Sensor -ACS712 ( Amazon )

3. OLED Display (Amazon / Banggood)

4. 5V Power Supply ( Aliexpress )

5. Prototype Board - 4 x 6cm ( Amazon / Banggood )

6. 24 AWG Wire ( Amazon)

7. Header Pins (Amazon / Banggood )

8. Male-Female Jumper Wires (Amazon)

9. Screw Terminal (Amazon)

10. Standoff ( Banggood )

11. AC Socket Outlet

12. AC Plug

13. Spring-loaded connector ( Banggood )

14. Rocker Switch (Banggood)

15. PLA Filament-Silver (GearBest)

16. PLA Filament-Red (GearBest)

Tools Required:

1. Soldering Iron (Amazon)

2.Glue Gun (Amazon)

3. Wire Cutter/Stripper (Amazon)

4.3D Printer (Creality CR10S)

Step 2: How It Work ?

The block diagram of the entire project is shown above.

Power from the AC mains is drawn and passed through a fuse for avoiding any damage to the circuit board during the accidental short circuit.

Then the AC power line is distributed in two parts:

1. To the load through the current sensor (ACS712)

2. 230V AC/5V DC Power Supply module

The 5V power supply module provides power to the microcontroller (Arduino/Wemos), the Current sensor (ACS712) and OLED display.

The AC current passing through the load is sensed by the current sensor module (ACS712) and fed to the analog pin (A0) of the Arduino/Wemos board. Once the analog input is given to Arduino, the measurement of power/energy is done by Arduino sketch.

The calculated power and energy by the Arduino/Wemos is displayed on a 0.96" OLED display module.

The inbuilt WiFi chip of the Wemos is connected to the Home Router and linked to the Blynk App. So you can monitor the parameters as well as calibrate and modify different settings from your Smartphone via OTA.

Step 3: Understanding AC Basics

In AC circuit analysis, both voltage and current vary sinusoidally with time.

Real Power (P):

This is the power used by the device to produce useful work.It is expressed in kW.

Real Power = Voltage (V) x Current (I) x cosΦ

Reactive Power (Q) :

This is often called imaginary power which is a measure of power oscillates between source and load, that does no useful work.It is expressed in kVAr

Reactive Power = Voltage (V) x Current (I) x sinΦ

Apparent Power (S) :

It is defined as the product of the Root-Mean-Square (RMS) Voltage and the RMS Current. This can also be defined as the resultant of real and reactive power. It is expressed in kVA

Apparent Power = Voltage (V) x Current (I)

Relationship between Real, Reactive and Apparent power :

Real Power = Apparent Power x cosΦ

Reactive Power = Apparent Power x sinΦ

(kVA)² = (kW)² + (kVAr)²

Power Factor (pf) :

The ratio of the real power to the apparent power in a circuit is called the power factor.

Power Factor = Real Power/Apparent Power

From the above it is clear that, we can measure all form of power as well as power factor by measuring the voltage and current.

Image credit: openenergymonitor.org

Step 4: Currrent Sensor

The AC current is conventionally measured by using a Current transformer but for this project, ACS712 was chosen as the current sensor because of its low cost and smaller size. The ACS712 Current Sensor is a Hall Effect current sensor that accurately measures current when induced. The magnetic field around the AC wire is detected which gives the equivalent analog output voltage. The analog voltage output is then processed by the microcontroller to measure the current flow through the load.

To know more about the ACS712 sensor, you can visit this site. For a better explanation on working of the hall effect sensor, I have used the above picture from Embedded-lab.

Step 5: Current Measurement by ACS712

The output from the ACS712 Current Sensor is an AC voltage wave.We have to calculate the rms current, this can be done by the following way

1. Measuring the peak to peak voltage ( Vpp )

2. Divide the peak to peak voltage(Vpp) by two to get peak voltage (Vp)

3. Multiply it by 0.707 to get the rms voltage (Vrms)

Then multiply the Sensitivity of the current sensor ( ACS712 ) to get the rms current.

Vp = Vpp/2

Vrms = Vp x 0.707

Irms = Vrms x Sensitivity

The sensitivity for ACS712 5A module is 185mV/A ,20A module is 100mV/A and 30A module is 66mV/A.

The Connection for the current sensor is like below

ACS712 Arduino/Wemos

VCC --------> 5V

OUT -------> A0

GND -------> GND

Step 6: Power and Energy Calculation

Earlier I have described the basics of the various form of AC Power. Being a household user, the real power (kW) is our main concern. To calculate the real power we need to measure the rms voltage, rms current and power factor (pF).

Usually, the mains voltage in my location ( 230V ) is almost constant (fluctuation is negligible ). So I am leaving one sensor to measure the voltage.No doubt if you hook up a voltage sensor, the measurement accuracy is better then in my case. Anyway, this method is a cheap and simple way to complete the project and fulfilling the objective.

Another reason for not using the voltage sensor is due to the limitation of Wemos analog pin (only one ). Though extra sensor can be hooked up by using an ADC like ADS1115, for the time being, I am leaving it. In future, if I get time I will definitely add it.

The power factor of the load can be changed during the programming or from the Smartphone app.

Real Power (W) = Vrms x Irms x Pf

Vrms = 230V (known )

Pf = 0.85 (known)

Irms = reading from the current sensor (unknown)

Image credit : imgoat

Step 7: Interfacing With Blynk App

As the Wemos board have inbuilt WiFi chip, I thought to connect it to my router and monitor the Energy of home appliance from my Smartphone. The advantages of using the Wemos board instead of Arduino are: calibration of the sensor and changing the parameter value from the smartphone via OTA without physically programming the microcontroller repeatedly.

I searched for the simple option so that anyone with little experience can make it. The best option I found is using the Blynk App. Blynk is an app that allows full control over Arduino, ESP8266, Rasberry, Intel Edison and much more hardware. It is compatible with both Android and iPhone. In Blynk everything runs on ⚡️Energy. When you create a new account, you get ⚡️2,000 to start experimenting; Every Widget needs some Energy to operate. For this project, you need ⚡️2400, so you have to purchase additional energy ️⚡️400 ( cost is less than $1 )

i. Gauge - 2 x ⚡️200 = ⚡️400

ii. Labeled Value Display - 2 x ⚡️400 =⚡️800

iii. Sliders - 4 x ⚡️200 = ⚡️800

iv. Menu - 1x ⚡️400 = ⚡️400

Total Energy required for this project = 400+800+800+400 = ⚡️2400

Follow the below steps :

Step-1: Download the Blynk app

1. For Android

2. For iPhone

Step-2: Get the Auth Token

In order to connect Blynk App and your hardware, you need an Auth Token.
1. Create a new account in Blynk App.

2. Press the QR icon on the top menu bar. Create a clone of this Project by scanning the QR code shown above. Once it detected successfully, the whole project will be on your phone immediately.

3. After the project was created, we will send you Auth Token over email.

4. Check your email inbox and find the Auth Token.

Step-3: Preparing Arduino IDE for Wemos Board

To upload the Arduino code to Wemos board, you have to follow this Instructables

Step-4: Install the Libraries

Then you have to import the library on to your Arduino IDE

Download the Blynk Library

Download the libraries for OLED Display: i. Adafruit_SSD1306 ii. Adafruit-GFX-Library

Step-5: Arduino Sketch

After installing the above libraries, paste the Arduino code given below.

Enter the auth code from step-1, ssid and password of your router.

Then upload the code.

Step 8: Prepare the Circuit Board

To make the circuit neat and clean, I made a circuit board by using a prototype board of 4x6 cm. First I soldered the Male Headers Pin to the Wemos Board. Then I soldered the female headers on the prototype board to mount the different boards :

1. Wemos Board (2 x 8 Pins Female Header)

2. 5V DC Power Supply board ( 2 pins +3 pins Female Header)

3. Current Sensor Module (3 Pins Female Header )

4. OLED Display ( 4pins Female Header)

At last, I soldered a 2 pin screw terminal for input AC supply to the power supply unit.

After soldering all the headers pin, make the connection as shown above. I used 24 AWG soldering wire for all the connection.

The connection is as follows

1. ACS712 :

ACS712 --> Wemos

Vcc----> 5V

Gnd ----> GND

Vout---->A0

2. OLED Display:

OLED--> Wemos

Vcc----> 5V

Gnd----> GND

SCL----> D1

SDA---->D2

3.Power Supply module:

The AC input pin (2 pin) of the power supply module connected to the screw terminal.

The output V1pin is connected to Wemos 5V and GND pin is connected to the Wemos GND pin.

Step 9: 3D Printed Enclosure

To give a nice commercial product look , I designed an enclosure for this project.I used Autodesk Fusion 360 to design the enclosure. The enclosure have two parts : Bottom and Top lid.You can download the .STL files from Thingiverse.

The Bottom part is basically designed to fit the main PCB (4 x6 cm ), Current Sensor and Fuse Holder.
The top lid is to mount the AC socket and OLED Display.

I used my Creality CR-10S 3D printer and 1.75 mm silver PLA and red PLA filament to print the parts . It took me about 5 hours to print the main body and around 3 hours to print the top lid.

My settings are:

Print Speed : 60 mm/s

Layer Height : 0.3

Fill Density : 100%

Extruder Temperature : 205 degC

Bed Temp : 65 degC

Step 10: AC Wiring Diagram

The AC power cord has 3 wires: Line ( red), Neutral (black) and Ground (green).

The red wire from the power cord is connected to one terminal of the fuse. The other terminal of the fuse is connected to spring loaded two terminal connectors. The black wire directly connected to the spring loaded connector.

Now the power required for the circuit board (Wemos, OLED, and ACS712) is taped off after the spring-loaded connector. To isolate the main circuit board, a rocker switch is connected in series. See the above circuit diagram.

Then the red wire (line) is connected to the AC socket "L" terminal and green wire (ground) is connected to the center terminal (marked as G).

The neutral terminal is connected to one terminal of the ACS712 current sensor. The other terminal of the ACS712 is connected back to the spring-loaded connector.

When all the external connections have been finished make a very careful inspection of the board and clean it to remove soldering flux residues.


Note: Do not touch any part of the circuit while it is under power. Any accidental touch may lead to fatal injury or death. Be safe during working, I will be not responsible for any loss.

Step 11: Install the All Components

Insert the components ( AC Socket, Rocker Switch, and OLED Display) on the top lid slots as shown in the picture. Then secure the screws. The bottom part has 4 standoffs for mounting the main PCB board. First, insert the brass standoff into the hole as shown above. Then secure the 2M screw at the four corners.

Place the Fuse Holder and Current sensor on the slot provided on the bottom enclosure. I used 3M mounting squares to stick them on the base. Then route all the wires properly.

Finally, place the top lid and secure the 4 nuts (3M x16) at the corners.

Step 12: Final Testing

Plug in the power cord of the Energy Meter to the mains outlet.

Change the following parameters from the Blynk app

1. Slide the CALIBRATE slider to get the current zero when no load is connected.

2. Measure the home AC supply voltage by using a multimeter and set it by sliding the SUPPLY VOLTAGE slider.

3. Set the Power Factor

4. Enter the energy tariff at your location.

Then plug in the appliance whose power to be measured to the socket on the Energy meter. Now you are ready to measure the energy consumed by it.

Hope you enjoyed reading about my project as much as I have enjoyed during building it.

If you have any suggestions for improvements, please comment it below.
Thanks!

Microcontroller Contest

Runner Up in the
Microcontroller Contest

1 Person Made This Project!

Recommendations

  • Mason Jar Speed Challenge

    Mason Jar Speed Challenge
  • Bikes Challenge

    Bikes Challenge
  • Remix Contest

    Remix Contest

33 Discussions

0
makersanthosh
makersanthosh

5 weeks ago

It was a great post. Can you explain the calibration and finding the Irms part of the code?

Vrms = Vrms - (calibration / 10000.0); // Calibration Part
Irms = (Vrms * 1000)/Sensitivity ; // Why "1000/Sensitivity*Vrms"
Thank you.

0
klitaphor
klitaphor

Question 4 months ago

What if I want to change the price in the code? I'm having a reason why it keeps getting -145?

0
donquixotericky
donquixotericky

Question 1 year ago

How do i make the energy measure to each 8 channel of relay with single esp8266 or esp32 that lack of analog input? please give me the solution, Thanks...

0
dealba24
dealba24

Question 1 year ago on Introduction

Hello, are you still emailing out Auth Tokens?

0
AhmadA269
AhmadA269

2 years ago

I paid your amount please send me auth tokan

0
dealba24
dealba24

Reply 1 year ago

Did you ever get the Auth Token ? Im thinking about doing this project but I want to make sure I can get the token before I start building.

0
yenice_coding
yenice_coding

Question 1 year ago on Step 5

Firstly, thank you very much for the project.
Could you explain why we take samples every 2 seconds and read ACS712 every 0.95 seconds? For every 0.95 seconds will we have an instant value of AC current?
I was unable to see current over 0.2A, this is the reason I am asking.
Best wishes,

1
bpark1000
bpark1000

Question 1 year ago

Your equations for real power, and reactive power only apply if the load is linear (pure sine wave for the current). Phase angle does not exist for complex waveform (such as the one you show). Do the calculations work according to the equations listed, or are they averaging instantaneous voltage times instantaneous current (which gives correct answer for any waveshape)? What is the sample rate of the system (what is the highest frequency that can be processed)?

0
woodnboats
woodnboats

1 year ago

I tried to scan the Blynk QR, but Blynk said it wasn't a valid Blynk QR. Any suggestions? Also, if you install the Blynk server on your own computer, there is no need to buy power, and your data is safer. There are instructions in the documentations on the Blynk site.
A schematic would be nice, too.
Nice Instructable, and what I have been looking for.

0
LesB
LesB

2 years ago

Great project!

A nice addition to the smartphone app would be a plotting routine so power usage could be plotted over time. That way one could, for example, see how much time during the day the refrigerator is running.

0
woodnboats
woodnboats

Reply 1 year ago

Check the Blynk website. There is documentation that will tell you how to graph and save your data, and input it into a spreadsheet as well.

0
opengreenenergy
opengreenenergy

Reply 2 years ago

Thank You!

I really appreciate your valuable feedback.

0
ВладК8
ВладК8

Question 1 year ago

hi ;) today i was purchased all of it. iam a student, i will try to buid arduino energy meter of solar panels with help of blynk. thx for guides) wish of luck

0
mohammad bilaln
mohammad bilaln

1 year ago on Step 7

can we make energy meter over Ethernet( energy reading transfer to supplier of energy with load control )

0
MarcoS60
MarcoS60

1 year ago

Hello, I have a question, can I connect directly to the A0, do not need any voltage divider R1, R2 or resistance?

0
javdan
javdan

1 year ago

awesome project. any chance you can give me some guidance in applying this for a range of 110-480VAC?

0
fonetainer
fonetainer

Question 2 years ago

Hi,

i just wish to know following thing about this circuit. van i upload this codes to Arduino UNO or Nano instead of wemos. if yes i have to change anything on the code?

second this kind of LCD not available in my place so can i use 16x2 LCD or LCD keyboard shield ?

Regards.

0
DestuctiveC
DestuctiveC

2 years ago

Excellent project, keep it up :)

0
bsorli
bsorli

2 years ago

Interesting, yes great instructions, and big thumbs up!

I live in the USA and curious how this tester and 120 volt standards will effect the programming and measurements. It's just physics, so should only require minor changes to the code and possibly using different input/output boards if they don't support various ranges like 110 to 250v.

Also, where did you get those cool input plug connectors? I'll need something similar for American standard outlets, but something so small is pretty uncommon. What was your final project cost (understand item costs for components varies by country)?

Thanks for the instructable and reply, and I'm looking forward to trying something similar. Sorli...