We start by assigning the pins we are going to use and declaring them as output: // Motor AĪnd now we are going to create the functions to move the motors. We are going to make a little program that moves the motors in both directions, forward and backward, and in opposite directions of each other, also varying the speed of movement. Now we are in a position to start programming. The assembly scheme that we are going to use is going to be the following one, although you can use the pins that you want whenever we respect that those that we connect to ENA and ENB are PWM. If we have the jumpers in place, the motors will rotate at the same speed. We will connect them to two Arduino PWM outputs so that we send a value between 0 and 255 that controls the speed of rotation. To control the speed of the motors we have to remove the jumpers and use the ENA and ENB pins. And the same with pins IN3 and IN4 and engine B. They work so that if IN1 is at HIGH and IN2 at LOW, motor A turns in one direction, and if it is IN1 to LOW and IN2 to HIGH it does to the other. The pins IN1 and IN2 are used to control the direction of rotation of the motor A, and the pins IN3 and IN4 of the motor B. If it were not so, we would have to reverse the connections. Keep in mind the polarity when connecting them, so that when later we make them move forward, they work as they should.
![how to connect l298n motor driver how to connect l298n motor driver](https://lastminuteengineers.com/wp-content/uploads/arduino/Wiring-NEMA-17-Stepper-Motor-with-L298N-Arduino.png)
The outputs for engines A and B will give us the energy to move the engines. In this session we are going to focus on the control of DC motors. The other connections are used in one way or another depending on whether we are going to drive two DC motors or a stepper motor.
![how to connect l298n motor driver how to connect l298n motor driver](https://www.bluetin.io/wp-content/uploads/2017/07/l298n-dual-h-bridge-pin-connection-guide.jpg)
![how to connect l298n motor driver how to connect l298n motor driver](https://lastminuteengineers.com/wp-content/uploads/arduino/L298N-Motor-Driver-Module-Pinout.png)
The voltage range in which this module works ranges from 3V to 35V, and an intensity of up to 2A. We have talked about them before, but basically an H-bridge is a component formed by 4 transistors that allows us to reverse the direction of the current, and in this way we can reverse the direction of rotation of the motor.
#How to connect l298n motor driver driver
The L298N H-bridge driver board module allows us to control the speed and direction of two DC motors or a stepper motor in a very simple way, thanks to the 2 H-bridge it is mounted on.