How to control external voltage via PWM

Actually when you wrote this post you already used millions on transistors (MOSFETs) on that electronic gadget.

N-MOSFET stand for N-channel MOSFET. See these few videos to clear some of your doubts:

Videos (There are loads of videos on the Internet)

Working of Transistors | MOSFET - YouTube
Transistors Explained - How transistors work - YouTube
MOSFET BJT or IGBT - Brief comparison Basic components #004 - YouTube

I am also a student so I may not explain much clearly, but actually what happens is that with a variable PWM signal, the MOSFET acts as a variable resistor and drops some of the voltage.

I suppose you know what a PWM is, if not see the below image:

As the voltage on the Gate increases, the resistance (RDS(on)) decreases and the voltage increases.

Sorry, I made a mistake in the original schematic follow this schematic:
image

Note

I am also a beginner, so this schematic may not work, I built this based on my knowledge, I have not tried it myself.

Regards.