Often in MCU boards I see optocouplers even when the power supply is the same on both sides. Example:
simulate this circuit – Schematic created using CircuitLab
Here +3V3 and +12V have the same GND so there is no galvanic isolation between the MCU and the external world.
I guess using an optocoupler is more robust that connecting directly the wire to the MCU, but I wonder if there is a good reason to do that instead of using, say, a BJT or a line driver.