# How To Control A Motor with the Raspberry Pi

Clinton just shared a new tutorial: "How To Control A Motor with the Raspberry Pi "

In this tutorial, we are going to connect a Motor to the Raspberry Pi and create a hypnotic self-spinner. We are first going to look at how to wire the Raspberry Pi to the motor controller and the motor. We will then look at using the raspberry pi to…

I’m looking at using a motor with a max voltage of 12V and a lipo battery with a current capacity of 2200mAh. How would you recommend modifying this setup to suit this motor and battery?

The circuit doesn’t need to be changed. The Fritzing diagram isn’t really clear, and I had to look at it a couple of times to see it was correct.

What isn’t shown is the Pi power supply. The Pi has it’s normal power supply attached to power it.

The power rails on the left of the diagram are for the motor supply, in your case, the LiPo battery, and only the ground is connected to the Pi. The +ve rail is connected to motor power pin of the motor controller.

1 Like

I agree with Robin, you can use the same circuit but there are other things you need to consider.

First you need to consider the current drain of the motor when running and its stall current. A small DC motor can easily draw well over an amp when stalled. Can the motor driver handle this and for how long ?? I had a motor driver that shutdown because the current drain was too high.

Second is the LiPo voltage, you mention it is 2200mAH. Most LiPos I have seen are 3.7V. A 12VDC motor will most likely not run at 3.7V. Or run very slowly and with next to no torque. You would need some circuit to step up the voltage. A step up from 3.7V to 12V which would greatly reduce the 2200mAH capacity. If you used a 12VDC battery connected like the AA cells in the tutorial then it should work ok.

Last, there is a reason the motor power supply is separate from the Raspberry Pi power supply. I was using a single supply of 6 x AA cells to drive a robot cart. A 5V regulator supplied power to a Raspberry Pi. When driving the cart the motors dropped the voltage too low and the regulator dropped out causing the Pi to reset. My cart now has a USB powerbank for the Raspberry Pi and the 6 x AAs for the motors. I highly recommend the setup in the tutorial. (2 supplies)

Regards
Jim

1 Like

Thanks for sharing this solution. I am sure other users will benefit from you taking the time to write this up.

The driver used in this video is pretty typical of a DC motor driver so the idea would work for any driver motor pair. In theory if you have a driver that could support the input voltage you could run any DC electric motor with the same code and wiring. Just always be sure to check the current rating of your motor and driver board.

I have copied the code and the wiring for this but when I enter a backwards command it stops the motors, but forwards works perfectly. Any idea how I can get the motor to reverse?

Hey Mitchell,

I’d ensure that you’re connected to the correct pins and that the connection is clear. If it still fails to function can you please post the exact script that you’re using here and we can take a look at it for you.

Have a great day!

Bryce
Core Electronics | Support

Hi Bryce,

I ended up figuring this issue out. I am now trying to work out how to send commands to control the motors via a Flask webserver

Thanks,

Mitchell Shorto