Using DC-DC-step-up and DC-DC-step-down converters

PeterPan321:
Assuming you go the route of of using a boost converter to power the arduino, so that it will have plenty of additional voltage to work with as the battery voltage falls, all you'd have to do is use a voltage divider consisting of two resistors (10K will do) between the battery and ground, and measure the point between the two by connecting it to an unused analog input, and use some simple math to determine the battery voltage. When the battery is outputting 6V, the voltage divider will send 1/2 the voltage (3V) to the analog input. Assuming you leave the arduino at its default analog reference voltage of 5V, and a full a/d count would be 1023, 5/1023 = about 0.00489. From that we can derive that when the battery is at full capacity (6V) and 1/2 that (3V) is on the A/D input, you'll get an A/D reading of 3/.00489, or about 614 counts. Applying the same math, the A/D counts will be 1/2 of your 5.4V divided by .00489, or about 552 counts.

By the way, there are tricks you can use to approximate the above without floating point math, which can take more CPU time if you have to calculate often. For example by multiplying the voltages in these calcs by 10000, now instead of dealing with a fraction (like the .00489), you can work with 50000 / 1023, which is about 49. Now you have an easier scale of about 49 A/D counts per volt. You just have to remember to divide the final voltage you get by that same 10000 factor. If you have a count of 1104, then 1104 x 49 counts/volt = 54137. Dividing by 10000 though, and you're back to your 5.4 volts.

What I want to ask is this:

If I connect battery to the ADC of Arduino and at the same time I supply the Arduino from supply jack (or the USB better) don't I have a short circuit? I thought of using an optocoupler, something like this...

https://www.mouser.com/ds/2/365/pc817x_eJ-184297.pdf

What is your opinion?