OK, can someone confirm if what I think is happening here is correct?
View attachment 136597
When the micro pin is low, the opto is ON grounding the base of Q2 via R3 and turning Q2 on and hence the MOSFET off.
When the micro pin is high, the opto is OFF and Q1 will get a base current (~8mA) via R2 & R3, turning on Q1 and charging the MOSFETs gate to turn it on.
As the transistors have a minimum Hfe of 220 I'm assuming this will switch reasonably quickly.
And this one,
View attachment 136600
This is using a P channel MOSFET and the way I "think" it works is,
When the micro pin is low, the opto is OFF, the gate is held at 12V by R2 and so the MOSFET is OFF.
When the micro pin is high, the opto is ON, the two resistors act as a voltage divider placing the gate at 10V below the source and turning the MOSFET ON.
I expect this will switch much slower than the first one but still good for on/off operations.
I'm also assuming that the opto could be replaced with an NPN but the first one would be negative logic.
Hopefully, I got some of it right.
Mike.