Welcome to Solarduino , A blog about DIY Solar PV and Arduino projects

DIY Bi-directional DC & AC Energy Meter using Blynk For Solar Online Monitoring Application.

Energy Meter is a very useful device that measures and records important information of electrical parameters. Most Economic Commercial DC or AC Energy Meters are single direction meter which could only measure and record values in one direction. Uni-directional / one-way / one-direction Energy Meter is sufficient for typical household and DC power generation but it is not suitable for system that involves forward and backward current flow such as in Solar PV Application. For off-grid PV System, the battery bank (DC) involves charging and discharging DC current while on-grid PV System involves import and export AC current to the Grid Utility. If you use a typical 1 way Energy Meter to measure the 2-directional current flow, the meter might either filtered out the reverse current readings or may have error on the meter. 

Today’s project will be building a Bi-directional AC & DC Energy Meter 2 in 1 and monitor through Blynk app for online remote monitoring. This energy meter provide a total solution for measuring Solar PV Application as it is the most flexible to measure 2-direction flow for DC and AC power. It could record up to 15 electrical parameters including DC Voltage (Vdc), DC Export/Import Current (Idc), DC Power with direction (Wdc), Net accumulated, Import and Export DC Energy (Wh), RMS AC Voltage (Vac), RMS AC Export/Import Current (Iac), AC Real Power with direction (Wac), Apparent Power(VAac), Net accumulated, Import and Export AC Energy values (Wh), Frequency (Hz) and Power Factor (Pf). 

Kindly take note that this DIY project requires bunch of internal wiring, sensors and modules. If you are a beginner to Arduino Micro-controller I recommend you to try on the simpler and separate DC & AC bi-directional Energy Meter using Arduino UNO for local display.

1) DC Bidirectional Energy Meter – https://solarduino.com/diy-bi-directional-dc-energy-meter-for-battery-and-solar-pv-application/

2) AC Bidirectional Energy Meter – https://solarduino.com/diy-bi-directional-ac-energy-meter-for-solar-pv-system/

Peacefair PZEM-051 Energy meter is an compact 1-direction DC energy meter that measures Voltage, Current, Power and Energy. Peacefair has a lot of model to measure different current requirement from 20A up to 100A. You can get it at our affiliate link here !!!   

Peacefair PZEM-021 Energy meter is an compact 1-direction AC energy meter that measures Voltage, Current, Power and Energy. Peacefair has a lot of model to measure different current requirement from 20A up to 100A. You can get it at our affiliate link here !!!   

Warning ! You may now dealing with high voltage and high power source ! We assumed that you have the basic electrical knowledge and know what you are dealing with. You may need guidance from experienced guys if you are new to electrical work. Safety and Precaution must be always have in mind. We shall not be responsible for anything happening to you.

Below are the main modules and sensors needed:

  1. NodeMCU board x 1
  2. NodeMCU Base x 1
  3. 12V 2A power adapter x 1
  4. 16 channel multiplexer module x 1
  5. ZMPT101B AC Voltage Module x 1
  6. 1% Tolerance Resistors x 1 set 
  7. HSTS016L Hall Effect Current Sensor x 2
  8. Thermal Fuse (For safety) x 1
  9. Dupont Wires x 1 set
Below are the links to all the components………..

NodeMCU micro-controller

The NodeMCU micro-controller is similar to Arduino micro-controller board. It is compatible with Arduino IDE software and is built-in with the ESP8266 module which can be connected to the internet. You can grab some at our affiliate link here !!!  

Node MCU Micro controller Base

The based below the Node MCU can provide more flexibility on the connection ports to support more sensors. Besides, it also has 12V input port and able to provide 5V power supply to support the sensors. Support us by purchase it from our affiliate link here !!!

Overall Wiring Diagram

Wiring Diagram Summary:

16 Channel Multiplexer

  • SIG to Analog Pin A0 of NodeMCU
  • S3 to Digital Pin D3 of NodeMCU
  • S2 to Digital Pin D2 of NodeMCU
  • S1 to Digital Pin D1 of NodeMCU
  • S0 to Digital Pin D0 of NodeMCU
  • EN & Gnd to Ground of NodeMCU
  • VCC to +5V of NodeMCU (Base board)
  • C0 (Channel 0) to R1 & R2 (measure DC Voltage)
  • C1 (Channel 1) to yellow wire of Hall Effect CT (measure DC Current)
  • C2 (Channel 2) to R3 & R4 (measure AC Voltage)
  • C3 (Channel 3) to yellow wire of Hall Effect CT (measure AC Current)

AC Voltage Module

  • VCC to +5V of NodeMCU (Base board)
  • Gnd to Ground of NodeMCU
  • OUT to R3
  • N to Neutral AC Wire.
  • L to Live AC Wire. Live wire must be added fuse for protection.

Hall Effect CT

  • Yellow wire to respective signal wires
  • Black wire to Ground of NodeMCU
  • Red wire to +5V of NodeMCU (Base board)

DC Voltage Input

  • Positive of DC wire connected to R1
  • Negative of DC wire connected to R2

This is the Hall-Effect Split-Core Sensor HSTS016L module. The model ranges from 10A up to 200A. With split core current sensor type, not alteration on the existing system required. You can get it via our affiliate link here !!! The output voltage of this sensor is 2.5V +/- 0.625V with decent accuracy. I highly recommend this sensor for measuring AC & DC current.

Single Phase AC Voltage Module

This module is equipped with ZMPT101B high-precision voltage transformer and op amp circuit. It can measures AC voltage within 250V. The corresponding output signal can be adjusted using the trimmer potentiometer. You can grab this module at our affiliate link here !!!

Measure DC & AC Voltage using voltage divider method

NodeMCU can only measure Analog Value up to 3.3V. Sensors that has output signal not more than 3.3V (example the Hall Effect CT has maximum output of 3.2V) can be directly connected to the NodeMCU without any issues. For signal more than 3.3V, a voltage divider in between the measurement value (sensor) and NodeMCU is required to step down the measurement voltage.

In this example we will be using total of 2 Voltage Dividers (1 for DC voltage and another for AC voltage). DC voltage measurement will be subject to the maximum voltage in measurement. Take this project as an example, I have selected resistors of 20k ohm (R1) and 1k ohm (R2), it has a reduction factor of 21, (R1+R2)/(R2) thus the measurement DC voltage can measure up to 21 x 3.3V = 69.3Vdc. 

AC Voltage module will be able to measure AC waveform and will send out a maximum signal of 5V thus need to step down from 5V to 3.3V. I have selected the resistors of 200 ohm (R3) and 330 ohm (R4). It has a reduction factor of 1.6, (R3+R4)/(R4) thus typically can measure up to 1.6 x 3.3V = 5.28V which can cover maximum input of 5.0V from the AC Voltage module. The Resistor values will be needed to key inside the programming code for calculation adjustment.

 

16 Channel Analog Multiplexer Module

This module is an extension board that allows micro-controller to have more Analog Pins for sensor measurement. It is very important for NodeMCU as it only has one Analog Pin. Support us by grabbing one at our affiliate link here !!!

For more information on Resistors selection, Hall Effect Current Transformer and AC Voltage Module, kindly select the link below:

1) Resistor Selections (Resistance, % tolerance, Wattage) – https://solarduino.com/how-to-measure-dc-voltage-with-arduino/ 

2) Hall Effect Current Transformer – https://solarduino.com/how-to-measure-dc-and-ac-current-using-hsts016l-hall-effect-current-transformer/

3) AC Voltage Module – https://solarduino.com/how-to-measure-ac-voltage-with-arduino/

1% Tolerance Resistors

1% tolerance resistors have high accuracy resistance value thus suitable for precise application especially for measurement. You may purchase the resistor at our affiliate link here !!

Blynk App – The Online Data Monitoring Platform

Blynk is a user friendly platform that provide web interface for data display. It provide smart phone app for easy setup and monitoring. In the app, there are a lot of Widget Boxes which suits a lot of measurement data. However, if you want to use the Widgets, it will consume energies based on the Widget types, similar to online games that you may need to top up the energy when you require more widgets. Upon creating an account, there will be some energy which should be enough for small project.

Download Bylnk App on Google Play
Download Bylnk App on App Store

Fuse Wire

Fuse is required to prevent over-current incident such as short circuit and overload. It can prevent fire risk due to accidental Live and Neutral Wire touch or mis-wiring. Support us by purchasing from our Aliexpress Affiliate link here !!!

Software Step by Step Guideline

The software part will be divided into 2 parts: 1) the smart phone web interface Blynk App and the 2) programming part using Arduino IDE Software.

On phone 

  1. Download Blynk App on your smart phone (Google Play / AppStore).
  2. Open and create an Account on Blynk App.
  3. Add New Project  
  4. Blynk will send a Auth Token to your email specifically for this project.
  5. If you want to use 2 individual projects or channels, create 2 projects for 2 Auth Tokens.
  6. At your project main page, swap to the left to open Widget Box.
  7. Add Widget based on your desire.

Widget settings for this project: 

  • Virtual Pin V1 = DC Voltage (Vdc)
  • Virtual Pin V2 = DC Current (Idc)
  • Virtual Pin V3 = DC Power (Wdc)
  • Virtual Pin V4 = DC Accumulated Net Energy (Wh-dc)
  • Virtual Pin V5 = DC Accumulated Import Energy (Wh-dc)
  • Virtual Pin V6 = DC Accumulated Export Energy (Wh-dc)
  • Virtual Pin V7 = AC Voltage (RMS) (Vac)
  • Virtual Pin V8 = AC Current (RMS) (Iac)
  • Virtual Pin V9 = AC Real Power (Wac)
  • Virtual Pin V10 = AC Apparent Power (VAac)
  • Virtual Pin V11 = Power Factor (Pf)
  • Virtual Pin V12 = AC Accumulated Net Energy (Wh-ac)
  • Virtual Pin V13 = AC Accumulated Import Energy (Wh-ac)
  • Virtual Pin V14 = AC Accumulated Export Energy (Wh-ac)
  • Virtual Pin V15 = Frequency (Hz)

 

On Laptop / PC

  1. Install Arduino IDE Programming Software (If you do not have the software, click here to download)
  2. Install Node MCU Board Manager for using Node MCU in Arduino IDE Programming Software (see below section)
  3. Install Node MCU ESP8266 Library for using Wifi codes in Node MCU (see below section)
  4. Install Blynk Library for enable the Node MCU using Blynk server (see below section)
  5. Copy Auth Token from the email, note down the Wifi name & password.
  6. Upload the code to Node MCU Board. 

Dupont Line Wires

You may need Dupont Line Wires (male to female or female to female) to connect Arduino board and Voltage Sensor. It is available at our affiliate link here !!! 

Install Node MCU Board Manager 

If this is the first time you are dealing with NodeMCU, you need to add NodeMCU board manager file into the IDE software so that the software can support the Node MCU board. To add the Support File, open Arduino IDE Software, go to files>preferences>Additional Boards Manager URLs, paste this link http://arduino.esp8266.com/stable/package_esp8266com_index.json to the black space and click OK. Go to Tool > Board > make sure the board is showing NodeMCU 1.0 (ESP-12E module).

12V 2A Power Adapter

12V 2A Power Adapter is an ideal external power supply for micro-controller such as Arduino UNO and NodeMCU (that has its based). It is a worry-free plug and play power source without any wiring work. Grab 1 in our Aliexpress affiliate link here !!!

Install ESP8266 Wifi Library

If this is the first time you are dealing with Wifi programming, this ESP8266 Wifi Library file is needed to be installed to the Arduino IDE Software so that it can understand the programming function. Go to Tools > Boards > Boards Manager and download the ESP8266 library by ESP8266 Community

Install Blynk Library

If this is the first time you are dealing with Blynk server, this Blynk Library file is needed to be installed to the Arduino IDE Software so that it can understand the programming function. Go to Tools > Boards > Boards Manager and download the Blynk library by Volodymyr Shymanskyy

Initial Calibration

There are few calibrations need to be done before start measuring and monitoring. The first calibration need to be done is the 16 Channel Multiplexer & the NodeMCU analog pin. The analog value 0 to 1024 might not represents 0 to 3.3V and the initial analog value might not be exact 0 value when sensor has 0V output. It is the same for analog value 1024 which not exactly fall at 3.3V sensor value. Thus a potentiometer and multimeter is required for this calibration setup. Connect the middle pin to Channel 15 (Last channel) of Multiplexer, one of the potentiometer side pin connected to +3.3V while another pin connected to Ground. Open the Multiplexer offset.ino file below and upload to the same nodeMCU. Open up the Serial Monitor and start calibrating. Use multimeter to measure the voltage between middle pin and Ground pin of the potentiometer and compare with the Analog output value at the Serial Monitor. Record the Analog Value when voltage is 0V and record the voltage when Analog Value is 1024. Both values will be used to offset all the calculation later.

Second calibration is the AC Voltage Sensor. It has a calibration trimpot attached on the board for user to manually calibrate the module. For more information on how to calibrate the module, kindly visit here : https://solarduino.com/how-to-measure-ac-voltage-with-arduino/

The rest of the sensors will be in auto calibrate during every NodeMCU startup. It uses self reading value to calculate for auto calibration. However, be sure there are no measurement values during every startup. Make sure all current and voltage are at 0 values for at least the first 20 seconds of NodeMCU startup in order for it to auto calibrate the sensors correctly.

 

The smart phone Blynk app and Arduino IDE software are two independent parties. As long as you do it right, the Node MCU board should be able to send data to the Blynk server so that you can see the values from your smart phone. One of the advantage of using Blynk is that the Blynk server can allow for data storage so that you can trace or download previous record. You can customize your web interface at Blynk App. Below is one of the example how it would look like:

Before we end, we would like to give gratitude to you for taking the time to read the post. We would need readers like you to support us in order to keep growing. You can support us in the following ways :

Donate & Fund Raising

If you like my work, please send me a donation to encourage me to do more. Thanks

Aliexpress Affiliate

We are the member of Aliexpress affiliate marketing. Do support us by clicking the affiliate product links if you do wish to purchase them.

Like and Share

If you like our post, we need your support to like and share our posts or videos so that it can reach more and more people like you !!

DC & AC Bi-directional Energy Meter.ino
Multiplexer offset.ino