It's time to put some wires and the opamps in the breadboard.
For take it easy, will use the 3.3 Volt on the Arduino as Vx.
This comparator check the first battery.
According to the complete schematic, is the battery connected is up to Vx ( in this case 3.3 Volt ) the led not turn on.
So i connect the 1.5 volt AAA battery, an the result is: led ON.
Now i connect the Li-Ion battery, 3.7 volt: led OFF.
This opamp made the differentiam of the two inputs.
In this case i used 5V and 3.3V .
The result is 5V- 3.3 V = 1.7 V ideal.
Ok it's a good approximation.