The NPN common emitter configuration makes it easy to make a low-side to switch loads connecte to positive supply. It seems logical to assume that a PNP transistor could provide a mirrored circuit to make a simple high-side switch. The circuit of Figure 1 will work fine provided that \( V_{SS} \leq V_{MICRO} \) (or whatever voltage the micro is running on).
If If \( V_{SS} > V_{MICRO} \) then the output protection diodes built into the chip provide a sneak path for the base current. The e-b junction of Q1 will be forward biased and current will flow through it, R1 and D1 to the micro supply. Q1 will turn on and LED will light and will not switch off.
We can fix this at the expense of adding an NPN low-side switch.
In Figure 3 the micro drives Q2 as in a normal NPN low-side switch. When Q2 is turned on current will flow from the base of Q1, through R1 and Q2 to ground. Q1 will turn on and the LED will light.
In Figure 4 the problem has been solved by using an opto-isolator. Now there is no chance of the 12 V supply back-feeding into the micro.
Note that in this example the grounds are common between the two circuits. They could, however, be separated for complete isolation. See “A basic application” on Opto-isolators – intro for an example.