ROV DC motors need some help

Hi guys,
Planing to build small ROV 3 12Vdc motors controled by pot joystic, 3 directions:
1 up down (planin to use sliding pot fot that)
2 motors forward backward or one forward one backward
Now, i tried to upload one of the codes and modified it but is not changing directions just adjusting the speed.

Help please

Help please

Code, please.

int potPin = 0;
int trPin = 9;
int potValue 0;

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

void loop() {
potValue = analogRead(potPin) / 4;
analogWrite (9, potValue);
}

I can adjust speed but only one direction
Do i need to use a chip with this?

Hw to set up potentiometer value to be 0 in the centre??

I assume you've already got some sort of "chip" to drive the motor, but which one?

Hw to set up potentiometer value to be 0 in the centre??

Zero relative to what?

What about "map"?
"map (analogueValue, 0, 1023, -255, 255);"

not realy was planin to use a chip but im not that god with this so just a standard joystic taken out from playstation controler
What about "map"?
dont know hw to do that

http://arduino.cc/en/Reference/Map

You still haven't said what you're using to drive the motor.

int potPin = 0; 
int trPin = 9;
int potValue 0;

You haven't compiled this, so how do you know what it does?

It is a simple construction:
12V car battery
TIP 121
zener diodes
1k resistor
and joystic

what else do i need?

To reverse the motor, you'll need either a DPDT relay (and transistor to drive it) or an H-bridge.

const int potPin = 0; 
const int trPin  = 9;
const int revPin = 10;

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

void loop()  {
  int speed = map (analogRead(potPin), 0, 1023, -255, 255);
  if (speed < 0) {
    digitalWrite (revPin, HIGH);
    speed = -speed;
  } else  
    digitalWrite (revPin, LOW);
  }  
  analogWrite (trPin, speed);
}

Ok but instead of using relay i have got a joystic
Is that not gonna be better?

The relay is for reversing the motor power.

Is it posible by any chance to reverse the power just with the joystic?

No.

The TIP transistor is just acting like a simple SPST switch; it can't reverse the flow of current, only turn it on or off.

Thanks for that
One more thing ok?
if i will use a relay (which one?) will arduino swich automaticly directions so i can use only joystic pot to control it??

You need a DPDT relay with contacts rated for an inductive load comparable to the DC motor you're using, and a low voltage (probably 12V) coil - don't forget a diode across the relay coil.
You'll need another TIP120 to drive it, and the very simple sketch above.
You'll probably very quickly find out that to avoid relay chatter, you'll want to program in a dead-band around the middle of the joystick's movement, but the sketch as it is will allow you to drive a relay and the motor.

Thank You for advice
Really great help

Below are some simple motor reversing setups that might be of use.


Groove, Zoomcat; based on your words/drawings - while those ideas will allow direction control of a motor (and in Zoomcat's case, limit switches to shut it off) - neither of these will work for the OP's application.

What's being built is an ROV (underwater remote operated vehicle), the up/down (and left/right) motors need a way to be turned off (and while Zoomcat's limit switches could work in a steering control or similar, they aren't much use for a prop thruster).

What is needed (if using relays) is an h-bridge constructed from 2 SPDT relays (each with their own transistor control), one for each motor. Alternatively (and better from an amperage point of view) would be to use 4 SPST relays, one for each leg of the h-bridge; and 4 transistors (and diodes, and everything else) - plus you would need to be careful not to set the wrong relays creating a direct-short...

Really, it would be better to (and cheaper), depending on the current requirements of the motors, of course - to buy some IC-based motor drivers (L298, etc) instead; depending on the source, it would only cost a few dollars per motor, whereas the relay method could cost much more than that.

Of course, if the current requirements are high, then using relays may be the cheapest method per motor; high-amperage pre-built motor drivers (greater than 5 to 10 amps) get expensive quickly, whereas relays are cheap.

The big disadvantage, though, of relay h-bridges (unless you have a beefy mosfet controlling the motor power input), is the inability of them to PWM speed control the motors - this applies whether the h-bridge is driving a low current or high current motor (though it can be done with a low current motor if a suitable transistor or mosfet of the proper size is used to control the motor power input, as mentioned; a large NPN or N-channel mosfet on the low side of the h-bridge and ground could work).

The OP's gonna need a bigger allowance to complete this project if he wants to use the Arduino in it!

;D

The big disadvantage, though, of relay h-bridges (unless you have a beefy mosfet controlling the motor power input), is the inability of them to PWM speed control the motors

That's what the TIP121 is there for, I assume.

[edit]On further consideration, for vertical thrusters, I wouldn't even allow them to reverse, only drive downwards, since the ROV would be slightly positively buoyant.[/edit]

I probably should have also included the below drawing. Just to keep things simple, the below Radio Shack toggle switch can be used to control the direction of a motor with the center position being off. If motor speed control is needed, then a power control setup (voltage, PWM, etc) can be put in the power circuit supplying the switch. Starting out with this type of test setup will inexpensivly allow a person to then move on to the potentially more difficult parts of the project. I always like to do inexpensive "proof of concept" testing prior to spending a lot of time and $$$ only to find a previously unknown "show stopper". :wink: