DC motor turning 180 degrees

Consistent Motor control – specifically 180 degrees

Ask Question

Asked today

Active today

Viewed 9 times


I am struggling to get my motors to perform the same on each run. The first time I run the program, they will perform the same movement about 8/10 times. The second time I start the program, the movement does not perform the same as the last. It is significantly different.

How can I get my motors to perform the same exact movement, starting at Position A, turning 180 degrees forward to Position B, and then reversing 180 degrees back to Position A. Also, if there is a better method to implement this, please let me know. Need decent speed with high torque. This is the original way that was working for me with a singular motor.

I am using a 9V battery powering into my L298N Motor controller where I have 2 6-12V Mini DC Motors directed into. I then run the according control pins to my pi. I noticed when powering just one motor, I got much more consistent results in-between program starts. I am assuming it is because the power is not weaker, splitting into the two motors? Is the difference in power producing inconsistent results?

def init():
    gpio.setup(17, gpio.OUT)
    gpio.setup(22, gpio.OUT)
    gpio.setup(23, gpio.OUT)
    gpio.setup(24, gpio.OUT)

def forward(tf):
    gpio.output(17, True)
    gpio.output(22, False)
    gpio.output(23, True)
    gpio.output(24, False)

def reverse(tf):
    gpio.output(22, True)
    gpio.output(23, False)
    gpio.output(24, True)

for i in range(0,10):
    print ("forward")
    print ("backward")




asked 3 hours ago

Justin Priede

13144 bronze badges

  • (1) It is not clear what do you mean by “the same exact movement“. You need to be more precise. For example, can you tolerate a couple of degrees for a 180 degree movement, (2) It is not clear what do you mean by “decent speed and high torque“? (3) You need to specify more precisely. For example move 180 degrees in one second, or 0.1 second. (4) About the torques, you need to give a spec. Example, is a toy servo Towerpro MG996’s of 10kgf.cm good enough for you? Ref: html.alldatasheet.com/html-pdf/1131873/ETC2/MG996R/110/1/… – tlfong01 2 hours ago   
  • 1@tlfong01 I can spare a couple degrees but not much room for that… I need the action to be done in about a second and as for torque I am lifting about 50 grams. I am new to this so adding proper detail is harder for me. – Justin Priede 2 hours ago
  • (5) Ah, your updated spec is good enough to start doing experiments. So, let us say, for positioning, the tolerance is 5 degrees for a 180 degree movement, (6) Your updated spec of 50grams is also good, but you need to specify the diameter of the wheel or pulley lefting up the 50g load. For example, if the wheel is 10cm, then radius is 5cm, and the torque is 50gf.5cm, which can be handled by a toy servo or DC motor. (7) The speed of 1 second to do the movement is also OK for toy motors. – tlfong01 2 hours ago  
  • (8) Your motor seems to be for high speed applications, such as drilling or racing cards. If you don’t need high speed, you can consider a gear motor, which decreases speed, but increases torque. – tlfong01 2 hours ago  
  • You might like to skim my answers to motor questions below, to see how I am playing with DC, BLDC, and stepper motors. (9) DC Motor Speed Control using PWM electronics.stackexchange.com/questions/510755/… (10) BLDC Motor Control electronics.stackexchange.com/questions/590373/… (11) DC Motor with encoder electronics.stackexchange.com/questions/566586/… – tlfong01 2 hours ago   
  • (12) You might also like to let us know more details of your application, a sketch or a photo would be helpful. Then I can start compiling an answer and upload here. – tlfong01 2 hours ago  
  • 1I would be surprised if this incomplete code did anything other than print a string of error messages. – Milliways 16 mins ago 
  • @Justin Priede: (13) Some more references you might find useful: Always stop the motor at the same position (a) electronics.stackexchange.com/questions/608578/… Always stop the motor at the same position (b) electronics.stackexchange.com/questions/610405/… ESP32 Motor Control Pulse Width Modulator (MCPWM) docs.espressif.com/projects/esp-idf/en/latest/esp32/… – tlfong01 1 min ago   Edit  Delete

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.