Energy monitor to determine DC energy. This will be used to calculate the capacity of a battery and stop discharge at the end of battery life or to calculate the energy supplied to a battery and stop charge when either the current reduces or a pre-determined time is reached.
Requires:
- The GPIO Library (Already on most Raspberry Pi OS builds).
- The MCP3208 Library.
- The Flask web server. Install command:
- sudo apt-get install python3-flask
- A Raspberry Pi.
- Hardware:
- MCP3208 ADC, connected as per Raspberry Pi ADC: MCP3008 Analog to Digital Converter. Resistive divider (1k/220 ohm) to enable a maximum voltage of 20V to be applied to channel 0.
- ACS712ELCTR-05B-T Current sensor connected to channel 1. Resistive divider on Vout (4k7/10k) plus buffer op-amp to interface the 5V output to the 3.3V ADC input. Suggest a load for a car battery of 12V/55W car halogen bulb to provide a load (4.6A, just within the maximum for the current sensor). The current sensor is a high current device (noise on the output is about 100mA). The noise will probably get averaged out over the duration of a battery discharge but the current probably needs to be kept above 1A or so.
- 3.3V switched relay. There are many sources. Ensure that it can switch at least 5A. Active high output connects power input to load. Ensure that the switched load is on the output side of the monitoring - voltage monitoring must always take place. This can be achieved using a transistor to drive the relay board, which may be required anyway. An example is https://www.raspberrypi.org/forums/viewtopic.php?t=36225(https://www.raspberrypi.org/forums/viewtopic.php?t=36225)
Installation:
- Copy files to a folder on the Raspberry Pi.
- Enable SPI in Raspberry Pi Configuration
- Edit /etc/rc.local to autorun application:
- sudo nano /etc/rc.local
- Add: python /home/pi/.../energy-monitor.py where ... is the location of your file.
- Edit connections and/or resistor values and/or component settings to define your system hardware. The defaults match my hardware.
- Edit calibration values to ensure that your system is accurate. I used an adjustable 12V PSU and 21W car bulb to set the calibration points.
Recommendations (to make life easier):
- Set a static IP address.
- Define a hostname.
- Create a fileshare.
- Install VNC for full headless access.
See wiki.
Added lead-acid cut-off on time
Added lead-acid cut-off on full charge
Added basic charging control
Added calibration and checking routines
Added hardware test routine
Modified for new hardware.
Added CSV logging of results.
Added control of relay.
Added energy measurement until battery discharged.
Added web display of voltage and current.
Added zero current setting.
Added calibration of voltage and current.
Added measurement of current.
Initial trial code.
Measures voltage of input