I have a Raspberry Pi and I want it to control DC motor speed. I make the pi output 3x3,3V for controlling the speed. I need circuit that works like this; when one output gives 3,3V motor have 6V, when two output pins gives 3,3V motor have 9V and when all output pins gives 3,3V motor have 12V. Can this be archieved with one mosfet and some resistors or do I need to buy three transistors and 6V and 9V regulators. Input voltage is 12V. I hope you guys get what I'm trying to achieve.

Ihave this mosfet now, I can use it for on/off switch to my motor when outputting 3,3V from one GPIO pin to the Gate. If I use three of these, one with 6V regulator, one with 9V regulator and one without any will it work? My motor is Lego XL motor so it does'nt draw so much current.

  • \$\begingroup\$ The thing you are describing is a "motor controller". \$\endgroup\$
    – Phil Frost
    Commented Jan 15, 2015 at 2:08

1 Answer 1


For a single MOSFET solution you should feed the motor from a +12V supply. Then have the microcontroller generate a PWM signal with varying duty cycles to generate an effective drive to the motor to correspond to the desired 6V, 9V and 12V drive levels.

Clearly for the 12V to the motor the PWM would be at or close to 100% duty cycle. For the 6V equivalent drive to the motor the duty cycle of the PWM signal would be likely to be in the 45 to 60% duty cycle range. For the 9V drive the PWM would be set to some duty cycle in between the 6V and 12V settings.

  • \$\begingroup\$ I quicly readed here from the PWM with Python. Do I use 50Hz frequency for the BUZ11 or what? The duty cycles I figured out, I just try different cycles from 0 to 100. Edit: I almost forgot! Do I need to use the protective diode for the motor? I also have 1Kohm resistor between BUZ11's Gate and Source to make sure it really turns off, is that resistor ok? I have 12v battery and 5V regulator for Pi, so yeah, I use 12v supply for the motor \$\endgroup\$ Commented Jan 15, 2015 at 2:37
  • \$\begingroup\$ @LizNet - please be aware that there is a small chance that a particular MOSFET cannot be driven by your Pi. If you look at the data sheet, specifically at Gate Threshold Voltage, you will see that a typical number is 3 volts, but it might be as high as 4. As for PWM frequency, 50 Hz is probably too low for a motor, although it might work. Certainly the motor will "sing" at 50 Hz if you go that route. The resistor is an excellent idea. And so is the diode. \$\endgroup\$ Commented Jan 15, 2015 at 2:51
  • \$\begingroup\$ @WhatRoughBeast I tested the MOSFET with PC's PSU, I put the PSU's orange wire (I assume that is 3.3V) to the MOSFET's Gate and measured 12,54 volts throught the Drain and when I disconected the 3.3V the 1Kohm resitor pulled the voltage to zero. So I think my MOSFET runs smoothly with 3.3V. If 50Hz make the motor "sing", what is good frequency for motor controlling? \$\endgroup\$ Commented Jan 15, 2015 at 3:01
  • \$\begingroup\$ A good PWM frequency of motor control is 20 to 25 KHz. You use this high frequency so that the motor mechanism does not try to resonate and make a bunch of noise that you can hear. \$\endgroup\$ Commented Jan 15, 2015 at 3:26
  • \$\begingroup\$ @LizNet - you need to get a better understanding of how to test this. You don't say what the resistance of the motor is. Let's say (just for illustration) that it's 10 ohms,and the motor will pull a little over 1 amp when starting from a standstill with 12 volts. Get a 10 ohm, 10 watt resistor. Connect it between +12 and the MOSFET drain, and connect the source to ground. Don't assume the orange is 3.3 - measure it. You have a meter - use it. Apply 3.3 to MOSFET gate, and measure the drain/source voltage. It should be 0.1 or less. Remove the 3.3 and the drain should go to 12 volts. \$\endgroup\$ Commented Jan 15, 2015 at 3:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.