Interface L298N Using NodeMCU




Introduction: Interface L298N Using NodeMCU

About: " Work until you no longer have to introduce yourself " Show some love on Instagram & Motivate me on YouTube @TheCircuit

Hi Makers,

In this Instructable we go through how to interface an L298N Dual H-Bridge Motor Driver module with an NodeMCU.

So, let's get started.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials You Need

Hardware Requirements

  • L298N Dual H-Bridge Motor Driver module (various models will work)
  • NodeMCU
  • Jumper wires
  • DC Power Supply (7-35v)
  • DC Motors

Software Requirements

  • Arduino IDE

Step 2: Descritions

Getting to Know Your L298N Dual H-Bridge Motor Controller Module

An H-Bridge is a circuit that can drive a current in either polarity and be controlled by Pulse Width Modulation (PWM).

What is Pulse Width Modulation?

Pulse Width Modulation is a means in controlling the duration of an electronic pulse. Motors will last much longer and be more reliable if controlled through PWM.


  • Double H bridge Driver Chip: L298N
  • Logical voltage: 5V
  • Drive voltage: 5V-35V
  • Logical current: 0-36mA
  • Drive current: 2A (MAX single bridge)
  • Max power: 25W

Note: Built-in 5v power supply, when the driving voltage is 7v-35v. But i recommend you not to power up your microcontroller with on-board 5v power supply.

Step 3: Circuit Diagram

Supply Connections :

+12v - Positive terminal of the battery to be connected.

GND - Ground terminal of the battery to be connected.

+5v - +5v input (unnecessary if your power source is less than +7v to +9v, if the power source is greater than +9v to +35v then it can act as a 5v out)

Input Connections :

(Motor A)

ENA - Enables PWM signal for Motor A

IN1 - Enable Motor A

IN2 - Enable Motor A

(Motor B)

ENB - Enables PWM signal for Motor B

IN3: Enable Motor B

IN4: Enable Motor B

Note :

  • Make sure you have all of your grounds connected together. (NodeMCU, Power Source, and Motor Driver)
  • The PWM Pins are unnecessary if you do not want to control PWM features.

Step 4: Wiring Connections

Check the Circuit Diagram for any confusions.

Step 5: Coding Time

int ENA = 4;

int IN1 = 0;

int IN2 = 2;
void setup() {

// set all the motor control pins to outputs

pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

// this function will run the motors in both directions at a fixed speed

void testOne() {

// turn on motor

digitalWrite(ENA, HIGH); // set speed to 200 out of possible range 0~255
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);

delay(2000); // now change motor directions

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);

delay(2000); // now turn off motors

digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
// this function will run the motors across the range of possible speeds

// note that maximum speed is determined by the motor itself and the operating voltage
// the PWM values sent by analogWrite() are fractions of the maximum speed possible by your hardware

void testTwo() {

// turn on motors

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);

// accelerate from zero to maximum speed

for (int i = 0; i < 256; i++)

    analogWrite(ENA, i);

// decelerate from maximum speed to zero

for (int i = 255; i >= 0; --i)
      analogWrite(ENA, i);

// now turn off motors

digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
void loop() {


Download the "L298N_NodeMCU.ino" file and open it up in the Arduino IDE.

Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload. You can tinker with it if you like based on the application, or just use it as it is.

Step 6: OUTPUT

That's all Makers.

You have successfully completed another instructable, It takes pretty less time to create this instructable, and its fun too.

Thank you. Stay tuned for another interesting Instructables.

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Be the First to Share


    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Tiny Speed Challenge

      Tiny Speed Challenge

    5 Discussions


    Question 3 months ago on Introduction

    The code works fine till nodemcu is connected to my pc for power source,

    But as soon as I power it up using 12v DC battery and 7805 chip motor starts running at full speed


    9 months ago

    I would like to clear the way you connected the board to the power.
    I think that you have missed the V+ to the board.
    I have no idea. I copied and replicated your project but a motor did not start.
    Sketch was uploaded successfully. Inbuilt led blinks and it seems that the board works properly.
    Thanks a lot in advance.


    Question 10 months ago

    What to do to control 4 motors at a time ?


    Question 1 year ago on Introduction

    Hi, I have a similar project and your tutorial was really helpful. I have a question to you, do you maybe know how to write a code so that I can control the motor speed and change its direction from right to left when I want? thanks in advance


    Answer 1 year ago

    you are probably going to have to use pwm (pulse width modulation) this can change the speed