Go Down

Topic: Control speed of DC Motor with potentiometer (Read 5 times) previous topic - next topic

elp

Mar 29, 2011, 12:38 am Last Edit: Mar 29, 2011, 11:40 pm by elp Reason: 1
hi all,
it's possible to control the speed of a dc motor with a potentiometer?
I started reading this article: http://homepage.mac.com/joester5/art/digitalart2/dcmotor.html

I've attached all successfully, but i CAN'T ABLE TO set speed!

If i turn pot, dc motor run or stop, but at the same speed (fast).



Any idea to fix this issue?

This is the used code:
Code: [Select]
int sensorValue = 0;
int outputValue = 0;
int transistorPin = 2;

void setup() {
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  sensorValue = analogRead(analogInPin)/4;           
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(transistorPin, sensorValue);
}


tks.
--
elp

MarkT

You seem to have a freewheel diode in the wrong place - needs to be across the motor.
[ I won't respond to messages, use the forum please ]

retrolefty




Quote
int sensorValue = 0;
int outputValue = 0;
int transistorPin = 2;
int analogInPin = ?;      // you must state which analog pin you are using
  void setup() {
    pinMode(transistorPin, OUTPUT);
   }

void loop() {
  sensorValue = analogRead(analogInPin);  // sensorValue = analogRead(analogInPin)/4;
                                                                // the map function will perform the /4, don't do it twice
           
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(transistorPin, sensorValue);
}

AWOL

#3
Mar 30, 2011, 09:11 am Last Edit: Mar 30, 2011, 09:13 am by AWOL Reason: 1
Code: [Select]
sensorValue = analogRead(analogInPin)/4;            
 outputValue = map(sensorValue, 0, 1023, 0, 255);


Why bother with the map?
And yes, why haven't you shown the code you're using?

Maybe your speed problem would be solved if you used a PWM pin for the output.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

elp

I get pot values.... from 0 to 1023.
Sorry for copy/paste code, analogInPin was forgotted.
What kind of value i need to pass to pot?

I'm very newbie, about coding, about electronics and about english!  XD

Quote

Maybe your speed problem would be solved if you used a PWM pin for the output.

What is a PWM pin?

Quote

You seem to have a freewheel diode in the wrong place - needs to be across the motor.

What is diode correct place? Have you a detailed example for a beginner?

thanks for helps!
--
elp

Go Up