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.

CONNECTION OVERVIEW
// 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);
}