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
@Sloth do you mean. No microcontroller. Just the pot?
100 years ago they controlled motors that way 😉

Just pot wired to the hw 130 motor shield v1. And the shield is ona aurdiono uno.
@Sloth so is the pot conected to the arduino. And your reading it by code?@Sloth
Yes the middle pin is connected to A0 and 2 outside 5v and gnd
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
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)"
Did it go smoothly?
It went with a full sweep of the pot?
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?
Yes.
Ok now share your code
#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
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
try this
I see what you did there
Thx cant try yet but I'll get back to you when I tried it!