Driving DC Motors w...
 
Notifications
Clear all

Driving DC Motors with Microcontrollers

31 Posts
5 Users
10 Reactions
2,561 Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1088
Topic starter  

How to use 7 different motor driver modules with an Arduino or any microcontroller. Hookup, code & demonstrations with motors big and small.

Today we will be working with lots of motor drivers and lots of motors!

You’ll see how there are actually three methods used among all of these drivers for controlling speed and direction. Because of this, it’s pretty easy to swap drivers and use a sketch for small motors to be used with much larger ones (or vice-versa).

I’ll be driving everything with a simple Arduino Uno today, but you could use any microcontroller to work with these motor drivers.

The code for all these motors is pretty simple, I’ll show it to you, and I’ll also introduce you to a few libraries that make coding for these motor drivers a breeze. We’ll also check out a motor driver library from Cytron that is a hidden gem, as it can be used with ANY of these drivers!

Here is the Table of Contents for today's video:

00:00 - Introduction
01:17 - DC Motor Driver Basics
08:05 - L298N Dual H-Bridge
16:13 - TB6612FNG Dual H-Bridge
25:24 - DRV8871 Single H-Bridge
31:08 - MX1508 Dual H-Bridge
38:54 - DBH-12 Dual H-Bridge
46:27 - IBT-2 Single H-Bridge
51:17 - MD25HV Single H-Bridge & Controller
1:02:27 - Conclusion

Hope you enjoy this, remember that the article on the DroneBot Workshop website has all the code I used today.

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

Good timing, I am just starting to experiment with these.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Me-Chiel
(@me-chiel)
Member
Joined: 3 years ago
Posts: 9
 

If you ever do a follow up on these motor drivers, be sure to add this nifty piece of hardware:

it was exactly what I needed to drive some 12V linear motors.

rz7886 dc motor driver 7a 8 pin dip if you are in the Netherlands

RZ7886 DC motor Driver 7a 8 pin dip if you want them from Ali-Express

Small, simple and cheap.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@me-chiel What is it, why is it a good choice? I had a quick look at specs, didn't see much to catch my attention, what caught yours?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Me-Chiel
(@me-chiel)
Member
Joined: 3 years ago
Posts: 9
 

I was looking for simple 12V controllers that could handle some current. These are not PWM controlled but just "FWD" "REV" "STALL" and it works on 3.3V so I could use them with my ESP32's.

The form-factor is the smallest, and they just work:)
It doesn't get any simpler than that. My humble opinion is that these tiny IC's deserve some mentioning as well.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@me-chiel Thanks for the clarification. The 'tiny' is a problem for me, and I suspect a lot of us older folks, but I will soon get a decent hot air gun, so maybe I can handle the 'tiny' chips. Since I am fairly sure I want more control than that I don't see a use for wheeled propulsion, but may be useful for a hovercraft.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@rob7912)
Member
Joined: 8 months ago
Posts: 9
 

I'm new to electronics so some terms are unfamiliar to me. PWM? I know what it does but still confused. Not sure if this is true but I read that the PWM of a motor controller is not the same PWM of an RC receiver. Is this True?

The reason I'm asking is that I want to control the same very large motor with the MD25HV controller that Bill used in this video. I would like to attach the RC receiver PWM to the PWM of the MD25HV? Is this possible or do I need an Arduino UNO to be in-between. I've searched for this info and can not get the information I need, everything is through an Arduino.

If it is possible to direct connect the RC receiver to the Md25HV, what would be connected to the DIR pin on the MD25HV?

Thank you in advance for your help.

This post was modified 8 months ago 3 times by Rob7912

   
ReplyQuote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1088
Topic starter  

@rob7912  The PWM signal from your radio controller is not the same as the type used by the Cytron driver. The signal from your RC controller incorporates both speed and direction, whereas the Cytron expects a separate PWM and direction input.

You COULD use an Arduino or other microcontroller to do the conversion, my article and video about using RC remotes has what you need to do that. But that's not the way I would do it.

A simpler, "plug and play" solution is to use a DC Motor ESC (Electronic Speed Control). While most ESC devices are for brushless motors, you can get ones from DF Robot (and probably others) for brushed motors.  I've used the DF Robot ones, and they work perfectly with my Flysky FS 16-X.

If you want to learn more about PWM (Pulse Width Modulation) I covered it a long time ago in my H-Bridge article and video.

And, BTW, welcome to the forum!

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
ReplyQuote
(@rob7912)
Member
Joined: 8 months ago
Posts: 9
 

@dronebot-workshop Hi Bill, Thank you for the welcome.

I did view these videos before and just re-viewed again. I'm confused, are Motor Drivers/Controllers only to be used with an Arduino or other microcontrollers?

I'm guessing that ESCs have motor drivers/controllers built in? Like I said I confused.

This is the list of equipment I have purchased for the project:

  1. MD25HV Cytron 25Amp 7V-58V High Voltage DC Motor Driver Speed Controller 
  2. 24VDC Rated Current 16.5 350W Brushed Electric Motor Permanent Magnet Motor
  3. ASMC-04B Robot Digital Servo High Power Torque 12V/24V 180kg.cm 
  4. Radiolink RC4GS V3 5 Channels RC Transmitter and R6FG Gyro Receiver, 2.4GHz Surface Remote Controller

I will be using a 12 volt battery to power the motor and servo. I was going to use the 5VDC out from the MD25HV to power the RC receiver.

I can see that the 20A Bidirectional Brushed ESC Speed Controller without Brake (XT60 Connector), has the connection for the RC receiver, and the other set of wires looks like they are for battery and motor. 

Would I still need the MD25HV? I purchased the MD25HV because it looked like an all inclusive board. I can return it if I don't need it.

The project is to build RC controls to put on a child sized 4 wheel pedal cart, no one will ride it, it is for a skeleton to pedal around for Halloween, I need to get it working before October.

Any help would be appreciated, this got more involved than I was expecting. Any help would be greatly appreciated.

Thanks in advance.

This post was modified 8 months ago by Rob7912

   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi @rob7912,

Please note your question is dealing with equipment that I am not familiar ... this is just a comment based on what I can gather from data specs, etc on the web. Of course, I am just expanding on the information Bill (@dronebot-workshop) has provided, since he is definitely the expert in this field. Hopefully someone else will provide further information, including pointing out any mistakes of mine. And of course, if I do make any mistakes, all I can do is apologise in advance, which I do.

-----------

PWM ... Pulse Width Modulation ... is very generic term ... the principle it is based on, is that it is a signal, which has two levels, and each of the 2 levels are assigned a descriptive name, so you will see pairs of names like: On & Off, 0 & 1, 0V & 5V, etc. The pair of names will be chosen to suit the particular circuit and circumstances. I'll use 0 & 1 for convenience here.

Now a signal carries information or data ...and for PWM, the data is encoded by varying the width (amount of time) when it '1', compared to when it is '0'. In a practical code, there will be 'rules' as to what range of time values are allowed, and possibly more sophisticated 'rules', of particular patterns of 0 & 1 timings, that the transmitter can encode, and the receiver can decode, to pass more complex messages.

----

The simplest case of PWM is when it is being used to send a 'value' between 0.0 and 1.0, so that for example) 0.5 will have equal time periods of 0 and 1, whilst 0.25 would have a 0 time period 3 times the length of the 1 period. Providing the actual time periods are kept short, this signal can often be directly used to control power output transistors (or similar) for speed of a motor or brightness of a light.  

This simplest case appears to apply to the Cytron controller. Note that this signal can only control the speed of the motor. A second signal (DIR) is needed to specify direction, forward or reverse.

It is easy to construct a programme for an Arduino or similar microcontroller to produce the two required signals (PWM-speed + direction), but it is not the 'traditional' signalling convention for Radio Control, so it may be difficult/impossible to find a suitable 'off the shelf' RC decoder to drive the Cytron decoder. Bill has provided a link to using an Arduino, whilst advising you to look for an alternate course of action.

-----

Radio Control (RC) has 'traditionally' used PWM to signal servo control messages, using protocols defined for the purpose. A brief description of the underlying protocol is given in

Wikipedia : https://en.wikipedia.org/wiki/Servo_control

There are clearly individual RC manufacturer's adaptations, but that is beyond my experience, so please read the specifications of an individual product, to see if it is compatible. (I suspect there will be a fair degree of compatibility, but I don't know, and this type of situation often ends up with 'odd' cases that don't work.)

-----

Bill provided a useful reference for a product that appears to be designed to decode the RC protocol and directly drive a motor. 

ones from DF Robot

This shows the style of product, which if suitable, would drive the motor without the need for the Cytron unit. Unfortunately, the voltage specification says:

image

specifying a maximum of 8.4 V, whilst your motor says it requires 24V

So I think you need to find a 'similar' style device, but with higher voltage rating.

--------------

So, sorry, this is not a 'I have built one, so I know it works', but rather 'I had a quick look on the web, and thought this might be worth you looking at', type of answer. Please be careful, as the motor is nearly 0.5 horsepower, so make sure you have fused the line from the battery and an emergency power interrupt mechanism, in case the controller decides to go haywire. 

Best wishes and good luck, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@rob7912  @davee I second everything that Dave says. I would add that your best course forward might be to find a project either here or elsewhere that is a close match to what you want. Perhaps Bill's RC Robot Car.

I may be misunderstanding, but is that the right kind of motor?

CONCERNED: I am a little concerned with the size and power of a moving device especially after dark during a time when many kids are about. Make sure you have line of sight, and a self centering throttle.

Good luck

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1088
Topic starter  

Posted by: @davee

This shows the style of product, which if suitable, would drive the motor without the need for the Cytron unit. Unfortunately, the voltage specification says:

image

specifying a maximum of 8.4 V, whilst your motor says it requires 24V

So I think you need to find a 'similar' style device, but with higher voltage rating.

Good catch, I hadn't read that far back to get the motor specs.

There are other Brushed Motor ESC devices of course, this one from Ali Express seems to handle the voltage and more current than most of us will ever need. I haven't used it before, just found it with a quick Google search.

Just be sure you get an ESC for BRUSHED DC motors, most of them are for brushless motors.

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
DaveE reacted
ReplyQuote
(@rob7912)
Member
Joined: 8 months ago
Posts: 9
 

@davee Thanks Dave, That was very helpful.


   
ReplyQuote
(@rob7912)
Member
Joined: 8 months ago
Posts: 9
 

@zander Hi Ron, The motor I'm using is the large at the end of the video. We were not sure what we were going to us as a vehicle so we decided on the largest. I'm new to RC so I don't understand the motor or servo strengths, I'm sure we over engineered what we needed.

We expect to only go about 2-3 mpg and it will mostly be run during the day in our campground. We go all out in October for Halloween, I think we can give Disney World a run for their money when it comes to Animatronics. We though this would be our home grown Animatronic that the guests will get a kick out of. If we can pull it off.

 


   
DaveE reacted
ReplyQuote
(@rob7912)
Member
Joined: 8 months ago
Posts: 9
 

Working on this same project, I will need a large battery to be able to run the project for a few hours a day. Is it OK to use a 6 or 8 volt golf cart battery, we have many sitting around? Or is there a better smaller choice other than the S battery packs?

Thanks for your help.


   
ReplyQuote
Page 1 / 3