Arduino Uno mini rov with 4 dc motors

I am new to the Arduino world when it comes to programming and understanding things, though I am taking a class that should help my learning curve.

My project is to build a mini ROV that can operate underwater. The Arduino will be pre programmed though my goal is to eventually hook up with tether to my lap top. First thing is first though I need to get 4 dc motors running off my Arduino Uno.

My problem is I can't figure out how program the Arduino to run 4 dc motors. Assuming I have correctly wired up both H-Bridges. I will have two motors that propel the ROV up and down and two motors that can go forward reverse or left or right by changing speed. I am using two dual TB6612FNG H Bridges so I can control each pair of motors bidirectionally. I was told this is possible but have found very limited information online when it comes to using the Arduino Uno with two H-Bridges.

Does anyone have any insight on this topic that could help me out?

The h-bridge driver will typically have a number of logic level inputs to control the direction and speed, and you connect these to pins on your Arduino and then set the pins to the appropriate state. The documentation for the h-bridge driver ought to explain how to control it. If it's designed to be used with an Arduino then it might well come with a code example too.

Lets see..... "TB6612FNG" ... cut-n-paste into google. FIRST hit : A picture with wiring diagram (showing a board made by Sparkfun that uses this chip) . SECOND hit - the full PDF datasheet. THIRD hit - Pololu's page with their board using this chip (with the schematics). On that page a - and I kid you not - link to “How to use the TB6612FNG motor driver with the Arduino for noobs”.

Oh, wait, just a moment - I just thought of something. Of course the question is how to connect TWO of these bridges to Arduino, not just one. Well, if one pin is in use by the first bridge, then you cant use it, use another pin that is free. Thats about it. If you do not have enough pins ... either get a MEGA or learn how to use various intermediate chips reduce the required pin count. If you truly want to independently control 4 motors each with FWD/REV/STP then it needs 4*3 = 12 pins plus another for the Standby/Enable.

As far as the software goes - it is whatever code you have, copied one more time and given new names. Or learn how to use arrays and so you only write the code once, and than just pass the array index (which for each motor know the pin assigments). DO NOT USE DELAY().

I have wired up both H-Bridges though I read something online saying pins 0 and 1 are already in use for the Arduino uno but the analog pins can also be used as digital output is there any truth to this?

I guess what I really need help with is the coding because when I tried doing a sketch for the 4 motors and it didn't like that I had two standby pins and used the PWMA function twice. I simply took the code I already have to run both motors and tried meshing it together for 4 motors but it doesn't seem to be as straight forward as that. Any help appreciated yes I am new to this.

Licaris:
pins 0 and 1 are already in use for the Arduino uno but the analog pins can also be used as digital output is there any truth to this?

If you use the hardware Serial port then this uses pins 0 and 1.

The analog pins can also be used for digital I/O by using A0, A1 etc as the pin number when you call pinMode(), digitalWrite(), digitalRead().

What is the hardware serial port? Ok thats what I thought. so when i'm defining outputs from the h bridge for two motors my code starts.

int STBY = 8;//this will be the standby pin

//Motor A
int PWMA = 6; //Speed control
int AIN1 = 3; //Direction
int AIN2 = 2; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 4; //Direction
int BIN2 = 7; //Direction

How do I define the other H-Bridge any tips for Motor C and Motor D.

Licaris:
How do I define the other H-Bridge any tips for Motor C and Motor D.

Similarly, but using the whatever pin numbers you have connected the second H-bridge to. In case you intend to use pwm to control speed, note that not all pins support pwm.

Given that you have four motors it would IMO be sensible to define a motor class that encapsulates the pin configuration and the logic to output the right pin states to control the motor speed and direction.

Given that the use of pins in that code fragment looks quite conventional, I wouldn't be surprised if there was already a library implementing such a class.

If the idea of using classes is too much to tackle at this stage, consider using arrays instead. I.e. put all the IN1 pin numbers into an array, and all the IN2 pin numbers into a (different) array, and all the PWM pin numbers into another array. Then write functions to make a motor move forwards, stop, reverse, brake etc with the motor specified by the array index number. It's not as clean a way to encapsulate the concept of a motor, but if you aren't comfortable with OO techniques yet then it's better than having to reference motor pin numbers all over the place.