Control the output voltage of pwm pin

Hello everyone,

I was writing a code to control 2 dc motors using an h bridge and I was thinking of controlling the speed by using a potentiometer to control how much voltage is put out from the pwm pin. Is that possible and if so how. Thank you in advance.

Read a pot on A0 and map the resultant from 0-255 and write that to your PWM out.

Of course, that controls the duty cycle of the PWM and doesn't really control the voltage as requested. A PWM signal is not necessarily the right way to operate an H bridge anyway.

This question causes me to wonder what is REALLY going on here and WHAT is REALLY needed.


PWM through a low pass filter tends to be slow in responding to changes or tends to have a lot of ripple. It doesn't have to be that way but those people who can design better don't usually have to be told to use a low pass filter.

An H bridge has TWO inputs. Either the H bridge is augmented with something else (such as an inverter) or another Arduino output is used (which has not been explained) or the H bridge is excessive because operation in both directions is not really needed or the H bridge is not really a full H bridge.

In any case, I would prefer to hear from the OP.

Driving an H-Bridge with a filtered PWM signal is a recipe for smoked FETs. The entire point of an H-Bridge is that is CAN be driven with a digital PWM. That is precisely how it is MEANT to be controlled.

Ray L.

I agree but I am not clear on what the OP was asking. I want to hear a lot more information from Gurveer777.