{"id":5513,"date":"2019-03-02T16:52:05","date_gmt":"2019-03-02T21:52:05","guid":{"rendered":"https:\/\/dronebotworkshop.com\/?p=5513"},"modified":"2023-04-12T11:48:35","modified_gmt":"2023-04-12T15:48:35","slug":"dc-gearmotors-pwm","status":"publish","type":"post","link":"https:\/\/dronebotworkshop.com\/dc-gearmotors-pwm\/","title":{"rendered":"Control Large DC Gearmotors with PWM & Arduino"},"content":{"rendered":"\n

\"Download \"Parts<\/a> \"View<\/a> \"Download<\/a><\/p>\n

Introduction<\/span><\/h2>\n

I\u2019m very excited to announce a new project here in the workshop!<\/span><\/p>\n

I\u2019m building a robot. This probably won\u2019t come as Earth-shattering news on a site called \u201cDroneBot Workshop\u201d, but this robot is different. \u00a0Unlike the small \u201crobot car\u201d bases I\u2019ve used in past projects, this will be a big robot. A capable robot.<\/span><\/p>\n

A \u201creal\u201d robot!<\/span><\/p>\n

Real robots need big motors and for my robot, I\u2019ve chosen a couple of large DC gearmotors to do the job. \u00a0These powerful motors consume a lot of current, which means I\u2019ll need to use a motor driver that can handle the current without burning up.<\/span><\/p>\n

<\/div>\n

Today I\u2019ll show you how to do exactly that, control a large DC gearmotor and change its speed and direction. I\u2019ll be using an Arduino to create a Pulse Width Modulation (PWM) signal to regulate the motor speed and a Cytron MD10C motor driver to supply the power.<\/span><\/p>\n

\"Controling<\/p>\n

Let\u2019s get started!<\/span><\/p>\n

DC Gearmotors<\/span><\/h2>\n

DC gearmotors are used in many electromechanical applications in appliances, industry, and robotics. \u00a0Their high torque and low cost make them popular components for experimenters and hobbyists. <\/span><\/p>\n

A \u201cnormal \u201cDC motor spins at a very high speed, often several thousand RPM. \u00a0This is great for a high-speed drill but much too fast for spinning wheels to move a robot or car around. \u00a0<\/span><\/p>\n

In a gearmotor there are, not surprisingly, a set of gears that reduce the motor speed to something more manageable, a few hundred RPM or even less. \u00a0The motor I\u2019m using has a full-speed shaft rotation of just 110 RPM.<\/span><\/p>\n

\"DC<\/p>\n

When you reduce speed using gears you also increase torque, this inverse relationship means the slower you gear the motor down the more torque it will have. \u00a0\u00a0<\/span><\/p>\n

Most DC gearmotors, including the one I purchased for my robot, use brushed DC motors.<\/span><\/p>\n

Pulse Width Modulation<\/span><\/h2>\n

Pulse Width Modulation, or PWM, is a method of controlling the speed of a motor. It actually has many uses beyond that, controlling lights and LED\u2019s and data communications are a few other applications of PWM.<\/span><\/p>\n

With PWM control the DC current applied to the motor is sent in square-wave pulses. The width of the pulses is changed to regulate motor speed, the wider the pulse the faster the motor will spin.<\/span><\/p>\n

The pulse width is expressed as a percentage, at 50% the output is a perfect square wave. At 75% the pulse spends 75% of its time HIGH, the rest LOW. \u00a0At 25% it is HIGH 25% of the time and LOW for 75%. <\/span><\/p>\n

This width is called the \u201cduty cycle\u201d.<\/span><\/p>\n

At 100% width the pulse is constantly HIGH. The motor receives full power and spins at its rated output speed.<\/span><\/p>\n

At 0% the signal is constantly LOW, essentially meaning no voltage at all. Obviously, this causes the motor to stop.<\/span><\/p>\n

For a detailed explanation of PWM please see the article \u201c<\/span>Controlling DC Motors with the L298N Dual H-Bridge and an Arduino<\/span><\/a>\u201d. <\/span><\/p>\n

H-Bridges<\/span><\/h2>\n

A common method of controlling a DC motor is to use an \u201cH-Bridge\u201d. This type of controller allows you to change the polarity of the current sent to the motor.<\/span><\/p>\n

H-Bridge Operation<\/span><\/h3>\n

An H-Bridge is an arrangement of switches that allows you to apply current to a DC motor and reverse the polarity to spin the motor in the opposite direction, as illustrated below:<\/span><\/p>\n

\"H-Bridge<\/p>\n

By turning on two of the switches the current is directed to the motor, In the following illustration, the motor spins clockwise when the switches are turned on:<\/span><\/p>\n

\"H-Bridge<\/p>\n

Turning those switches off and then turning on the remaining two switches will cause the polarity of the current to be reversed. As a result, the motor spins counterclockwise.<\/span><\/p>\n

\"H-Bridge<\/p>\n

Of course in real life, we seldom would use switches to create an H-Bridge.<\/span><\/p>\n

Instead, we would use an active semiconductor switch, like a transistor, to do the switching for us.<\/span><\/p>\n

H-Bridge with Bipolar Transistors<\/span><\/h3>\n

In a traditional H-Bridge, like the L298N, the switching elements are built with bipolar transistors.<\/span><\/p>\n

Bipolar transistors are the oldest and one of the most common types of transistor. They are inexpensive and readily available, making them ideal for use in circuits like H-Bridges.<\/span><\/p>\n

\"H-Bridge<\/p>\n

The problem with bipolar transistors is that in switching mode they act a lot like a \u201cswitched diode\u201d, and like any diode, they have a voltage drop. A voltage drop of 0.7 volts.<\/span><\/p>\n

While that may not sound like a lot of voltage it actually does cause a lot of issues with H-Bridge circuits based upon bipolar transistors.<\/span><\/p>\n

First, there are two transistors, so the total voltage drop is 1.4 volts. This is significant, especially for low-voltage motors like the 6-volt ones commonly used in small robot cars. A 6-volt power supply would only deliver 4.6 volts (6 – 1.4) to the motor, causing it to operate below its peak efficiency.<\/span><\/p>\n

Second, that voltage doesn\u2019t just disappear. Instead, it is dissipated, mostly as heat. This is why many H-Bridge designs require big heatsinks.<\/span><\/p>\n

There is actually a better component that can be used, one that doesn\u2019t exhibit the problems suffered by bipolar transistor designs.<\/span><\/p>\n

H-Bridge with MOSFETs<\/span><\/h3>\n

A metal-oxide-semiconductor field-effect transistor<\/em>, or <\/span>MOSFET<\/span><\/a>, is a more advanced transistor that has become extremely popular in switching and amplifier circuits. <\/span><\/p>\n

When used as switch a MOSFET acts more like a \u201cswitched resistor\u201d than a \u201cswitched diode\u201d. \u00a0\u00a0A very low-value resistor at that.<\/span><\/p>\n

\"H-Bridge<\/p>\n

This gives the MOSFET a very low voltage drop. \u00a0The 0.1-volt drop on the above illustration is actually just an estimate, as a MOSFET acts more like a resistor the actual voltage drop is really determined by the amount of current flowing through it.<\/span><\/p>\n

Suffice to say that the voltage drop is extremely low.<\/span><\/p>\n

Because the MOSFET doesn\u2019t drop the voltage as much as a bipolar transistor it is superior to the bipolar transistor in the following ways:<\/span><\/p>\n