Welcome to sensors-software Discussions! #1
gvidinski
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to introduce to you a small feature as an addition to the main functionality. I called it “Battery monitor”. It allows you to monitor the state of the battery if UPS topology is used to power the board by showing current battery capacity percentage and its voltage which might be useful for many advanced users I believe.
Details about my setup can be found here: https://gvidinski.wordpress.com/2021/05/10/solar-powered-nodemcu-sds011-dust-sensor/
The feature can be enabled through the configuration menu. When enabled user will have to enter few parameters – threshold voltage for both, the discharged [Battery U min (mV)] and the fully charged [Battery U max (mV)] state along with the maximum input voltage at the voltage divider [ADC divider U max]. In case when NodeMCU1) is used and battery voltage is greater than 3.3V user will have to add additional resistor (R1) to the monitor line, in series with the positive terminal and the A0 input of the board (Figure 1):
Figure 1.
The value of the R1 can be found by solving the following equation (1):
where R2 = 220kΩ and R3 = 100kΩ both forming the internal voltage divider provided inside the NodeMCU1) board; Vin is the voltage at the battery’s positive terminal; Vout is the maximum input voltage of the ESP8266’s 10-bits ADC which is always 1V. Internal voltage divider provides sufficient solution for input voltages ≤ 3.3V without having the need of R1 to be installed. But having for instance a Li-Polymer single cell battery we will need to be able to read voltage of at least 4.2V. For example solving equation (1) for Vin = 5V will give us a standard value for the R1 resistor of 180kΩ.
Of course there could be another approach especially if we do not have a resistor with the exact value of 180kΩ for R1 on hand but we have one with value of 155kΩ instead. By simply using the values of all the resistors in the voltage divider and solving (2):
where Vout = 1V; R1 = 155kΩ; R2 = 220kΩ; R3 = 100kΩ will give us the [ADC divider U max] value for the configuration – VinMAX = 4.75V.
The code takes into account if we build it for ESP8266 or ESP32 platform. For ESP32 platform I’ve used a definition where pin 36 (GPIO36) is selected for the battery monitor input which corresponds to the ADC1 channel 0 (ADC0) of the ESP32. (By the time I was writing this I didn’t have any available Node322 so the definition needs to be tested and eventually changed.) In this case user will have to implement his own voltage divider by using only two resistors as shown in Figure 2:
Figure 2.
Then the following equation (3) have to be used:
where Vin is the voltage at the battery positive terminal; Vout = 3.3V (the maximum meaningful input voltage for the 12-bit ADC’s analog inputs of the ESP32); R1 & R2 by your choice. Just pick large enough value in order of hundreds kilo Ohms to keep the current that will be drawn from the battery at insignificant levels. I would suggest using 220kΩ (R1) and 330kΩ (R2) standard 1% resistors. This will give readings of maximum 5.5V with small enough current draw (7.6 µA @ 4.2V).
In Table 1 are shown different solutions for different input voltage ranges for both platforms using standard resistors of 1% tolerance and will draw current as low as 10µA form the battery.
Table 1.
The UI is organized in the following manner. All the settings for the Battery monitor have to be entered form the “Configuration” page, “More settings” tab, under the “Enable battery monitor” checkbox (Figure 3.). By enabling it another three more input fields will become visible. For the Battery discharged, fully charged voltage and for the maximum input voltage at the divider (Figure 4). Then the actual battery state can be obtained at the “Device status” page in the form of “Capacity: [%]([V])” (Figure 5.).
All the measurements are done by averaging 3 consecutive readings taken in periods of 1 second, then followed by 10 seconds pause period. Also no reading will be taken during the report period, when data has to be send to the external web resources (taking into account the “send_now” state). In addition the Battery state data is added to the json result. This way users can track the state of the battery and also may develop customized battery state charts on their platforms.
Build and testing was done using the PlatformIO under the Visual Studio Code IDE following the [Contributing Guidelines](https://github.com/opendata-stuttgart/sensors-software/blob/beta/airrohr-firmware/Contributing.md).
1) Developments boards based on ESP8266 chips – NoneMCU v2 & v3.
2) Development boards based on ESP32 chip – Node32.
3) Single cell (1S) Li-Ion or Li-Polymer 3.7V batteries (2.8V ~ 4.2V).
4) Double cell (2S) Li-Ion or Li-Polymer 7.2V battery packs (5.6V ~ 8.4V).
5) Six cell lead acid 12V battery (10.5V ~ 13.8V).
6) Four cell (4S) Li-Ion or Li-Polymer 14.4V battery packs (11.2V ~ 16.8V).
Beta Was this translation helpful? Give feedback.
All reactions