Digital Control of DC Motors
Updated: May 7
Drones, submarines or automobiles, all vehicles have one entity in common, without which it is impossible for it to work: the Motor. Indeed, a vehicle without mechanical materialization of electrical energy is unimaginable. In fact, there are several types of motors, but the focus of this article is the control and use of DC motors using digital signals.
The DC motor rotates in one direction when directly polarized and in the opposite direction when reversed polarized. You should imagine that like LEDs, buzzers and other simple electronic components, it is possible to connect them to the digital or analog ports on your microcontroller and control them by sending direct signals. Even if the voltage of the analog / digital ports is sufficient, the high current required by these components can (literally) fry the microcontroller. So, how to use motors, controlling their speed, direction of rotation and even using an external power supply?
To get around this situation we use a circuit known as the H-Bridge. An H-bridge is a circuit with the shape that resembles the letter H and is capable of altering the polarization of the central element through external signals. Turning it simple, this circuit has 4 switches that, when connected in certain combinations, allow current to flow in the motor in the desired direction, changing its direction of rotation. These switches can be replaced by electronic components, such as Transistors, which allows the polarity of the central element to depend exclusively on an external digital signal sent to the circuit.
How to control motor using these concepts:
An usual implementation of the H bridge is done using IC l293D. This chip contains 2 H-bridges, through 4 ways, that is, it can control two independent motors, holding up to 600mAh in each and voltage from 4.5 to 36 Volts.
The pins work as follows:
1,2EN -Activate channels 1 and 2
1A -4A: Input
1Y - 4Y -Output for motors
3,4EN -Activate channels 3 and 4
Ground -IC Ground
Vcc1 -IC Voltage Input
Vcc2 -Output Power for motors (From 4.5V to 36V)
1 - First we will power up IC using 5 volts of the Arduino (Vcc1), the power for the motors (Vcc2) and connect the grounds.
2 - Now we connect 3,4EN and the Inputs 3A and 4A on the Arduino.