This post is dedicated to curious about the basics of DC motors in robotics and precisely how to control them. You can begin with the previous post dealing with the different motors used for robotic applications. While some of them are not often used, others, as the DC brushed motor, are more common.
In this post, be aware that the word motor will be short for DC brushed motor.
Today, I’m talking to you about the basics of how to control your motor.
One of the main features of these motors is the simplicity of use: if you plug each wire of a battery into the motor’s terminals, it is likely to turn one way. If you switch the wires, it will turn the other way.
(Of course, it’s a little bit more complicated since the battery must not be too powerful for the motor. If not, the motor may be damaged.)
But this is the problem: it just turns. No speed control. No direction control unless you manually inverse the wires. At this point, your motor is a little bit impertinent. This is painful if you want to build a rover robot for Venus ground (Mars is so 2017)…
If we talk about priorities, we will find that direction control comes before speed control. Why? Because you’d rather have a rover that rolls way too fast with jerky turns than a rover that moves smoothly in only one direction — and cannot turn. Yes, you get it.
So let’s put aside the speed control for a while and focus on the direction control.
As I said earlier, if you plug the positive wire of your battery on one of the motor’s terminals and the negative wire on the other motor’s terminal, the motor rotates in one direction. If you switch the wires, it rotates in the other direction. In the following images, U are batteries, and M are motors.
We could design a small circuit with a mechanical switch (S) to make it more automatic. Switching the switch (yes, this is how it works) changes the polarity, hence the direction of rotation:
At this point, this sassy motor is no longer controlling you, but you are still far from having complete control on your side.
You are still in manual mode. Your hand and your fingers must press the toggle switch to invert the direction. And please, don’t build a robotic arm that does it instead of your hand.
To avoid using your hand, I want to introduce you to H-bridges.
H-bridges are simple electronic circuits (they have the size of a chip actually, but can easily be made with discrete components). They allow the voltage to be applied in one direction by opening and closing four doors.
In the example below, the motor (M4) is situated at the center of the horizontal bar of the H.
Only two configurations can make the motor rotate, in one direction or the other:
Configuration 1: S2 and S5 are closed, S3 and S4 are opened
Configuration 2: S2 and S5 are opened, S3 and S4 are closed
Ok, now that’s too many schematic pictures. I don’t know about you, but I find this very exhausting, so please take a while and relax.
Let’s go back to control.
Any other “doors” configuration would result either in nothing happening, either in a short circuit on the power supply (which is terrible), or either in braking the motor.
With Luos, you can control every part of your system in the same place. We are like Docker, for embedded systems:
Note: braking (or short-braking) a motor consists in connecting both its terminals together. It only works when the rotor is moving, resulting in shorter stopping. But you can quickly try it at home with a disconnected motor: turn the axis with your hand, then do it again while connecting the terminals; you’ll feel the rotor is a little bit harder to turn.
— Ok, you’re telling me, but what you call “doors” looks quite like push-buttons to me. That means I’ll need my hands again, and two of them this time!
Right, this was only the simple way to explain it. These doors can be replaced by several components, called transistors or MOFSETs. The most used is called the bipolar transistor. This three-legged component will take the role of an automated door; it means that connected to a microprocessor that sends commands, each door automatically lets a certain amount of current flow through it or blocks it. This results in a door or a no-hands-needed push-button.
This kind of transistor works like a controlled door: the B side is the control side, from where you choose to open or close. If a small “signal” current flows through B to E, the door is opened and lets a more significant “power” current flow from C to E. If no current flows from B to E, the door is closed, and no current is allowed from C and E.
Note: This explanation is for the case of a perfectly saturated transistor. The reality may be a little more complex.
Also, you can find PNP (this was an NPN), which is the opposed polarity.
Many electronic control boards (like L298N) carry one or several H-bridge chips in their design. The microprocessor you’re using (for example, the one in an Arduino board) is connected to the input pins of the control board. High and low signals from the microprocessor will then command the H-bridge chip to make the motor rotate the way you want.
- You write a program in a microprocessor (more accessible with the help of a developing board).
- The microprocessor sends high or low signals to the H-bridge (easier with a controlling board).
- The H-bridge orient the voltage so that the connected motor can rotate the way you politely asked it.
Of course, you will have to program your developing board to work properly. Many websites provide great help for dealing with Arduino or Raspberry Pi boards.
Note: H-bridges are used for other functions, like, for example, DC-to-AC converters. Also, the stepper motors are controlled by H-bridges, but it’s slightly more complicated.
Congratulations. Despite some pictures challenging to watch for too long, you now have half the control of your not-that-eager-now motor. In the next part, we will look at the speed control, still on DC brushed motors. One more step towards total control!
Thank you for reading.
— If you liked what you read, please clap the hell out of it and follow us on Reddit!
Discover the following article: How to stop being controlled by your DC motor: reverse the roles! Part 2.