Zak well explained how to add a MOSFET that will help with situations like

  • using only battery
  • USB connected, charging battery, battery is not used for powering the load. What USB cannot provide enough power, will charging suffer?
  • USB connected but battery is missing (MOSFET has nothing to do here, this is on MCP73831)

MCP73831 loadshare

Which is in its turn an adaptation of a note from Microchip (Designing A Li-Ion Battery Charger and Load Sharing System With Microchip’s Stand-Alone Li-Ion Battery Charge Management Controller by Brian Chu)

Interesting that I found these links in one very long rant on a EEVblog forum. Very confusing discussion full of MOSFET dyslexia ()

But it was much more constructive discussion than on Electronics Stackexchange where I found very confusing topics:

  • How to add MOSFET to switch between battery and external source. Doesn't look like the source is connected right
  • Two diodes or MOSFET? but the answer is to buy a board. Otherwise, mind bending schematics without ground. No ground at all!
  • Idea with the comparator. And also with two comparators that detect a voltage range (window comparator curcuit). Though it's interesting but doesn't look flexible: first you need to understand the window and comparators, then calculate values (take into account battery charged and discharged states, and difference between USB and battery voltage), then why one MOSFET is not enough?

On hackster.io I found some concerns about LDO voltage regulator (suggesting HT7333 as a solution)

most boards such as Wemos, NodeMCU and others have an AMS117 voltage regulator that has an extremely high drop-out voltage of 1.3V, which makes them unusable for battery power

and proper battery level readings (this is about separate LipoFuelGauge system)

In order to be able to accurately measure the state of the battery, you cannot do it through resistors and ADC Pins, because the voltage of lithium-ion batteries does not drop linearly, while this chip has a special algorithm that calculates the state of the battery.

More complex control - voltage multiplexer from Power Electronics Technology magazine

Alternatives

Power distribution boards

Plan

  • search for a prototype board for ESP32
  • add USB connector
  • voltage stabilizer (buck converter)
  • battery charger chip
  • solar panel connector
  • battery connector
  • SPI line connectors and power for display
  • voltage divider between ADC and battery (to read battery level) about ADC

Power source

Motors normally require higher voltage (6V, 12V, 24V) and current, and it's a good practice to keep motors, LEDs (like very long strips of LEDs), switches electronically seperated from the logic (3.3V). But how do you decouple it when the whole project should work from the battery?

Do you use two batteries? Just imagine what a headache is to keep two separate batteries charged. I can only think about sophisticated system where there is an assumption that motors can kill the battery often, but at the same time the main brain must continue operating, therefore it remains only one option: to send a signal about help to other robots. But I've never seen such design.

So what normal people use instead?

Power supply needs to be protected from Back EMF when motors abruptly stop or reverse the rotation direction. But rechargeable battery only wins from this effect. The only concern will be values above maximum ratings especially for li-poly batteries that are very sensitive.

Read more: Operating an Arduino for a Year from Batteries

Battery charger

Let's design our custom board for powering the robot from one lithium polymer battery, say 3.7V and 2500mAh.

First of all, even before using the battery in any way, we should think about charging it. Here's a battery charger from Adafruit based on MCP73833 (evaluation board doc). For a second I thought that I found cheaper option - MCP73831 on Digi-Key in a 5-lead SOT-23 package, but it consumes 4x times less current during charging which means that it's going to charge much slower and has less indication signals. The datasheet provides PCB layout example.

Old alternative for these chips is MAX1555 and TP4056.

battery charger typical application

Additional components:

  • 3x indicator LEDs: 2x yellow and 1x white
  • 2x capacitors 4.7uF - Voltage Rating 10VDC
  • 3x resistors 470 Ohms - for LEDs, so for 20mA the Power Rating would be >100mW
  • 1x resistor (to set maximum charging current) 1K - for 25mA current (?), therefore the Power Rating >125mW
  • 1x resistor (to skip temperature control) 10K - for 50uA and 1.25V = 62.5uW

Send indication to MCU

Why not send signaling information to MCU too instead of only connecting LEDs? Then a question arises here. Input voltage is 5V, will voltage on these lines will be acceptable to 3.3V GPIO?

When STAT1, STAT2, or PG connected to ground, LEDs consume from 2 to 3 volts, which gives only 2 to 3 volts reaching the resistor and the chip. Then if we add a parallel route from the chip to GPIO pins, then this will work as adding a button in pull-up mode (power source is always connected to GPIO pin making high logic input on it but the circuit is not closed).

Does it make sense to add a transistor? Thus to stop that high logic before LED is lit.

https://electronics.stackexchange.com/a/324804/30694

How to use BJT https://electronics.stackexchange.com/questions/324795/are-bjts-suitable-for-level-shifters-it-seems-fets-are-more-common-how-do-they

I think I just need pull-up transistors https://electronics.stackexchange.com/questions/381171/mcp73833-and-status-to-raspberrypi https://forum.microchip.com/s/topic/a5C3l000000MXTtEAO/t358761

But why positive voltage applied to the gate directly and not the logic output from PG?

To keep different voltage separate

The PG output can sink current, but not source current.

From datasheet

About MOSFETS in general: https://toshiba.semicon-storage.com/info/application_note_en_20180726_AKX00068.pdf?did=59460

Load sharing

Even an LED can cause the battery to never finish charging.

USB should work as input and charge the battery too.

Power multiplexer. Add diodes to prevent flow from solar panel to USB (as they will share input lines). What MOSFET specs to use?

Step up voltage regulator

We need to boost 3.7V voltage from our battery to 5V level where Arduino and motors can work. Preferably we should supply 3.3V to logic board and separate 5V or 6V or even more to motors. But we must keep the first version simple.

Again we start with a popular at this time breakout board and look at the main chip (TPS61030). For logic board AND motors I found 1.8A TPS613222 and 3.6A TPS61032 switch current boost converters from Texas Instruments. The datasheet provides PCB layout example.

Old alternative for these chips is TPS6109.

voltage regulator typical application

Additional components:

  • 1x coil (inductor) 2.2uH (max DC current > 1.18A)
  • 1x schottky diode (alt) (required for >250mA loads) - find average and peak current from the inductor (1.8A, 2.4A)
  • 1x resistor 5 Ohms (for RC snubber) - power dissipation of the snubber is calculated as CV^2f = 150pF x (5V)^2 x 1MHz = 3.75mW (frequency of the circuit is calculated by the formula in datasheet with values V_in = 4V, V_out = 5V, n = 0.9, L = 2.2uH, I_lh = 0.5A)
  • 1x capacitor 150pF (for RC snubber) - x3 of schottky diode capacitance (45pF x 3 = 135pF) and voltage rating 10V
  • 3x capacitors 10uF - voltage Rating 6.3VDC

Connectors

  • Arduino uses barrel jack connector, and more precisely 2.10mm ID (0.083"), 5.50mm OD (0.217")
  • Power for Arduino or Raspberry Pi (1/2 - in theory) - Micro USB Type B Male Vertical - connector is perpendicular to the board's surface thus it connects to Arduino or Raspberry Pi perpendicular as well. Raspberry Pi 1/2 where lower power consumption. Some components not rated for the current greater than 1A, so with Raspberry Pi 4 it can fry them)
  • Battery to the board - JST PH Connector
  • For charging USB cable let's be modern and use type C - USB Type C Female

Don't forget

  • Programmer connector. Two options: USB to UART with chips like CP210x or CH340, and see DevKitM for WROOM; or COM port (or USB to Serial converter) directly connected to RXD and TXD pins (this might not work on every system, maybe because DTR and RTS which just automatically trigger Reset and Boot buttons)

Picture from Last Minute Engineers showing form and marking difference between CP210x and CH340

  • Add several buttons in a joystick formation plus functional buttons (for setup, menu) (seen a capacitors near buttons on a dev board and wondered, so here's small info about debounce)

Solar Panel

And then carefuly think about power consumption and try to save on some functionality that you don't use. For example, here an amazing list from

  • Run the processor at a lower frequency
  • Run the processor at a lower voltage
  • Turn off unneeded internal modules in software (eg. SPI, I2C, Serial, ADC)
  • Turn off brownout detection
  • Turn off the Analog-to-Digital converter (ADC)
  • Turn off the watchdog timer
  • Put the processor to sleep
  • Don't use inefficient voltage regulators - if possible run directly from batteries
  • Don't use power-hungry displays (eg. indicator LEDs, backlit LCDs)
  • Arrange to wake the processor from sleep only when needed
  • Turn off (with a MOSFET) external devices (eg. SD cards, temperature sensors) until needed

ADC

Max range is from 0 to Vref which is 3.3V. But for precise readings the maximum value should be lower and that limit is defined by the attenuation setting. Read more here and in the docs

ADC on ESP32 known to have issues. Some simple steps to resolve it [ADC calibration] (https://esp32.com/viewtopic.php?f=19&t=2881&start=20#p16166). Reference voltage Vref can be measured by a multimeter if it directed by a special command to an IO pin. Last docs

We are going to implore "paleolithic circuit design" with two transistors instead of going the smart way and using CMOS analog switch (like this (but can find cheaper alternatives)).

It can be a good idea to use an external ADC (for example ADC101C021 or MCP3021)

Q&A

  • Do you know that batteries can have multiple cells. One cell is 3.7V. 2 cells (2S) - 7.4V. 3 cells (3S) - 11.1V

  • Why capacitors are basically everywhere?

schematics with many capacitors

Capacitors are everywhere. Or at least in many places where the power is applied

Extra

  • Serial port debugging with Bray++ terminal
  • Futuristic case: small PCB board connects to a sheet of acrylic where it’s cut with special lines to deliver led lights to sides. Also the battery is attached to that part. Acrylic and PCB are connected by custom 3d printed piece
  • Smooth routes: kicad plugin posts about melting kicad 1 and 2. In KiCad 8 draw a normal sharp route, then select all intervals, right click and select Fillet Tracks and set radius to 2mm.

Rate this page