Back to Basic Projects

🔄 DC Motor Speed Controller

Control a DC motor from dead-stop to full speed using a potentiometer and PWM — the foundation of all motor drives.

📋 Overview

DC motors are everywhere — in fans, wheels, pumps, and drills. This project teaches you to control their speed using Pulse Width Modulation (PWM) and an L298N motor driver to safely handle higher currents.

Technical Insight: The L298N dual H-bridge driver accepts PWM signals from Arduino and controls motor voltage using power transistors rated at 2A peak. By varying the duty cycle of the PWM from 0% (stopped) to 100% (full speed), the average voltage to the motor changes proportionally, allowing smooth, continuous speed control.

In simple terms: The potentiometer knob is your 'throttle.' The Arduino reads it (0–1023), scales it to a PWM value (0–255), and sends that to the L298N, which drives the motor at exactly that speed fraction.

What you'll learn: L298N motor driver wiring, analogRead() + analogWrite(), motor speed-to-PWM mapping, direction control with H-bridge logic, and flyback protection.

Estimated time: 40-55 minutes. Difficulty: ⭐⭐ Easy.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
L298N Motor Driver2A, 5–35V1Dual H-Bridge module
DC Motor6–12V, any small DC motor1Hobby motor, fan, or pump
Potentiometer10kΩ Linear1Speed control knob
Power Supply9V battery or 12V adapter1For L298N motor supply
Breadboard + WiresFull-size1

🗺️ Component Pin Mapping

DC Motor Speed Controller Component Pin Mapping Infographic

📖 Step-by-Step Tutorial

1

Wire the L298N

L298N: ENA → Arduino pin 9 (PWM), IN1 → pin 7, IN2 → pin 8. Motor terminals to OUT1 and OUT2. Connect 12V supply to VS and GND to GND (share GND with Arduino).
2

Wire the Potentiometer

Left pin → 5V, Right pin → GND, Center (wiper) → Arduino pin A0.
3

Set Direction

IN1=HIGH, IN2=LOW for one direction. Reverse to go the other way. Upload and test.
4

Adjust Speed

Turn the potentiometer knob. Watch the motor go from full stop to maximum speed smoothly.
5

Add Reverse

Optional: add a push button to toggle IN1/IN2 logic and instantly reverse direction.
💡
Never connect the motor directly to Arduino pins — they can only supply 40mA, far less than even a small motor needs. The L298N acts as a power amplifier, taking tiny PWM signals and driving motors with full battery power.

💻 Arduino Code

dc_motor_speed_control.ino
INO
// DC Motor Speed Controller — Volt X
// Potentiometer on A0 controls speed via L298N ENA pin

const int ENA = 9;  // PWM speed control (must be ~ pin)
const int IN1 = 7;  // Direction pin 1
const int IN2 = 8;  // Direction pin 2
const int POT = A0; // Potentiometer

void setup() {
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  // Set forward direction
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  Serial.begin(9600);
}

void loop() {
  int potVal = analogRead(POT);            // Read 0-1023
  int speed  = map(potVal, 0, 1023, 0, 255); // Scale to 0-255
  analogWrite(ENA, speed);                 // Set motor speed
  
  Serial.print("Pot: "); Serial.print(potVal);
  Serial.print("  Speed PWM: "); Serial.println(speed);

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
...

Loading reviews...