4
\$\begingroup\$

I have a raspberry pi. I want to control a 12 volt motor (low torque). I believe the motor only has two connectors, and when it is powered it goes. The motor goes off of 12 volts where as the Raspberry Pi is only 5 volts.

I also want to be able to power the motor and the raspberry pi in one unit. I don't know what this yellow box is. For example, do I split the 12 volts DC coming in, and send 12 volts to the motor and then do some resisters to lower the 12 volts to 5 volts to power the raspberry pi? What about the ground for the motor? Can it be connected back to the yellow box too? (what ever the yellow box is)

For more clarification:

enter image description here

\$\endgroup\$
11
  • 2
    \$\begingroup\$ I strongly recommend that you look at the comments which have now been moved to chat here. The discussion was interesting but peripheral to the main topic. \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 4:33
  • 1
    \$\begingroup\$ Matthew: It will greatly help people help you if you provide web links to anything you are using . The term "servo" can cover several quite different motor types and power and voltage and drive requirements for what you are probably using vary. Please provide brand & model of your servo motor and a web link to a data sheet (or a technical description if data sheet not available). A web link to a Pi Zero datasheet would also do no harm. || Note that what Chris says is valid - to get a good answer that works it is necessary to be sure of what the real requirement is. \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 4:33
  • \$\begingroup\$ Do you need to have closed loop positioning, or just spin the motor? In one direction or both? Also for this type of motor we really need the current or power rating, it should have a name plate... \$\endgroup\$ Oct 1, 2020 at 23:22
  • \$\begingroup\$ I just need to spin the motor, one direction, for about a second. It is for an automatic food dispenser, so just a burst for a second or so, and I don't know exactly what type of motor I need for that. \$\endgroup\$
    – Matthew
    Oct 1, 2020 at 23:54
  • \$\begingroup\$ @Matthew Do you have a motor brand / model/weblink? \$\endgroup\$
    – Russell McMahon
    Oct 2, 2020 at 2:47

2 Answers 2

2
\$\begingroup\$

@mguima has provided a useful link in his answer. BUT do note Chris Stratton's comments also.

Important considerations include:

  • Any motor tends to make electrical "noise" which a microcontroller is very sensitive to.

  • Usually the power needs of a motor exceed that which what can sensibly be fed from a Pi header directly.

  • The servo voltage needs to be correct and may not match the Pi supply.

Overall, when starting off, supplying the servo from a separate supply, batteries or other is a safe move.

Grounds of Pi supply and servo supply MUST be connected.

The servo control lead can usually be driven directly by the Pi.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ The question uses the term "servomotor" which tends to be associated with traditional industrial devices. It does not say "hobby servo" so it's not appropriate to be assuming that the asker is speaking of a hobby servo. The whole point of EESE is that we don't guess what someone is asking about, we wait for them to provided the critically needed information. Normally that would be electrical specifications; if it actually is a hobby servo then identifying the brand or model or providing a picture, would at least let people know which set of collected knowledge is applicable. \$\endgroup\$ Oct 1, 2020 at 0:24
  • 1
    \$\begingroup\$ @ChrisStratton Again, I largely agree with you. In a level-playing-field discussion your suggested approach is the greatly preferred one. I also initially took "servomotor" to mean a traditional 'servo'. It took mguima's comment to trigger the mentat mode (Dune, about 35% of necessary facts for a usually right solution :-) ) to realise that with high probability he means a hobby servo. I certainly do not know with certainty. | I agree that what I am doing is a non ideal approach on a level playing field. I also consider that for a beginner with obviously very limited technical knowledge ... \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 0:36
  • 1
    \$\begingroup\$ ... 'getting them comfortably to the table where we can talk' probably requires a slightly different approach. I value technical rigour about as much as the great Olin Lathrop. Getting there I may favour a different path in order not to lose victims along the way :-) :-(. \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 0:38
  • \$\begingroup\$ @ChrisStratton I keep meaning to ask - are you the person with the same name that I knew in NZ decades ago, or someone else? \$\endgroup\$
    – Russell McMahon
    Oct 1, 2020 at 0:39
2
\$\begingroup\$

I just need to spin the motor, one direction, for about a second. It is for an automatic food dispenser, so just a burst for a second or so

Unidirectional control of a DC motor is typically accomplished with an N-FET switching the motor's negative power lead, while the positive remains permanently connected to the supply.

Many of the best modern FETs for this kind of role are in surface mount packages, but if you prefer a through-hole package, Adafruit sells the IRLB8721PBF (data sheet) for this type of purpose. The main factor of importance is not the ultimate current rating, but rather that with the 3.3 volts the pi can supply to the FET gate, the FET will be reasonably (and not just minimally) "on".

Given that a motor is an inductive load which exhibits a "kick" when turned off, you'll also need a diode "backwards" across the motor.

And you'll want a 10K or so pull-down resistor on the FET gate.

Some might suggest using a relay module for this task; that is a path you can pursue but there have been some anecodotal reports of the cheap undocumented e-commerce site relay modules sometimes not working reliably with 3.3 volt input, as they sometimes have optocouplers set up in a way that assumes 5 volt logic from an Arduino. The potential isolation provided by a relay and optocoupler is substantially (if not entirely) defeated when you use the same power supply for both the computer and the motor.

(Incidentally, if you could use an Arduino, that would probably make your project a lot more robust than a pi, which as extremely complex system with far more things that can go wrong).

and I don't know exactly what type of motor I need for that

This is worrisome, until you've picked the motor it's impossible to say much of anything about power supply requirements. Fortunately TO-220 size FET's are likely overkill for the switching requirement. Your picture made it seem like you were considering a gear motor, which could indeed be a good choice for slow one-way movement.

For example, do I split the 12 volts DC coming in, and send 12 volts to the motor and then do some resisters to lower the 12 volts to 5 volts to power the raspberry pi?

Loads of time-varying power requirement like a Raspberry Pi cannot be supplied through a resistor. They'd need a voltage regulator. In the very old days a Linear Voltage regulator (which is basically a resistor which self adjusts for load) might have been used, but a pi consumes so much power that this would generate a lot of heat. So today, instead you would use a Switching Regulator. The LM2596 is a relatively old and not terribly sophisticated part compared to what is on the market for such purposes now, but it would probably work, and the Internet is full of places selling modules with something comparable (if not literally) that on them. Pick one where any adjustment is via a screw type potentiometer and carefully pre-set it while measuring the output voltage; you don't want something that will fry your pi if bumped out of adjustment.

\$\endgroup\$
1
  • \$\begingroup\$ This has been very helpful. Thank you. I will continue to research! \$\endgroup\$
    – Matthew
    Oct 2, 2020 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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