Introduction: Monitoring Solar Panel Backup LiPo Bateries Using a Mosfet Transistor
When we use solar cells in our projects there is a big concern with the duration of the back-up battery, which feeds the device when there is not enough sunlight.
I learned a lot with Andrea Spiess on her YouTube channel about how to calculate the capacity of the panel to feed loads of your device, in your city. See the video link on how to do it. The most complete I've seen.
But the curiosity to know how much is the capacity of my batteries made me build this little gadget that helps me monitor them.
The backup battery life is directly related to the consumption of the load and therefore you must not connect permanently in the analog pine of your controller to measure its level without wasteful energy consumption.
The idea (it is not mine) of this project was to use a MOSFET as a switch, operated from a digital pin, connects the positive terminal of the battery to the analog pin and proceeds to read the value of the ADC signal. You can read in the link here a very good post about this.
The sketch interprets and calculates the available voltage of the battery and sends it to ThingSpeak to store the data and show the energy consumption over time in graphics.
Note: English is not my natural language. If you find grammatical errors that prevent you from understanding the project, please let me know to correct them.
Step 1: The Gadget
- 1 transistor Mosfet - IRF9540 (can be any P-channel MOSFET)
- 1 220 ohms resistor
- 1 100 k ohms resistor
- 1 220 k ohms resistor
- 1 100 nF ceramic capacitor
- 1 LED
- 5 wires with different colors
- 5 pins
How it works
In the photo, you can see the circuit diagram.
It can be noted that there is a voltage divider that limits the signal to the maximum that an ESP8266 can receive as an input on its pins. The LiPo battery has a maximum of 4.2V and the ADC pin can receive a maximum 3.3V. The voltage divider of 100K over 220K allows a current of a maximum 2.89V.
Vout = [R2 / (R1 + R2)] * Vin
Vout = 220 k / 320 k * 4.2V
Vout = 2.8875V
Any combination of resistors can be chosen as long as it limits the input to 3.3V.
The ESP8266 wakes up and sends a pulse through the digital pin D7 to the GATE of the MOSFET. At the same time, it turns on the LED to only show that the pulse was given. This will allow conducting the electric current between SOURCE and DRAIN allowing the pin A0 to read the value in milliseconds.
It is important to say that the ADC pine of the ESP8266 has a voltage divider of 100k / 220K also. It will limit the input value between 0 and 1 V and transform the signal into a value between 0 and 1024. If you want more explanations on how the ADC reads the signal you can go to this link randomnerdtutorials or this link of ESP8266 Core.
The sketch calculates the value of the entry according to the formula:
Vin = analog read / 1023 * 3.3V
The voltage of the battery then is:
Vbat = Vin / (220k / 320k)
For example, we measure the voltage of a battery and it shows us 3.5 V.
When connecting to the gadget we will have:
Vin = 3.5 V * 220/320 = 2.4 V as input to the ADC
A0 = reads approx 730 and 740 due its voltage divider
Vin = 730/1023 * 3.3 v = 2.35 V
Vbat = Vin / (220/320) = 3.42 V (2% lower)
The measurement difference exists due to the tolerances of the resistors, your multimeter precision and also due to the voltage drop of the MOSFET between DRAIN and SOURCE. According to the datasheet, for 4.5 V curve the voltage drops less than 0.6 V. If you want to be more precise, add this value or part of it at the end. I added half of it.
Step 2: The End
See the video attached.
The case to accommodate the gadget I have recycled a dental floss case that is perfect for that. Always giving a second life to a rejected piece.
ESP8266 will sleep deeply for 15 minutes between each measurement. I believe 60 minutes better.
The sketch is easy to understand and is full of explanatory comments. Create a new folder on the ARDUINO folder with the same name and download it. Change the credentials on lines 17 to 21 using your wifi network SSD and PASS and your ThingSpeak account ID. Use the ARDUINO IDE to upload to your device.
Create a new channel for your gadget and send the data. You can monitor the level of your batteries even from your cell phone with the ThingView application.
I hope you find this project useful. In case of any doubt, do not hesitate to contact me.
Participated in the