Control DC Motor Speed Using Potentiometer + L298n + Arduino

Introduction: Control DC Motor Speed Using Potentiometer + L298n + Arduino

About: Hi, I'm an electronics and Arduino amateur, I try to share with you my experience and little projects, hope you like it. visit my youtube channel for more projects

Hello there,

Here in this tutorial we gonna try to control a DC motor speed using a potentiometer, L298n Motor driver and an Arduino board, (we won't complicate things with directions or other functions).

If it's your first time using the L298n Driver with an Arduino board, you can check my previous Instructable, it shows step by step how to use it.

For this we gonna need:

- Arduino Board (here I'm using UNO)

- 1k Potentiometer

- L298n Motor driver

- DC motor

- Jump wires, breadboard if you want, and something to power the module (here I'll use 9v battery).

Step 1: Wiring

So to not make it long, this is the wiring I'm using:

Potentiometer : (from left to right) GND (A0) 5v

L298n: IN1 IN2 ENA with respectively D8,D9 and D10 From Arduino and the DC motor is in Out1 and Out2

The driver is powerd by 9v battery wired with +12v and GND ( don't forget to ground the Arduino too)

And don't forget if you're using another wiring that the ENA here wired with D10 should always be wired with a pin that can deliver PWM signal

Step 2: Code

Here I'll leave you a written code or a .ino code.

I've added some comments so you can easily know what we are doing.

Hope you like it, and find it simplified to use in your own projects.


//This code is to control the speed of a DC motor by a potentiometer using l298n driver
//We read the value from the analog input, calibrate it then inject to the module //Refer to Surtrtech youtube channel for more information
int in1 = 8; //Declaring where our module is wired
int in2 = 9;
int ConA = 10;// Don't forget this is a PWM DI/DO
int speed1;
void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);  
  pinMode(10, OUTPUT);
void TurnMotorA(){ //We create a function which control the direction and speed
  digitalWrite(in1, LOW); //Switch between this HIGH and LOW to change direction
  digitalWrite(in2, HIGH);
  speed1 = analogRead(A0);
  speed1 = speed1*0.2492668622; //We read thea analog value from the potentiometer calibrate it
  analogWrite(ConA,speed1);// Then inject it to our motor
void loop() {
TurnMotorA(); //one function that keeps looping you can add another one with different direction or stop

1 Person Made This Project!


  • "Can't Touch This" Family Contest

    "Can't Touch This" Family Contest
  • CNC Contest 2020

    CNC Contest 2020
  • Robots Contest

    Robots Contest

2 Discussions


1 year ago

AYassineLebouiha I have a motor driver (MD10-POT) is able to control the speed and direction of your DC motor without using a microcontroller or writing a single line of programming code. Very easy installation. No need wiring so much. The product link below :

soBIJaFB-dI0wHRounH0C-Q.pngMD10-POT potentiometer switch control motor driver-800x800.jpg