Variable Voltage with MOSFET using Arduino?
I know you can use a MOSFET as a switch. I was wondering if it is possible to turn the switch on and off with PWM and use that to change the voltage. So for example, if I had a duty cycle of 50%, the voltage across the cicuit would be 1.85V


You can do something like this, but you have to consider the characteristics of the load.

Suppose the load is a resistor, or an LED &amp; resistor, or something else where it's actually okay to apply the full voltage and you just care about the output power. In that case, you can just PWM, and this is a common way to vary brightness of a light. But more complex loads actually need a stable voltage. How do you produce a smoother voltage out of PWM input? You add a capacitor.

But then the output voltage on that capacitor will not be 50% of input — it will depend on the capacitor's charging curve and how much the load is drawing from the capacitor. So you need to vary your PWM duty cycle based on the voltage/charge on the capacitor — a feedback loop.

Now what you have is better known as a switch-mode power supply (SMPS). There's one more detail — you also need an inductor, which is used to avoid the losses which result from abruptly connecting a capacitor to a voltage source.

It is tricky to build a stable and efficient SMPS, and you should not try to build it using your Arduino as the controller. Instead, buy a premade module — you can find ones with voltage adjustment inputs. SMPSs are called either buck converters or boost converters depending on whether they lower or raise the input voltage, respectively. In your case you want a buck converter.