Jump to content

Potentiometer for DC Motor Speed Control: Difference between revisions

From cognifront
CogWikiEditor (talk | contribs)
Created page with "===Arduino DC Motor Speed Control Using Potentiometer=== {| class="wikitable" style="float:right; margin-left:20px; width:300px;" ! colspan="2" style="font-size:120%;" | DC Motor Speed Control |- ! Controller | Arduino | | ------------------- | | ! Motor Driver | | Motor Driver | | - | | ! Input | | Potentiometer | | - | | ! Potentiometer Pin | | A0 | | - |..."
 
CogWikiEditor (talk | contribs)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Arduino DC Motor Speed Control Using Potentiometer===
===Arduino DC Motor Speed Control Using Potentiometer===
{| class="wikitable" style="float:right; margin-left:20px; width:300px;"
! colspan="2" style="font-size:120%;" | DC Motor Speed Control
|-
! Controller
| Arduino            |
| ------------------- |
| ! Motor Driver      |
| Motor Driver        |
| -                  |
| ! Input            |
| Potentiometer      |
| -                  |
| ! Potentiometer Pin |
| A0                  |
| -                  |
| ! Motor Control    |
| A1, A2              |
| -                  |
| ! Enable Pin        |
| PWM                |
| -                  |
| ! Output            |
| Motor Speed        |
| }                  |


'''Arduino DC Motor Speed Control Using Potentiometer''' is a simple motor-control setup using an Arduino, motor driver and 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 '''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.
The PWM value is applied to the motor driver's enable pin to control the motor speed.
Line 43: Line 17:
! Pin
! Pin
! Arduino
! Arduino
 
! Function
| ! Function             |
|-
| ----------------------- |
| Potentiometer
| Potentiometer           |
| VCC
| Wiper / Output          |
| 5V
| A0                      |
| Power
| Analog input            |
|-
| -                       |
| Potentiometer
| Potentiometer           |
| GND
| VCC                    |
| GND
| 5V                      |
| Ground
| Power                  |
|-
| -                       |
| Potentiometer
| Potentiometer           |
| Wiper / Output
| GND                    |
| A0
| GND                    |
| Analog input
| Ground                  |
|-
| -                       |
| Motor Driver
| Motor Driver           |
| A1
| A1                     |
| D5
| D5                     |
| Motor direction control
| Motor direction control |
|-
| -                       |
| Motor Driver
| Motor Driver           |
| A2
| A2                     |
| D6
| D6                     |
| Motor direction control
| Motor direction control |
|-
| -                       |
| Motor Driver
| Motor Driver           |
| Enable A
| Enable A               |
| D9
| D9                     |
| Motor PWM speed control
| Motor PWM speed control |
|}
| }                      |
[[File:Dc-motor-pot-arduino.jpg|thumb|center|700px|Arduino motor speed control using potentiometer]]


== Potentiometer ==
== Potentiometer ==
Line 81: Line 55:
The potentiometer provides an analog voltage to the Arduino '''A0''' pin.
The potentiometer provides an analog voltage to the Arduino '''A0''' pin.


The Arduino's ADC reads a value between:
The Arduino reads the potentiometer using its analog-to-digital converter (ADC).
 
The analog reading ranges from:


<center>
<center>
Line 87: Line 63:
</center>
</center>


The program converts this value into a PWM value between:
The program maps this value to the PWM range:


<center>
<center>
Line 98: Line 74:
<code>speed = map(potVal, 0, 1023, 0, 255)</code>
<code>speed = map(potVal, 0, 1023, 0, 255)</code>
</center>
</center>
Therefore, turning the potentiometer changes the PWM value supplied to the motor driver.


== Motor Direction ==
== Motor Direction ==


The motor direction is fixed by the following logic:
The motor direction is fixed using the following control signals:


<center>
<center>
Line 110: Line 84:
</center>
</center>


This causes the motor to rotate in one direction.
The motor therefore rotates in one direction.


The direction does not change when the potentiometer is rotated. The potentiometer is used only to control the motor speed.
The potentiometer controls the motor speed and does not change the motor direction.


== PWM Speed Control ==
== PWM Speed Control ==
Line 118: Line 92:
The Arduino generates a PWM signal on '''D9'''.
The Arduino generates a PWM signal on '''D9'''.


The PWM value is determined from the potentiometer reading:
The PWM value is calculated from the potentiometer reading:


<center>
<center>
'''PWM = 0–255'''
'''PWM = 0 to 255'''
</center>
</center>


A low potentiometer value produces a low PWM value, while a high potentiometer value produces a high PWM value.
The calculated PWM value is applied to the motor driver's '''Enable A''' pin.
 
The PWM signal is applied to the motor driver's '''Enable A''' pin.


== Working ==
== Working ==


The Arduino continuously reads the potentiometer and controls the motor according to the following sequence:
The Arduino continuously performs the following operations:
 
# The potentiometer value is read using '''A0'''.
 
# The Arduino obtains an ADC value between '''0 and 1023'''.


# The value is mapped from '''0–1023''' to '''0–255'''.
# 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 motor direction is set using '''A1 = HIGH''' and '''A2 = LOW'''.
The overall operation is:
 
# The mapped value is applied as PWM to the motor driver's '''Enable A''' pin.
 
# The potentiometer value and PWM speed value are displayed on the Serial Monitor.
 
# The program waits for '''200 ms''' before repeating the process.
 
The control relationship is:


<center>
<center>
Line 152: Line 118:
</center>
</center>


== Serial Monitor Output ==
== Serial Monitor ==


The Serial Monitor is set to '''9600 baud'''.
The Serial Monitor is set to '''9600 baud'''.


The program displays both the potentiometer ADC value and the corresponding PWM value.
The program displays the potentiometer value and corresponding PWM speed value.


Example output:
Example:


<pre>
<pre>
Line 165: Line 131:
Potentiometer Value: 1023  |  Motor Speed (PWM): 255
Potentiometer Value: 1023  |  Motor Speed (PWM): 255
</pre>
</pre>
The exact values may vary depending on the potentiometer position.


== Arduino Code ==
== Arduino Code ==
Line 176: Line 140:


// Define analog input pin connected to the potentiometer
// Define analog input pin connected to the potentiometer
 
const int Pot = A0;
const int Pot = A0);


// Define motor control pins
// Define motor control pins
 
const int motorA1 = 5;  // Motor driver input A1 (direction control)
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)
const int motorA2 = 6);  // Motor driver input A2 (direction control)
 
const int enableA = 9);  // Motor driver enable pin (PWM speed control)


void setup() {
void setup() {
   // Start Serial communication for debugging and monitoring
   // Start Serial communication for debugging and monitoring
   Serial.begin(9600);
   Serial.begin(9600);


   // Configure potentiometer pin as input (optional for analogRead)
   // Configure potentiometer pin as input (optional for analogRead)
   pinMode(Pot, INPUT);
   pinMode(Pot, INPUT);


   // Configure motor control pins as outputs
   // Configure motor control pins as outputs
   pinMode(motorA1, OUTPUT);
   pinMode(motorA1, OUTPUT);
   pinMode(motorA2, OUTPUT);
   pinMode(motorA2, OUTPUT);
   pinMode(enableA, OUTPUT);
   pinMode(enableA, OUTPUT);
}
}


void loop() {
void loop() {
   // Read potentiometer value (range 0–1023 from ADC)
   // Read potentiometer value (range 0–1023 from ADC)
   int potVal = analogRead(Pot);           
   int potVal = analogRead(Pot);           
 
 
   // Map potentiometer range to motor speed range (0–255 for PWM)
   // Map potentiometer range to motor speed range (0–255 for PWM)
   int speed = map(potVal, 0, 1023, 0, 255);   
   int speed = map(potVal, 0, 1023, 0, 255);   


   // Set motor direction: A1 HIGH, A2 LOW → rotate in one direction
   // Set motor direction: A1 HIGH, A2 LOW → rotate in one direction
   digitalWrite(motorA1, HIGH);
   digitalWrite(motorA1, HIGH);
   digitalWrite(motorA2, LOW);
   digitalWrite(motorA2, LOW);


   // Control motor speed using PWM signal on enable pin
   // Control motor speed using PWM signal on enable pin
   analogWrite(enableA, speed);     
   analogWrite(enableA, speed);     


   // Display potentiometer value and motor speed on Serial Monitor
   // Display potentiometer value and motor speed on Serial Monitor
   Serial.print("Potentiometer Value: ");
   Serial.print("Potentiometer Value: ");
   Serial.print(potVal);
   Serial.print(potVal);
   Serial.print("  |  Motor Speed (PWM): ");
   Serial.print("  |  Motor Speed (PWM): ");
   Serial.println(speed);
   Serial.println(speed);


   // Small delay for readability in Serial Monitor
   // Small delay for readability in Serial Monitor
 
   delay(200);        
   delay(200);          
 
}
}
</pre>
</pre>
Line 248: Line 189:
The Serial Monitor is set to '''9600 baud'''.
The Serial Monitor is set to '''9600 baud'''.


As the potentiometer is rotated, the '''Potentiometer Value''' changes from approximately '''0 to 1023'''.
As the potentiometer is rotated, the '''Potentiometer Value''' changes according to the position of the potentiometer.


The corresponding '''Motor Speed (PWM)''' value changes from approximately '''0 to 255'''.
The corresponding '''Motor Speed (PWM)''' value changes between '''0 and 255'''.


The motor rotates in the fixed direction specified by:
The motor rotates in the direction specified by:


<center>
<center>
Line 261: Line 202:
== Result ==
== Result ==


The Arduino successfully reads the potentiometer value, converts it into a PWM speed value, and controls the speed of the DC motor through the motor driver's enable pin.
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.
The motor direction remains fixed while the potentiometer controls the motor speed.

Latest revision as of 16:23, 3 September 2026

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
Arduino motor speed control using potentiometer

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:

  1. Reads the potentiometer value from A0.
  2. Stores the analog reading in potVal.
  3. Maps the value from 0–1023 to 0–255.
  4. Sets the motor direction using A1 = HIGH and A2 = LOW.
  5. Applies the PWM value to Enable A.
  6. Displays the potentiometer value and PWM value on the Serial Monitor.
  7. 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.