Skip to main content

L298N Motor Drive Controller - Reference Guide

Navigation - L298N Quick Reference Guide:

IN1 and IN2 = Right Motors
IN3 and IN4 = Left Motors
ENA and ENB = controls the speed of the right and left motors via PWM.

ENA or ENB
IN1 or IN3
IN2 or IN4
Motor Action
0
X
X
Stop
1
0
0
Brake
1
0
1
Forward
1
1
0
Backward
1
1
1
Brake


Connection on the Arduino: 









Pin Connection
L298N
Arduino Microcontroller
ENA
10 (~PWM)
ENB
5(~PWM)
IN1
9
IN2
8
IN3
7
IN4
6


Car Movement Directions vs. Wheels Rotation




Car Moves Forward

Car Moves Backward

Car Stops

Car Turns Left

Car Turns Right

Left Wheels\Motors

Forward

Back

Stop


Back


Forward


Right Wheels\Motors


Forward

Back

Stop

Forward

Back







(Picture courtesy of ArcBotics)



Sample Code:

Here is a code I wrote to make the care move forward:

/* 
    Amr - 11/14/2017
    Basic Navigation 
    Car Moves Forward
*/

// defining the pins connected between the L298N Dual H-Bridge and Arduino Microcontroller

//pins that will control speed of motors, enable PWM
int ENA = 10;
int ENB = 5;

//right motors
int IN1 = 9;
int IN2 = 8;

//left motors
int IN3 = 7;
int IN4 = 6;



void setup() {
  // put your setup code here, to run once:
  //define the mode of the pins, are they pins sending data to outside peripherals? or recieving data? .....
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}


/*
    To move the car forward, both left motors and right motors must be rotating forward.

    So that means:
    Right Motor - ENA = 1; IN1 = 0; IN2 = 1
    Left Motor - ENB = 1; IN3 = 0; IN4 = 1


    We write the code for that in void loop() below
*/

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  
}


Popular posts from this blog

LTspice Tutorial: How to Design and Simulate a Circuit in LTspice

 If you do not have LTSpice already installed on your machine, please head over to LTSpice's page on Analog Device's website (Link: LTspice Information Center | Analog Devices ). Note: a video version of this tutorial is available here  Click on the applicable download button that suits your machine's operating system. Upon successfully downloading and launching LTspice, you will be greeted with a window that looks something like in the figure below. Alright, now we will need to create a new schematic. That can be done by either of the following approaches:  click on File then choose New Schematic . click on the New Schematic symbol   on the toolbar. on your keyboard, press Ctrl+N . Upon doing so, a new grey-ish screen will pop up... that will be your new empty schematic (just like the one in the figure below). In this example, we will try to design and simulate a very basic voltage divider.  To recap: a voltage divider is a circuit that takes a certain i...

How Does an Inverter (NOT) Gate Work - NOT Gate Explained

For a video version of this tutorial, please refer to this link . An inverter gate, or NOR gate for short, is one of the essential logic gates used constructed digital circuits. As implied by its name, the NOT gate works by taking an input, inverting it, then outputting the inverted value. The NOT gate schematic symbol looks like a triangle with clown nose on the Output side (as shown in the Figure above). In logic circuits, inputs and outputs are binary, which means their value can either be 0 or 1. So: If NOT receives a 0 at the input, it will output 1 . If NOT receives 1 at the input, it will output 0 . To sum it up, the truth table for the NOT gate will be as the following: Input Output X F 0 1 1 0 The NOT gate can be algebraically represented as the following:  F = X' (or you can have a bar above the X) where :     F is the output and X is the input

How Does an AND Gate Work - AND Gate Explained

 The following video goes over what an AND Gate is and how it functions, along with its logic and truth table.