Electronic – Use a Mosfet/PNP transistor to boost voltage for mcu pin

esp8266mosfet

I am looking to turn off/on a 5v laser diode with an esp8266 micro controller.
The mcu's gpio pins can only take 3.3v.
A PNP, NPN and mosfet, among these three which will help me boost the voltage to 5v and how should it be connected?

Best Answer

The easiest way would be something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

When selecting the MOSFET, make sure it is a 'logic level' MOSFET that can turn on fully with 3.3V gate to source, and handle the current the laser diode uses.

Note that I don't show any current limiting here. If the laser diode doesn't include that you will need to use a resistor in series.