To test if code can make the DC motor move any faster, connect the power supply + and - directly to each motor + and -... that will be the maximum speed.
A gear "ratio" might be given on the motor case. A larger ratio gives a faster speed, but less torque.
Your code does not "increase speed" in both directions (on both sides of "512")... using the map() function from post #3 is necessary to do this. I made some adjustments to the code, now you can see potentiometer and motor speeds...
sketch.ino for wokwi.com
// https://forum.arduino.cc/t/i-need-help-making-my-motors-faster/1319694/
// Define pins
const int potPin = A0; // Pin for potentiometer
const int motorPin1 = 3; // Motor driver input 1
const int motorPin2 = 4; // Motor driver input 2
const int enablePin = 5; // Motor driver enable pin
int oldPotValue, oldMotorSpeed;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int potValue = analogRead(potPin); // Read value from potentiometer
// Map the potentiometer value to motor speed
int motorSpeed = map(potValue, 0, 1023, 0, 255);
// show only changes
if (oldPotValue != potValue || oldMotorSpeed != motorSpeed) {
oldPotValue = potValue;
oldMotorSpeed = motorSpeed;
Serial.print("P|");
spacepad(potValue);
Serial.print(potValue); // Print pot value for debugging
for (int i = 0; i < potValue / 24; i++)
Serial.print(" ");
Serial.print(" ");
Serial.print("P"); // Print pot value for debugging
Serial.print(" ");
Serial.print(motorSpeed); // Print pot value for debugging
Serial.print(" ");
Serial.println(255 - motorSpeed); // Print pot value for debugging
}
if (potValue < 512) {
// Rotate motor in one direction
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin, motorSpeed);
} else {
// Rotate motor in the opposite direction
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
analogWrite(enablePin, 255 - motorSpeed); // Reverse speed
}
// delay(100); // Small delay for stability
}
void spacepad(int value) {
if (value < 1000) Serial.print(" ");
if (value < 100) Serial.print(" ");
if (value < 10) Serial.print(" ");
}
diagram.json for wokwi.com
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": -106.8,
"left": 131.4,
"rotate": 90,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": -78,
"left": 131.4,
"rotate": 90,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -49.2,
"left": 131.4,
"rotate": 90,
"attrs": { "color": "red" }
},
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -10.9, "left": 172.6, "attrs": {} }
],
"connections": [
[ "nano:GND.2", "led3:C", "black", [ "v0" ] ],
[ "nano:GND.2", "led2:C", "black", [ "v0" ] ],
[ "nano:GND.2", "led1:C", "black", [ "v0" ] ],
[ "nano:3", "led3:A", "green", [ "v0" ] ],
[ "nano:4", "led2:A", "green", [ "v0" ] ],
[ "nano:5", "led1:A", "green", [ "v0" ] ],
[ "pot1:GND", "nano:GND.1", "black", [ "v19.2", "h-57.1" ] ],
[ "pot1:SIG", "nano:A0", "green", [ "v28.8", "h-125.2" ] ],
[ "pot1:VCC", "nano:5V", "red", [ "v38.4", "h-87.2" ] ]
],
"dependencies": {}
}