Electronic – Optocoupler with the same power supply

gpioisolationmicrocontrolleropto-isolator

Often in MCU boards I see optocouplers even when the power supply is the same on both sides.
Example:

schematic

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.

Best Answer

No, there is no good reason to use an expensive and large optocoupler if you're sharing ground. The optocoupler's prime advantage is isolation. The common use of this appears to be cargo cult adoption from cheap expansion kits for development boards. You can protect the pin with cheaper discrete components, or multiple "discrete components" integrated into a small package.