Potentiometer for DC Motor Speed Control
Arduino DC Motor Speed Control Using Potentiometer
Arduino DC Motor Speed Control Using Potentiometer is a simple motor-control setup using an Arduino, motor driver and potentiometer.
The potentiometer is connected to the Arduino's A0 analog input. The Arduino reads the potentiometer value and maps it to a 0–255 PWM range.
The PWM value is applied to the motor driver's enable pin to control the motor speed.
Potentiometer → Arduino A0 → PWM → Motor Driver → DC Motor
Connections
| Device | Pin | Arduino | Function |
|---|---|---|---|
| Potentiometer | VCC | 5V | Power |
| Potentiometer | GND | GND | Ground |
| Potentiometer | Wiper / Output | A0 | Analog input |
| Motor Driver | A1 | D5 | Motor direction control |
| Motor Driver | A2 | D6 | Motor direction control |
| Motor Driver | Enable A | D9 | Motor PWM speed control |

Potentiometer
The potentiometer provides an analog voltage to the Arduino A0 pin.
The Arduino reads the potentiometer using its analog-to-digital converter (ADC).
The analog reading ranges from:
0 to 1023
The program maps this value to the PWM range:
0 to 255
The mapping used by the program is:
speed = map(potVal, 0, 1023, 0, 255)
Motor Direction
The motor direction is fixed using the following control signals:
A1 = HIGH
A2 = LOW
The motor therefore rotates in one direction.
The potentiometer controls the motor speed and does not change the motor direction.
PWM Speed Control
The Arduino generates a PWM signal on D9.
The PWM value is calculated from the potentiometer reading:
PWM = 0 to 255
The calculated PWM value is applied to the motor driver's Enable A pin.
Working
The Arduino continuously performs the following operations:
- Reads the potentiometer value from A0.
- Stores the analog reading in potVal.
- Maps the value from 0–1023 to 0–255.
- Sets the motor direction using A1 = HIGH and A2 = LOW.
- Applies the PWM value to Enable A.
- Displays the potentiometer value and PWM value on the Serial Monitor.
- Waits for 200 ms before repeating the process.
The overall operation is:
Potentiometer → Analog Reading → PWM Mapping → Motor Speed
Serial Monitor
The Serial Monitor is set to 9600 baud.
The program displays the potentiometer value and corresponding PWM speed value.
Example:
Potentiometer Value: 0 | Motor Speed (PWM): 0 Potentiometer Value: 512 | Motor Speed (PWM): 127 Potentiometer Value: 1023 | Motor Speed (PWM): 255
Arduino Code
// © 2026, Cognifront. Member of The IoT Kits Family.
// Controlling DC Motor with potentiometer and display output on serial monitor
// Define analog input pin connected to the potentiometer
const int Pot = A0;
// Define motor control pins
const int motorA1 = 5; // Motor driver input A1 (direction control)
const int motorA2 = 6; // Motor driver input A2 (direction control)
const int enableA = 9; // Motor driver enable pin (PWM speed control)
void setup() {
// Start Serial communication for debugging and monitoring
Serial.begin(9600);
// Configure potentiometer pin as input (optional for analogRead)
pinMode(Pot, INPUT);
// Configure motor control pins as outputs
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(enableA, OUTPUT);
}
void loop() {
// Read potentiometer value (range 0–1023 from ADC)
int potVal = analogRead(Pot);
// Map potentiometer range to motor speed range (0–255 for PWM)
int speed = map(potVal, 0, 1023, 0, 255);
// Set motor direction: A1 HIGH, A2 LOW → rotate in one direction
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
// Control motor speed using PWM signal on enable pin
analogWrite(enableA, speed);
// Display potentiometer value and motor speed on Serial Monitor
Serial.print("Potentiometer Value: ");
Serial.print(potVal);
Serial.print(" | Motor Speed (PWM): ");
Serial.println(speed);
// Small delay for readability in Serial Monitor
delay(200);
}
Observation
The Serial Monitor is set to 9600 baud.
As the potentiometer is rotated, the Potentiometer Value changes according to the position of the potentiometer.
The corresponding Motor Speed (PWM) value changes between 0 and 255.
The motor rotates in the direction specified by:
A1 = HIGH
A2 = LOW
Result
The Arduino successfully reads the potentiometer value, maps it to a PWM value, and controls the speed of the DC motor through the motor driver's enable pin.
The motor direction remains fixed while the potentiometer controls the motor speed.