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

DIY Bi-directional DC Energy Meter for Battery and Solar PV Application

Energy Meter is a very useful device that displays important information of electrical parameters. Most Economic Commercial DC Energy Meters are single direction meter which could not record or may be error if the current flow in reverse. They are normally using shunt resistor to measure the current value which physically need to alter the wiring circuit into the shunt resistor in order to measure the current flow.

Today’s project will be building a Bi-directional Energy Meter which could record electrical parameters such as DC Voltage, Export Current, Import Current, instantaneous Power with direction, accumulate Import and Export Energy values. These parameters are mostly needed in DC energy generation or DC load such as Solar PV System. Furthermore, we will be using the Hall-effect Split Core Transformer which do not require to modify the existing circuit in order to make measurement. To cut everything short, we need 2 sensors, the DC voltage sensor and DC Current Sensor.  

Peacefair PZEM-051 Energy meter is an compact 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 !!!   

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.

Arduino has the ability to measure DC voltage and DC current (via module) using analog input pins. For Arduino UNO, there are 6 analog input pins (A0-A5) where you need separate pin for each measurement. If you stacked up a LCD Display Shield, Analog Pin A0 is automatically occupied by the button function. If you are going a step further by adding Datalogger Shield, Analog Pin A4 and A5 are also occupied for I2C communication for the Real Time Cloak module in the Datalogger Shield. 

However, in this project we have to remove the datalogger code as it take up a lot of coding space which may cause measurement deviates. I will set A1 to measure DC Voltage and A2 to measure from current module. Do not reverse the voltage polarity which may damage the pins.

Arduino UNO (compatible board)

If you still not yet own an Arduino Micro-controller Board, you can get it cheap at our affiliate link here !!!

Measure Voltage using voltage divider method

If your measure DC voltage value which is not more than 5.0V, you can directly connect to the analog pin without any modification. In order to measure higher voltage such as 18Vdc, 48Vdc, 100Vdc or even 500Vdc, voltage divider method is used to split and reduce the measurement voltage into a 5V range. The voltage divider consists of two resistors connected in series as shown in the diagram below. All you need is just 2 resistors with different resistance values.

When the voltage is applied across the pair resistor of different resistance, it creates a voltage drop based on each resistor and it can be used as reference value and it is directly proportional to the total voltage value. Higher resistance R1 tends to have larger voltage drop while smaller resistance R2 will have smaller voltage value which is within acceptable range of Arduino.

For easy calculation, below we have attached an excel sheet that can automatically calculate the value of the resistors. First, key in the Monitoring Voltage. It is the maximum value of your DC voltage monitoring range. The next step is to key in the Total Resistance value. It is recommend that the total resistance ranges from 50,000 ohm to 300,000 ohm. 

Total Resistance is flexible. However, small total resistance will have large consumption and heat dissipation for high voltage measurements which end up you have to buy larger wattage resistor. In the contrary, too large total resistance may end up voltage measurement processing too slow or not accurate in low voltage measurements. 

As a guide, 100Vdc and below use Total Resistance value of 50,000 ohm, 200Vdc and below key in 100,000 ohm, and voltage less than 500Vdc key in 300,000 ohm. Once you keyed in Monitoring Voltage and Total Resistance values, the Excel sheet automatic calculate all the relevant specs for the two resistors.

 

There are 3 important information that need to be specified during the resistor purchase. You may purchase the resistor at our affiliate link here !!

1) Resistance value 

You will end up getting 2 resistors of different resistance value. You might get weird resistance value in the calculation sheet, for example 44,565 ohm and 5,325 ohm. It is just a guideline and all you need to do is to get a round figure which is closer but larger value for resistor R1 and smaller value for resistor R2. Example: 45,000 ohm and 5,300 ohm. This is to ensure monitoring voltage can be measured within 0-5V range.

2) Resistor Wattage

Similar to other products, resistor itself has its withstand’s wattage rating. Oversize wattage rating is always better than using small wattage rating on large consumption which may lead to resistor burnt. Resistor R1 always has more heat dissipation than resistor R2 thus it is not strange that both resistors are not with same wattage requirement. Just get a value larger than the wattage rating as specified in the excel sheet. The standard wattage of a resistor is: 1/8 Watt (0.125W), 1/4 Watt (0.25W), 1/2 Watt (0.5W), 1 Watt, 2 Watt and 5 Watt.

3) The resistance tolerance in %.

Resistor Tolerance is the percentage of deviation from the stated resistance value. If you do not have a Multimeter to measure the actual resistance value, you will need to purchase a better accuracy resistor. Resistors are very small and cheap component; if possible get most accurate ones. 1% is widely use and suitable for monitoring and measuring purposes. 

You may purchase the resistor at our affiliate link here !!

16X2 LCD Display Shield can be directly fit on to the top of the Arduino board without the need of extra wiring for the LCD Display. Without the LCD Display, you can only monitor the measured current value on PC via Serial Monitor. You can get the LCD Display board at our affiliate link here !!!. 

Measure Current using Hall Effect Split Core Transformer

In this project, we will be using the Hall Effect Split Core Transformer to measure DC current. It utilizing hall-effect phenomenon which voltage is produced from the movement of current within the region of magnetic field. The voltage produced by hall effect is directly proportional to the applied current making it suitable to estimate the applied current from the voltage sensed.

The sensor can measure current in 2 direction. Reverse current will not damage the sensor but the voltage difference will be in negative. As we know, Arduino analog input only read positive integer values. In order to measure 2 direction, the zero point should be at half the total voltage range (0 to 5V) which is 2.5V. This is true if the supply voltage to the sensor is 5V. 

Hall-Effect Split-Core Sensor HSTS016L module can measure two direction of DC curret ranges from 10A up to 200A (based on the model number). With split core current sensor type, no modification on the existing wiring 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. 

Unlike Voltage Sensor, Current Sensor requires initial offset setting. When no current operate, the sensor might have some deviation value and not exactly at 2.5V which most probably due to sensor or the supply voltage from Arduino Board. Secondly, current sensor is also a sensitive sensor. The output reading of the sensor seems to have electrical noises and its value fluctuates  all the time even when there is no current detected. It is more obvious if the measurement is in a smaller time frame. In order to greatly reduce this phenomenon, multiple samples must be taken for averaging must be done. 

The good news is you do not need to manually calibrate the offset settings if you got the LCD Display Shield with you. Below we have attached the code that utilizes the button function that could automatically calibrate by itself when you pressed the SELECT Button. You may download from the end of this page below.  

Our code is also designed to display a value which is derived from averaging 1000 samples in every second. Each sample is recorded every 1 milli second (0.001 second). The single averaged value is then to be displayed at Serial Monitor and LCD Display. With this, the fluctuation of value is way lesser compare to taking 1 sample reading every second. Make sure the sensor cables are tight because minor movement of wires might affects on the wire terminal connections thus affecting the accuracy reading.

Hardware Connection

Once you get your Resistorscurrent sensor module and Arduino Board ready, you may start to do hardware wiring. Below is the schematic of the whole wiring. You may also need some tools and accessories. Be sure your connection cable is tight and module shall be installed in such a way no movement at all. You can stack up screw shield, LCD Display Shield on top of Arduino UNO. No additional wiring is required. 

Screw Shield / Expansion Shield

When there are a lot of wiring around especially more than 1 sensor, sharing pins will be difficult as existing pins (ground and 5V) are limited. This shield provides a lot of convenient terminals for each of the input and output pins. The shield can be mounted directly on top of the Arduino Uno board or in between the shields which made it very convenient to use. You can get it at our affiliate link here !!!

Dupont Line Wires

You may need Dupont Line Wires to connect Arduino board and Sensor Module. It is available at our affiliate link here !!! 

Software Codes

The final step would be adding source code onto Arduino board. I assume you have installed the Arduino Software. If you still have not installed the software, the link here can bring you to the official download site. Once you have downloaded the software, you may download the code file (.ino) for this application below (right click save link). Once the code has been uploaded to the arduino board, the output can be shown in LCD Display. I will not display the code here because it is long. You can download the .ino file to see for your own. Almost all code lines are with explanation. 

Ferrule Lugs and Crimper Set

Ferrule lugs are used at terminals for tight and secure connection. Besides, it also prevent stranded cables accidentally touching adjacent power line that may cause short circuit. Grab 1 at our affiliate link here !!!

Step By Step :

  1. Wiring circuit based on the schematic diagram provided.
  2. Program the Arduino Board based on the code provided.
  3. Provide external 12V power supply to Arduino Board. 5V power supply not sufficient and measurement not accurate.
  4. Calibrate the current sensor by pressing the “Select” button. Make sure the initial current is at 0.00A.
  5. Do not unplug power supply for the Arduino Board or else the Accumulate Energy will be reset.
  6. To reset Energy value, you can press the Reset button. Calibration is required for every reset.

Terminals Crimping Plier Set

This is a crimping tool with interchangeable jaw for crimping many types of terminals. It is a must have for DIY electronic and electrical for professional installation work. You may choose at out affiliate link here !!!

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 !!

Bi-directional DC Energy Meter