A
Arduino•2mo 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?
5 Replies
AnonEngineering
AnonEngineering•2mo ago
100 years ago they controlled motors that way 😉
No description
Sloth
SlothOP•2mo ago
Just pot wired to the hw 130 motor shield v1. And the shield is ona aurdiono uno. Yes the middle pin is connected to A0 and 2 outside 5v and gnd 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)" 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? #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•2mo 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);
}
Sloth
SlothOP•2mo ago
Thx cant try yet but I'll get back to you when I tried it!
wtf
wtf•2mo ago
I see I see

Did you find this page helpful?