Pages: 1 [2]   Go Down
 Author Topic: How to control DC motor forward and reverse with one potentiometer  (Read 5392 times) 0 Members and 1 Guest are viewing this topic.
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
 « Reply #15 on: December 04, 2012, 09:17:43 am » Bigger Smaller 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
Karma: 59
Posts: 2731
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
 « Reply #16 on: December 04, 2012, 09:46:28 am » Bigger Smaller 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

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Poole, Dorset, UK
Offline
Edison Member
Karma: 23
Posts: 1787
 « Reply #17 on: December 04, 2012, 10:35:41 am » Bigger Smaller 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
Brattain Member
Karma: 225
Posts: 23636
I don't think you connected the grounds, Dave.
 « Reply #18 on: December 04, 2012, 10:38:46 am » Bigger Smaller 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
Edison Member
Karma: 23
Posts: 1787
 « Reply #19 on: December 04, 2012, 10:56:11 am » Bigger Smaller Reset

And two for current sensing?

Mark
 Logged

0
Offline
Tesla Member
Karma: 104
Posts: 8577
Arduino rocks
 « Reply #20 on: December 04, 2012, 06:49:25 pm » Bigger Smaller 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.

0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
 « Reply #21 on: December 04, 2012, 08:57:47 pm » Bigger Smaller 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
Newbie
Karma: 0
Posts: 46
 « Reply #22 on: December 05, 2012, 02:20:54 am » Bigger Smaller 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
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
 « Reply #23 on: December 05, 2012, 06:42:45 pm » Bigger Smaller 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
Tesla Member
Karma: 104
Posts: 8577
Arduino rocks
 « Reply #24 on: December 05, 2012, 06:56:27 pm » Bigger Smaller 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.

Offline
Newbie
Karma: 0
Posts: 46
 « Reply #25 on: December 05, 2012, 07:56:22 pm » Bigger Smaller 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
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
 « Reply #26 on: December 05, 2012, 09:36:33 pm » Bigger Smaller 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
Jr. Member
Karma: 2
Posts: 58
 « Reply #27 on: December 06, 2012, 12:32:48 am » Bigger Smaller 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
Newbie
Karma: 0
Posts: 46
 « Reply #28 on: December 06, 2012, 02:47:48 am » Bigger Smaller 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 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

// 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
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