Your Business
Your Business
  • Home
  • Arduino Projects
    • List of projects
    • Traffic lights
    • L298N Motor driver
    • Ir Car
    • LCD
    • Led remote control
    • Ultrasonic Detector
  • ESP 32 Projects
    • ESP32 & 1.28 display
    • Weather Station
  • More
    • Home
    • Arduino Projects
      • List of projects
      • Traffic lights
      • L298N Motor driver
      • Ir Car
      • LCD
      • Led remote control
      • Ultrasonic Detector
    • ESP 32 Projects
      • ESP32 & 1.28 display
      • Weather Station
  • Home
  • Arduino Projects
    • List of projects
    • Traffic lights
    • L298N Motor driver
    • Ir Car
    • LCD
    • Led remote control
    • Ultrasonic Detector
  • ESP 32 Projects
    • ESP32 & 1.28 display
    • Weather Station

L298N Motor Driver with Arduino Nano - Full Tutorial

Project Description:

 In this video I show how to control the speed of a DC motor using an Arduino Nano, an L298N motor driver, and a potentiometer.  The motor is powered correctly through the L298N (OUT1 and OUT2), while the Arduino controls speed and direction using PWM. This setup is perfect for beginner Arduino projects, robot cars, and DIY robotics. 

Description

Materials Needed:

  1. Arduino Nanoor equivalent.
  2. HW-130 Motor Driver:
    • To control the motors.

  1. 1 DC Motors with Gearbox:
    • Two motors grouped for left-side control and two for right-side control.

  1. Ni-MH AA 2400mAh Battery Pack:
    • For powering the motors.

  1. Breadboard and Jumper Wires:
    • For connecting the IR receiver.


Circuit Setup

  CONNECTION OVERVIEW 

  • ENA → D9 (PWM speed control) 
  • IN1 → D8 
  • IN2 → D7 
  • Potentiometer → A0 
  • Battery → L298N VIN & GND 
  • Motor → L298N OUT1 / OUT2 
  • Common ground between Arduino and L298N

Arduino Code

// DC Motor Speed Control - Arduino Nano + L298N + Potentiometer


const int ENA = 9;   // PWM pin

const int IN1 = 8;   // Direction pin 1

const int IN2 = 7;   // Direction pin 2

const int POT = A0;  // Potentiometer


void setup() {

  pinMode(ENA, OUTPUT);

  pinMode(IN1, OUTPUT);

  pinMode(IN2, OUTPUT);


  // Set motor direction (forward)

  digitalWrite(IN1, HIGH);

  digitalWrite(IN2, LOW);


  Serial.begin(9600);

}


void loop() {

  int potValue = analogRead(POT);           // Read potentiometer (0–1023)

  int motorSpeed = map(potValue, 0, 1023, 0, 255);


  // Optional: avoid motor buzzing at low values

  if (motorSpeed < 40) {

    motorSpeed = 0;

  }


  analogWrite(ENA, motorSpeed);             // Send PWM to motor


  // Debug (optional for video)

  Serial.print("Speed: ");

  Serial.println(motorSpeed);


  delay(20);

}

Testing Instructions

  1. Assemble the Circuit:
    • Connect the motors, motor driver, and IR receiver as described.

  1. Upload the Code:
    • Use the Arduino IDE to upload the code to your Arduino Uno.

  1. Adjust Speed:
    • Modify the motor speed with potentiometer.

Download Stl

Files coming soon.

Copyright © 2025 Alex3dworks - All rights reserved

Powered by

  • Politica sulla privacy

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

DeclineAccept