A
Arduino•21h ago
Sloth

Cant control speed of dc motor with potentiometer

I am trying to control the speed of my dc motor with my potentiometer. But when I turn the potentiometer to max it works but when I turn it a little bit the dc motor turn off. Any idea why?
14 Replies
MaderDash
MaderDash•21h ago
@Sloth do you mean. No microcontroller. Just the pot?
AnonEngineering
AnonEngineering•21h ago
100 years ago they controlled motors that way 😉
No description
Sloth
SlothOP•21h ago
Just pot wired to the hw 130 motor shield v1. And the shield is ona aurdiono uno.
MaderDash
MaderDash•21h ago
@Sloth so is the pot conected to the arduino. And your reading it by code?@Sloth
Sloth
SlothOP•21h ago
Yes the middle pin is connected to A0 and 2 outside 5v and gnd
MaderDash
MaderDash•20h ago
Ok so. Make a serial print in code. And print out the value the pot is creating. @Sloth let me know what you get when turning the pot
Sloth
SlothOP•20h ago
I did and the pot value is from 1023 to 0 but when I used the potvalue to set motor speed: this is code to set motor speed "motor.setspeed(potvalue)"
MaderDash
MaderDash•20h ago
Did it go smoothly? It went with a full sweep of the pot?
Sloth
SlothOP•19h ago
In the graphic if i turned it to max it was not the smoothest but also not very static so in-between. And when it reached max it would be a flat line. Is this wat you mean?
MaderDash
MaderDash•16h ago
Yes. Ok now share your code
Sloth
SlothOP•8h ago
#include <AFMotor.h> AF_DCMotor motor(1); int potpin = A0; int potval = 0; void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Motor test!"); // turn on motor motor.setSpeed(0);
motor.run(RELEASE); } void loop() {
potval= analogRead(potpin);
Serial.print(potval); Serial.print("\n"); motor.run(FORWARD); motor.setSpeed((potval/1023)*255);

delay(100); } Here you go
AnonEngineering
AnonEngineering•1h ago
try this
c++
/*
Arduino | coding-help
Sloth 9/8/25 — 2:34 AM
*/

int potpin = A0;

void setup() {
Serial.begin(9600);
Serial.println("Get pot value test!\n");
}

void loop() {
int potval = analogRead(potpin);
int setSpeed = (potval / 1023) * 255;
int mappedSpeed = map(potval, 0, 1023, 0, 255);
Serial.print("potval: ");
Serial.println(potval);
Serial.print("setSpeed: ");
Serial.println(setSpeed);
Serial.print("mappedSpeed: ");
Serial.println(mappedSpeed);
Serial.print("\n");
delay(1000);
}
c++
/*
Arduino | coding-help
Sloth 9/8/25 — 2:34 AM
*/

int potpin = A0;

void setup() {
Serial.begin(9600);
Serial.println("Get pot value test!\n");
}

void loop() {
int potval = analogRead(potpin);
int setSpeed = (potval / 1023) * 255;
int mappedSpeed = map(potval, 0, 1023, 0, 255);
Serial.print("potval: ");
Serial.println(potval);
Serial.print("setSpeed: ");
Serial.println(setSpeed);
Serial.print("mappedSpeed: ");
Serial.println(mappedSpeed);
Serial.print("\n");
delay(1000);
}
nis
nis•1h ago
I see what you did there
Sloth
SlothOP•1h ago
Thx cant try yet but I'll get back to you when I tried it!

Did you find this page helpful?