Go Down

Topic: How to control DC motor forward and reverse with one potentiometer (Read 8569 times) previous topic - next topic

David82


For a motor (with h-bridge/motor shield of course!). You read the pot with ADC and then values above (say ) 700 are forward, values below 300 are backward and values in between are stop. But you still need one pot per motor.

Mark
That looks to be correct. Do you have a link to a recommended h-bridge/motor shield? Remember, I'm simply using a analog, 2-axis joystick (with 2 pots total) to control a pair open-loop motors for use in a pan tilt system. For example, if the joystick is half-way tilted to the right, the pan/tilt system will go half-speed in that direction. I've done this plenty of times with servos but now the components need to be basic, dc motors.

HazardsMind

#16
Dec 04, 2012, 03:46 pm Last Edit: Dec 04, 2012, 04:00 pm by HazardsMind Reason: 1
Quote
I've done this plenty of times with servos but now the components need to be basic, dc motors.


Then my solution is the one you want to use.

It gets data from the 2 pots and tells the motors how to move.If you dont like my second way, then just repeat my first way for both motors.

This controls the forward and backwards movement of ONE motor, repeat for second motor.
Code: [Select]
// say the lowest is 350 and the highest is 650, the difference is 300
// so divide 300 by 2, you get 150.
// then 350 + 150= 500 (center)
//offset, you decide how much dead zone you want, for the center.
// +-10 should be enough.
If( POT1< 490) { // offset(10) - center(500)
...go forward...
}
Else if (POT1 > 510) {
... Go backwards...
}
Else {
... Full stop...
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

holmes4

Which motor shield depends on how much current the motors would require. Take a look and the Arduino one in the hardware section of the main site as a starter. This runs two motors each with speed and direction (4 digital pins in all).

As for the pots one end to earth one to the 5v and the center wiper to the analog pin.

Mark

AWOL

Quote
This runs two motors each with speed and direction (4 digital pins in all).

You may also want to add another couple of pins for the brakes.
"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.


zoomkat

The quick fix would be to get two of the below (one for each joystick pot) motor controllers, and connect the joystick pots in place of the pots on the controllers.

http://www.electronickits.com/kit/complete/motor/k166.htm
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

David82

#21
Dec 05, 2012, 02:57 am Last Edit: Dec 05, 2012, 03:04 am by David82 Reason: 1

The quick fix would be to get two of the below (one for each joystick pot) motor controllers, and connect the joystick pots in place of the pots on the controllers.

http://www.electronickits.com/kit/complete/motor/k166.htm


That looks to be perfect. So to summarize, you would use one of these:

and wire each one to one of these in place of the pots that they come with:

is that correct?

If so, where else can I get these? They are expensive http://www.electronickits.com/kit/complete/motor/k166.htm
Also, don't I also have to make sure the pots on the joystick are the same resistance as the pots that were originally on the speed controller?

jabbado


Also, don't I also have to make sure the pots on the joystick are the same resistance as the pots that were originally on the speed controller?

It's a 100k pot. Looking at the schematics it's not simply connected to V+ and ground. There is a 100k resistor on the high side and a 10k connecting it to ground. So yeah it won't act the same unless the joystick pots are 100k. Or you change the resistors to compensate.

David82

Good point. Now, knowing that, what would I have to change those two resistors to to be able to use the 5k pots that are on the joystick instead?

zoomkat

Or maybe replace the pots in the joystick.

http://www.ebay.com/itm/10pcs-100K-Ohm-B100K-Knurled-Shaft-Linear-Rotary-Taper-Potentiometer-/260985205438?pt=LH_DefaultDomain_0&hash=item3cc3ee32be
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

jabbado

Replacing the pots might be a better idea. But if you want to change the resistors you just need to reduce them by the same factor. ie, your 5k pots are 1/20 of the original pot's value. So the top 100k resistor will become 5k, and the bottom 10k will become 500R. That's going to increase the current through that leg but it's still only 1.1mA or so.

David82

Yep. The pots that came with the motor driver will either fit in the joystick or they won't. If they don't, then I'll have to wither find 100k pots that fit correctly in the joystick or replace the resistors and use the 5k pots. I'll report back after the parts get here.

nanohex

Quote
Do you have a link to a recommended h-bridge/motor shield?


Yup - the L298N motor driver is a good controller that can supply up to 2A per motor (2 motors max). A motor controller board for these are dirt cheap off ebay.

http://www.ebay.com/itm/Dual-H-Bridge-DC-Stepper-Motor-Drive-Controller-Board-Module-L298N-for-arduino-/251080674810?pt=LH_DefaultDomain_0&hash=item3a75930dfa

They're also really easy to control:
http://www.youtube.com/watch?v=1Q0ZwpycbzY

jabbado

#28
Dec 06, 2012, 08:47 am Last Edit: Dec 06, 2012, 09:16 am by jabbado Reason: 1
If you do decide to make this with Arduino and H-Bridge shields, I wrote this code the other day as a learning experience (I'm new to Arduino) until I realized you wanted a non-MCU solution. Don't have an H-Bridge to test but seems to give proportional bi-directional control. This is just for the "horizontal" motor.

Code: [Select]
int deadZone = 50; // joystick deadzone rangec
int maxPWMValue =  255; // maximum PWM value. 255 for built-in PWM
int horizPotPin = A0; // Analog pin for horizontal pot sense

int horizPWMPin = 9; // Horiz motor speed control connected to this pinr
int horizDirPin = 2; // directional control connected here. HIGH = forward, LOW = reverse

void setup()
{
pinMode(horizPWMPin, OUTPUT);
pinMode(horizDirPin, OUTPUT);

// for debugging
Serial.begin(38400);
}


void loop()
{
int horizPWM = 0; // holds the pwm output for 'horizontal' motor
boolean  forwardDir = true; // direction for 'horizontal' motor. true = forward, false = reverse

// read horizontal pot value
int horizPot = analogRead(horizPotPin);

// map the analog value of 0..1023 to -255..+255
// If the direction and speed go in the wrong direction compared to joystick movement,
// just switch the sign of the last two parameters
int h = map(horizPot, 0, 1023, -maxPWMValue, maxPWMValue);

// check if joy in reverse position
if (h < 0)
{
forwardDir = false;
h *= -1;
}

// only set final PWM output if joy is outside of deadzone range
if (h > deadZone)
horizPWM = h;


// set pwm and direction
digitalWrite(horizDirPin, forwardDir);
analogWrite(horizPWMPin, horizPWM);


//debug crap
Serial.print(horizPWM );
Serial.print(", ");
Serial.println(forwardDir);
delay(50);

}




Go Up