Hi,
Well, I will explain in my designs;
When to use a transistor as a switch?
if MCU need to switch a LED on-OFF, or activate Relay, or buzzer or ...., I use NPN transistor, because, I do not worry about ground difference and no issue on huge current flow and temperature rise.
Since NPN will invert my logic, if I needed non-investing logic I use PNP.
Transistor as switch for application with mA only, larger current will create heat.
When to use a MOSFET?
If I need to SINK very large current say, 1000mA or 5000mA, then I use Mosfet because low heat lost.
opto isolator as a switch?
When I need to isolate input/output ground to system ground.
Again this refer to my design logic, other might have other reason.
M.Pathma