This is almost definitely a stupid question, but why do we need to use a MOSFET transistor to use a 5V input to control a 12V output in PWM? Considering that we can switch currents on and off using optocouplers, why can't we do PWM control of larger voltages using smaller control voltages using optocouplers alone with no MOSFET transistors? Considering that pre-made MOSFET driver boards include an optocoupler (the smaller 4-legged chip), doesn't this mean that the optocoupler switching must be fast enough to keep up with the MOSFET transistor switching, or else it would be like the "lens cap being left on", right, or is there something obvious that I am misunderstanding?
"What is an opto-coupler?"
It decouples, electronically, like cutting a wire, two parts of a system. They use light (optics) to make it save to run one side with a low voltage, the other with a (very) high voltage.
"Are opto-couplers drivers?"
NO! They need a driver for higher current on the other side! They just "decouple" !, even called
"opto-coupler" (sure, coupled via light, but decoupled systems, voltages, ...).
"(Power)MOSFETs - when to use?"
Can an MCU drive AMPERES? NO!
How can a small power signal (never mind what voltage it is - the capability to drive current here!) drive a load with very low resistance (consuming amperes)? NO!
So, you need a MOSFET as a DRIVER: drive with a small current (or voltage) a "switch" (amplifier, driver, ...) for a load which consumes so much current or would need a much higher voltage as the (original) driving system.
Think about:
MOSFETs are transistors (types of) acting as a driver (amplifier, voltage converter, current amplifier...).
If MOSFET or regular transistor - it is up to you (both work fine).
MOSFETs have often lower "self-resistance" (lower voltage drop), higher current ratings and due to lower voltage drop higher current vs. temperature rating.
I think, you question was more like: "why do I need a driver?" (after my MCU pin). Right?
An opto-coupler is used as an isolation device, the current through the LED in the package shines on a transistor and controls the current flowing through it.
These devices have low output current capability, probably only able to power a LED.
They also have limitations on the frequency of the current you apply to the input, there are some specialty optos that have high switching rates.
A MOSFET is controlled by the voltage on its gate with respect to its source, the gate consumes very little current, although as you increase any pulse frequency to it, the gate begins to draw some current.
The voltage on the gate controls the resistance of the source to drain, and thus controls any current going though it.
Because the output of the MOSFET is a current control you can have the current from a supply higher than the gate voltage.
MOSFETs labelled LOGIC LEVEL are the best to use with MCU 5V as they are designed operate with 5V to turn the MOSFET fully ON.
Most need 10v or more to do the same job.
You can drive the gate of a logic level MOSFET directly from the MCU, but you may like some isolation due to the environment or the load power/voltage.
A combination of opto and MOSFET provides an isolated and drive system so your MCU can control things like 12V or 24V motors, 12V LED strings.
The load being a lamp, LED array, motor etc.
If using a motor you would need a reverse biased diode across the motor as well to protect the MOSFET from back EMF from the motor.
I hope its not to hard to understand my ramblings.