Control Speed of DC Motor

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Control Speed of DC Motor

Post by yllumi » Mon Aug 25, 2014 6:56 am

Hi everybody,

I am trying to control rotation speed of vibrating motor using pyboard. Continuing from my previous post http://forum.micropython.org/viewtopic.php?f=2&t=267, I want to get the analog input from HC-SR04 ultrasonic range sensor and use it to control the power of vibrating motor rotation. My problems is, when I trying to rotate motor, the motor is not even rotating. I think the power should come from the batteries directly. Or I did something wrong.

Can anyone help me?

fma
Posts: 164
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: Control Speed of DC Motor

Post by fma » Mon Aug 25, 2014 6:59 am

How did you connect your motor?
Frédéric

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Control Speed of DC Motor

Post by dhylands » Mon Aug 25, 2014 7:46 am

You can't drive a motor directly. It draws too much current. You need to use a motor driver board which is sized for your motor. If you only need to drive the motor in one direction you can use a simple MOSFET, otherwise you'll need a full H-Bridge.

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Control Speed of DC Motor

Post by yllumi » Mon Aug 25, 2014 10:27 pm

fma wrote:How did you connect your motor?
I use pin X5 with DAC object. I guess with it I can control the rotation power.
dhylands wrote:You can't drive a motor directly. It draws too much current. You need to use a motor driver board which is sized for your motor. If you only need to drive the motor in one direction you can use a simple MOSFET, otherwise you'll need a full H-Bridge.
So should I make motor driver board or do you have a recommendation where I can buy it?

riklaunim
Posts: 32
Joined: Fri Aug 22, 2014 5:42 pm

Re: Control Speed of DC Motor

Post by riklaunim » Mon Aug 25, 2014 11:07 pm

In most electronics stores, just look for H-bridge DC motor controllers. With those and pyboard PWM you will be able to controll speed and directon of the DC motor.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Control Speed of DC Motor

Post by dhylands » Tue Aug 26, 2014 1:49 am

yllumi wrote:
fma wrote:How did you connect your motor?
I use pin X5 with DAC object. I guess with it I can control the rotation power.
dhylands wrote:You can't drive a motor directly. It draws too much current. You need to use a motor driver board which is sized for your motor. If you only need to drive the motor in one direction you can use a simple MOSFET, otherwise you'll need a full H-Bridge.
So should I make motor driver board or do you have a recommendation where I can buy it?
Which country are you in?
Which motor are you trying to control?

Even small motors like these: http://www.pololu.com/product/114/specs have a stall current of 2.1A so you want your motor driver to be able to drive that much current. Something like http://www.pololu.com/product/1212 would work for those motors.

This motor: http://www.pololu.com/product/2360 only has a stall current of 0.36A, so you can use a much smaller motor driver: http://www.pololu.com/product/2136

The motors used in RC trucks often have stall currents of around 20A, and require much bigger motor drivers, like this: http://www.pololu.com/product/1455 or http://www.robotmarketplace.com/product ... 25-RC.html

This one: http://www.robotmarketplace.com/products/0-IBCv2.html will do 50A per motor (and is priced for it too), but its an extremely well designed motor driver.

Some other products I've used:
https://solarbotics.com/product/k_smd/
https://solarbotics.com/catalog/motors-servos/

And other places that you can get motor controllers:
http://www.lynxmotion.com/c-10-motor-controllers.aspx
http://www.robotshop.com/en/catalogsear ... t&dir=desc
https://www.sparkfun.com/search/results ... controller
http://www.parallax.com/search?search_a ... tor+driver

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Control Speed of DC Motor

Post by yllumi » Wed Aug 27, 2014 9:00 am

I am using a very tiny vibrating motor. I want to control the power of rotation using dinamic voltage output from DAC pin, but because of a low current from that pin, so I have to use external power by using H-bridge or L293D chip. I have not try it yet.

fma
Posts: 164
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: Control Speed of DC Motor

Post by fma » Wed Aug 27, 2014 9:06 am

If you don't need to invert the polarity, a simple FET is enough. But in each case (FET or H-bridge), you will need to use a PWM output, instead of DAC output.
Frédéric

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Control Speed of DC Motor

Post by yllumi » Wed Aug 27, 2014 9:31 am

fma wrote:If you don't need to invert the polarity, a simple FET is enough. But in each case (FET or H-bridge), you will need to use a PWM output, instead of DAC output.
How can I get PWM output from pyboard?

update: I will try this module first http://wiki.micropython.org/contributedmodules/pwm

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Control Speed of DC Motor

Post by dhylands » Wed Aug 27, 2014 2:51 pm

That's whats available for now.

I have something working that hasn't been merged yet. I just need to code up the teensy version to make sure it works on both:
https://github.com/micropython/micropython/pull/815

Post Reply