Pages: 1 [2]   Go Down
Author Topic: How to control DC motor forward and reverse with one potentiometer  (Read 7761 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 340
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3772
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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...
}
« Last Edit: December 04, 2012, 10:00:06 am by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26497
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And two for current sensing?

Mark
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9696
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 340
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: December 04, 2012, 09:04:42 pm by David82 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 340
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9696
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 340
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);

}


« Last Edit: December 06, 2012, 03:16:05 am by jabbado » Logged

Pages: 1 [2]   Go Up
Jump to: