DC Motor Speed Control Using Arduino Nano Deshbot and Potentiometer

by devkrishnavhora in Circuits > Arduino

138 Views, 0 Favorites, 0 Comments

DC Motor Speed Control Using Arduino Nano Deshbot and Potentiometer

In this project, we control the speed of a 12V DC motor using an Arduino Nano, a DESHBOT Shield with L293D motor driver, and a potentiometer.

The potentiometer allows us to control the motor speed smoothly. By rotating the potentiometer, the PWM value sent to the motor driver changes, which changes the speed of the motor.

Supplies

Arduino Nano

DESHBOT Shield

L293D motor driver

12V DC motor

10K potentiometer

12V motor power supply

Jumper wires

Connections

Potentiometer

  1. Middle pin → A0
  2. One outer pin → 5V
  3. Other outer pin → GND

Motor

  1. Motor connection → D8 and D9
  2. D8 is used as the LOW/GND side
  3. D9 is used for PWM speed control


Working

The Arduino Nano reads the potentiometer using its A0 analog input.

The analog input gives a value between:

0 → 1023

The Arduino converts this value into a PWM value between:

0 → 255

This PWM signal is applied to the motor driver. As the potentiometer is rotated, the PWM value changes, allowing the motor speed to be controlled.

Control

Potentiometer minimum → Motor stopped/very slow

Potentiometer middle → Medium speed

Potentiometer maximum → Full speed

Code Explanation

Sure — here is the step-by-step explanation of the potentiometer direction + speed code.

1. Define the pins


const int POT_PIN = A1;

const int MOTOR_A = 8;
const int MOTOR_B = 9;

  1. Potentiometer is connected to A1.
  2. Motor driver uses D8 and D9.
  3. A1 reads the potentiometer position.

2. Set the motor pins


void setup() {
pinMode(MOTOR_A, OUTPUT);
pinMode(MOTOR_B, OUTPUT);

digitalWrite(MOTOR_A, LOW);
digitalWrite(MOTOR_B, LOW);
}

Here we tell the Nano that D8 and D9 are outputs.

Both pins start LOW, so the motor is stopped.

3. Read the potentiometer


int potValue = analogRead(POT_PIN);

The Nano reads A1.

The value is:

0 ---------------- 512 ---------------- 1023
LEFT CENTER RIGHT

4. Center position = STOP


if (potValue >= 480 && potValue <= 543) {

digitalWrite(MOTOR_A, LOW);
digitalWrite(MOTOR_B, LOW);
}

When the potentiometer is around the center, both motor pins are LOW.

So the motor stops.

The range 480–543 is called the dead zone. It prevents tiny potentiometer fluctuations from making the motor move.

5. Potentiometer left = motor left


else if (potValue < 480) {

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

motorSpeed = constrain(motorSpeed, 0, 255);

analogWrite(MOTOR_A, motorSpeed);
digitalWrite(MOTOR_B, LOW);
}

When you turn the potentiometer to the left:

  1. Near center → slow
  2. Further left → faster
  3. Fully left → maximum speed

map() converts the potentiometer position into a PWM value from 0 to 255.

6. Potentiometer right = motor right


else {

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

motorSpeed = constrain(motorSpeed, 0, 255);

digitalWrite(MOTOR_A, LOW);
analogWrite(MOTOR_B, motorSpeed);
}

When you turn the potentiometer to the right:

  1. Near center → slow
  2. Further right → faster
  3. Fully right → maximum speed

Now D9 gets PWM while D8 stays LOW, making the motor run in the opposite direction.

7. Final behavior

LEFT CENTER RIGHT

FAST ◀──────── SLOW ◀──────── STOP ──────── SLOW ────────▶ FAST
D8 PWM D8 LOW/D9 LOW D9 PWM

0 ~512 1023
A1 A1

So the A1 potentiometer works like a joystick: left = motor left, center = stop, right = motor right, with speed increasing the farther you move from center.

Conclusion

This project demonstrates how an Arduino Nano, potentiometer, and L293D motor driver can be used to control both the direction and speed of a DC motor. The potentiometer acts like a joystick: when turned to the left, the motor moves left; when turned to the right, the motor moves right; and when kept in the center, the motor stops. The farther the potentiometer is turned from the center, the faster the motor runs. This project helps in understanding analog input, PWM, motor control, and direction control using Arduino.