How do I implement a simple and efficient voltage divider for battery level readings for a ESP32 board?
Your idea is fine for a simple battery level detector but there needs to be some changes. The ADC on the ESP32 has an input range of 0 to ~3.3V. This means your divider needs to be designed so at maximum battery voltage the value at the GPIO pin is not outside this range. If I understand your schematic correctly you have a maximum of 8.4V from the battery and a minimum level of 5V? In this case your divider should be set up to output just under 3.3V with 8.4V across it. 

V(out) = V(in)*(R2/(R1+R2))

(R2 corresponding to the blue resistor in your schematic and R1 the red resistor)

use 8.4 for V(in) and 3.3 for V(out) and we get a ratio of R1 = R2 * 1.55 

You want your current to be low, so choose higher resistor values. The power rating of the resistor represents the maximum power the resistor COULD absorb before burning up. It is not the power they consume at any voltage or condition, which is defined by Ohms law. I would suggest resistors in the hundreds of kilohm or a few megaohm that satisfy the equality above. For example we can use your previous values and multiply by 100 to get 570k and 330k as a good solution. Then just test for an ADC value that represents 5V which is about 1.8V at the GPIO pin. 

In regards to the capacitor, it would reduce noise at the pin by adding a small (100nF) capacitor from the GPIO pin to ground. Below is a schematic of these suggestions, you may even consider higher resistor values.







simulate this circuit &ndash; Schematic created using CircuitLab