How can i control speed my dc motor

Hi there,

I am using g2 24v21 motor driver for drive my 200w 24 v maxon motor. I am using arduino that connection 10 k Potentiometer and then i get to pot analog signal, it turned pwm signal on the arduino after that when i tried conrtrol pot , my motor turning constat speed, moreover when i turning pot as slowly motor is begin turn after pass 100 analog value. i want to control my motor speed with pot. For now i dont need know speed value, only i want to do that change speed.

This is my arduino code:

const int pot_pin = A0;
const int motor = 8;
const int dir = 2;

int durum = 0;
int cikti = 0;
void setup() {
  pinMode(motor, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(pot_pin, INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(dir,HIGH);
  durum = analogRead(pot_pin);  
  Serial.println(durum);
  cikti = map ( durum , 0 ,1023 , 0 , 255 );

  analogWrite(motor , cikti);

}

Video link:

Hello.

It looks like you are currently using pin 8 for the motor speed output, and that pin probably is not capable of generating a PWM output, which would explain the behavior you are observing. Can you make sure you are using a valid PWM output pin for your Arduino (e.g. pin 9 for an Uno or Leonardo) and try again?

-Patrick

1 Like