The microcontroller installed on the Arduino board is not capable of delivering high current through its pins. What to do if you need to manage relatively powerful engines, for example, to move the robot?
In such cases, along with Arduino, a driver is used - a power unit controlled by the board and capable of switching a large current. The most famous such driver for collector engines - L298N!
BRIEF OVERVIEW OF THE MODULE
L298N - driver collector motors for 2 channels, which can also be used to control a single stepper motor. Driver pavement that allows you to use it without additional transistors missing shoulders. The maximum supply voltage of the motors is 46 V, the current per channel is 2 A.
The driver allows you to easily and clearly control the speed of rotation of the motors in both directions using PWM (separately for each motor).
The L298N based module does not require external components to get started. All you need is a dozen wires to connect power and control signals.
To control the direction of motion used 4 wires + 2 wires to adjust the speed.
SCHEME OF CONNECTION TO ARDUINO
To control the motor directions, 4 inputs are used - IN1-IN4, besides them - 2 more wires (1 per channel) for PWM speed control. They can be immediately closed with jumpers on + 5V for maximum rotational speed, saving these 2 pins of the controller.
IN pins are connected to any Arduino pins, ENABLE - only to the mark (PWM) marked on the board.
There are 4 possible combinations on the pins of the module:
- IN1 = 1, IN2 = 1 - the engine stands still;
- IN1 = 0, IN2 = 0 - the engine stands still;
- IN1 = 1, IN2 = 0 - the engine turns in one direction;
- IN1 = 0, IN2 = 1 - the engine turns in the other direction.
Please note - transistors have a relatively fast switching speed, but still the shutter does not close instantly. In some cases, it may happen that when the reverse transistor will have time to open, but the complementary will not close yet and a short circuit will occur.
To avoid this, you can press pins to a single voltage for several milliseconds and only then perform a reverse. If in your particular case there is enough time, then unnecessary delays can be eliminated. But note that there may be a microcontroller reset!
For example, let's write a small sketch in which we will accelerate the motor using PWM control:
#define IN1 5
#define IN2 4
#define ENA 3
pinMode (ENA, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
You can also stop the motor by giving the same signals, like this:
Or apply reverse braking by swapping signals in places. It will be extremely effective, but can lead to a voltage drop due to the large current.
It is advisable to use a power supply with large output current and hang several large capacitors in parallel in parallel if stability is really important.
Now you can build your robot or anything else motorized using Arduino!