Schematic
As we can see, the robot reads the voltage of the batteries through GPIO32 of ESP32. Because the battery
voltage is not read frequently, this GPIO is also used to control the Ultrasonic.
As shown in the figure above, the positive pole Vm of the power supply is controlled by the switch.
1. When the switch is turned on, the voltage value of VM is the voltage value of the battery.
2. Battery/Trig is connected to GPIO32 pin of ESP32.
3. The voltage acquisition range of GPIO32 on ESP32 is 0-3.3V, while the robot dog is powered by two 18650
lithium batteries, and the voltage is 8.4V when fully charged, which exceeds the voltage acquisition range of
ESP32. Therefore, after passing through the voltage divider circuit composed of R3 and R4, the voltage at
Battery/Trig is about 1/4 of the battery voltage, 8.4 / 4 = 2.1V, which is within the voltage acquisition range
of GPIO32.
Sketch
In this section, we will use GPIO32 of ESP32 to read the voltage value of the batteries and print it on serial
monitor. Open “Sketch_01_Battery” folder in “Freenove_Robot_Dog_Kit_for_ESP32\Sketches” and then
double-click “Sketch_01_Battery.ino”.