I'm trying to control the speed of two DC motors that are connected to a dual H bridge. I always used digital PWM pins with analogWrite() to change the speed, but since I'm making a project that will be using most of the digital pins, I wonder if I can use analog pins instead.

P.S. I know I can use analog pins as digital pins to free the digital PWM pins, but I'm not interested in doing that.

  • Well, I am confused. The Arduino reference page, the "Description" of analogWrite() also states: "Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. " So can it or can it not?
    – evie
    May 16, 2017 at 6:28
  • analogWrite() is for writing to the pins that support PWM. As far as I can tell you can't use it for writing to pins A0, A1, etc... Its a really confusing name for a function May 16, 2017 at 7:35

3 Answers 3


You can't do it with the analogWrite function as that is reliant on physical binding beween certain pins and hardware timers inside the AVR. But you can always use SoftPWM because the the analog pins can generally be used as digital pins just as well.

  • Yes, multiwii project does 'bit banging' software pwm on analog pins, but a library would be faster to implement Jul 19, 2015 at 4:01

No, you can't. As it says in the Arduiuno reference page for analogWrite(): "The analogWrite function has nothing to do with the analog pins or the analogRead function."

You can use the "analog input pins" (A0..A5) of Arduino for analog input, or as digital inputs or outputs. They cannot be used for PWM(digital)-output. Only digital pins, and only those specifically stated for PWM-output, can actually be used for PWM output (unless you go down the path of software-PWM, though I would hesitate to do that for an H-bridge).

  • depends on if the OP means an "H-bridge" with a control input stage that takes a single PWM input. I agree it would be a bit dicey to go that route with two inverted SoftPWM signals coming from the AVR.
    – vicatcu
    Jun 27, 2015 at 0:41

You can use multiplexers if you are running out of digital pins or SPI PWM drivers for the motors. There are many multichannel drivers out there like TLC5940, put a power stage after them and you're done.

*Use Soft SPI on the analog pins to control the driver.

  • The TLC5940 is designed for LEDs, would it be adequate for motor control? Aug 27, 2015 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.