DIY Victron Smart Shunt
Esp32 based Victron SmartShunt 500A project
Overview
This project uses an INA226 shunt amplifier to implement some smart shunt functionality. It sums up the charges that move through the shunt. With this information it tries to calculate the load status of an attached battery. The INA226 should be connected to the shunt so that charges going into the battery are positive and those coming out of the battery are negtive.
The smart shunt has three main interfaces.
- A web interface for human users. It allows setting the main parameters of the system and displays the current status of the system
- A modbus interface that is based on a PZEM017 energy meter but enhances it with the values mentioned above
- Victron VE.direct Text and Hex protocols in order to function as a Battery Monitor. The Hex protocol is only implemented as far as it’s required for startup. Furthermore, some fields of the Text protocol are not yet filled correctly.
- An API returning values a JSON payload, for use without the USB interface.
Hardware
For measuring the current you need an INA226 breakout board as you can acquire from Amazon.
Some of the boards have a different pinout. The SDA and SDL pins are swapped in comparison to others. So please check this if you can’t get a connection to the sensor.
As miocrocontroller I settled for Espressif products. This code has been tested with a Wemos D1 Mini, a Wemos S2 mini and a 8266 Nodemcu. I didn’t test any ESP32 WROOM boards, but they should work too. I settled for the D1 mini due to its small footprint and powerful CPU. I got mine from Amazon
You also need a shunt, since the small resistor on the board (don’t forget to remove it!) will not survive the high currents of a PV plant. There are plenty of options out there. Make sure that you select a resistor appropriate for the currents you expect. I’m using a 20A/75mV shunt.
The D1 needs a USB power supply, to power it, I used a 12v to USB converter connected into the same DC system as being measured. Make sure the Battery – is connected to the GND potential of the sensor. Otherwise the voltage measurements will be invalid, since the INA226 has only one GND. Furthermore, you should use an isolated USB module to connect the D1 to the target. You can destroy your computer or Victron GX if you connect it directly to the USB of the MCU.
Before you can use the sensor board you have to remove the shunt resistor soldered to that board and instead use a bigger shunt, e.g. a 100A/75mV. Make sure that the shunt supports the current your system produces. You can set the parameters of the shunt in the web interface. A wide variety of shunts can be found on Amazon, EBay or other platforms.
If you have a 48V System, be aware of the fact that the INA226 does only support voltages up to 36V (40V max). You need a voltage divider to make sure your sensor is not destroyed. The code assumes that you use a 470K Ohm and a 1M Ohm resistor, measuring across the 1MOhm towards GND. ( + --470K-- --1M -- GND )
This works for a 16S LifePO4 battery. The smaller you choose the small resistor in comparison to the bigger one, the more accurate the measurement will be.
Optional Temperature and Humidity monitoring using a AHT20 I2C Temperature Humidity Sensor
https://crcit.net/c/93609e4da6e9468ea96ee64330156ded
Software
The Software has been created using platformio and the Arduino environment. In order to build it you also need some libraries.
- the INA226lib The latest version should work with this code.
- emelianov/modbus-esp8266
- locoduino/RingBuffer
- prampec/IotWebConf
The latter three will be automatically downloaded when using platformio.
https://github.com/IanCarruther5/SmartShuntINA226
Set up
The configuration field Voltage calibration factor can be used to calibrate the voltage reading of the sensor. Set it to 1000 and then simply divide the real battery voltage by the value the sensor shows and multiply it by 1000
. The same can be done for the current in the field Current calibration factor. If you entered the shunt resistance correctly, a value close to 1000 is expected here. Mine is 1028.5.
DIY Victron SmartShunt
Arduino based SmartShunt
This project uses an INA226 shunt amplifier to implement some smart shunt functionality. It sums up the charges that move through the shunt. With this information it tries to calculate the load status of an attached battery. The INA226 should be connected to the shunt so that charges going into the battery are positive and those coming out of the battery are negtive.
The smart shunt has three main interfaces.
- A web interface for human users. It allows setting the main parameters of the system and displays the current status of the system
- A modbus interface that is based on a PZEM017 energy meter but enhances it with the values mentioned above
- Victron VE.direct Text and Hex protocols in order to function as a Battery Monitor. The Hex protocol is only implemented as far as it's required for startup. Furthermore, some fields of the Text protocol are not yet filled correctly.
Materials
Instructions
- First take a piece of stripboard 9 tracks wide and links to join D2 to header 3 (track 3) and D1 to header 4 (track4). +3.3v to JST pin4 (track 6) and gnd to JST pin1 (track 9)
- Add JST 4 pin connector to the bottom right connected to track 6-9
- Add a 8 pin header soldered to tracks 1-5
- Cut tracks 6-8 one from header so no connection is made from pins 6-8 of the header. Cut track 52 down from the header so that D5 can connect to the header but is isolated from the rest of the board. Cut track 6 one up from the JST to break the connection.
- Solder in header pins from 3v3, gnd ,D5, D2,D1 Tx and RX (these are the only pins used.
- Solder the D1 mini on to the header pins 3v3, gnd ,D5, D2,D1 Tx and RX
- Solder 8 pin header (keep as much as possible protruding to allow contact to the D! board header), 1M resistor from pins 2-6 (gnd to ALE) and 470k from ALE to 3pin JST 3pin 1. Solder 4 pin JST to pins 1-4 and 3 pin JST to pins 6-8
- Remove resistor from INA226
- Solder INA226 to header pins
- Put D1 mini board in case
- Put divider in case
- Fit INA226 daughter board
- Make up JST to JST cable
- Plug in comms cable
- Fit lid
- Put TTL USB in case
- Plug in comms cable
- Fit lid
- Finished Shunt
https://www.amazon.co.uk/hz/wishlist/ls/1I6J6VZ0SYMQA?ref_=wl_share
If you liked this you might like my DIY temperature sensor.