Help using arduino and motor driver

Need help badly..

Can anyone please tell me if there's a way to drive two of this module (https://docs.google.com/file/d/0BxdLxDCD6HidMTFJVFdfeC1pQ3c/edit) using 1 arduino. Is it possible? We badly need to control 4 of this module for our project and fortunately, we have 2 arduinos at hand.

Thanks in advance

If I read that datasheet correctly, that board drives only one motor?

If so, you might consider other boards which drive two- that's just a bit simpler and takes up less space.

But if you need to use two of those, yep looks like it's no problem to hook them up. It only needs three wires to the INA, INB and PWM pins. If you do a count of pins available on your Arduino you may be able to run more. You don't say which Arduino you have, so check the data sheets for how many I/O lines you have. A UNO has 14... subtract the two for serial comms, leaves you 12.... you could run 4 of those boards if you have all the pins available.

(That all assumes I read the datasheet correctly, E&OE)

JimboZA: If I read that datasheet correctly, that board drives only one motor?

If so, you might consider other boards which drive two- that's just a bit simpler and takes up less space.

But if you need to use two of those, yep looks like it's no problem to hook them up. It only needs three wires to the INA, INB and PWM pins. If you do a count of pins available on your Arduino you may be able to run more. You don't say which Arduino you have, so check the data sheets for how many I/O lines you have. A UNO has 14... subtract the two for serial comms, leaves you 12.... you could run 4 of those boards if you have all the pins available.

(That all assumes I read the datasheet correctly, E&OE)

thanks for the reply mate.. i have 1 arduino mega and 1 arduino uno.. yes, we really need this module since it's the only available module we have. We're worried about the current consumption of each & the current limit for arduino since we're going to drive two modules using 1 arduino board. Is it safe? and the two motors driven by 2 modules should run at the same time.

Well don't forget that you're not driving the motors from the Arduino.... The motors MUST have their own power supply: that goes into the board on the MOTOR SUPPLY + and - connectors.

It says that the logic supply required is 50mA. If you're concerned, you could also have a separate 5V into the motor board, as opposed to using the Arduino's 5V, to power the board's logic. Then all you're supplying from the Arduino is a tiny current on the control pins. If you do use a separate 5V power supply to the motor board, you must also link the Arduino ground to the motor board ground too.

JimboZA: Well don't forget that you're not driving the motors from the Arduino.... The motors MUST have their own power supply: that goes into the board on the MOTOR SUPPLY + and - connectors.

It says that the logic supply required is 50mA. If you're concerned, you could also have a separate 5V into the motor board, as opposed to using the Arduino's 5V, to power the board's logic. Then all you're supplying from the Arduino is a tiny current on the control pins. If you do use a separate 5V power supply to the motor board, you must also link the Arduino ground to the motor board ground too.

yes, we're using an external supply for the modules. and we're using only the arduino board to control the INA, INB, and PWM of each module. (2 modules for 1 board (6 pins for INA INB and PWM of module1 and INA INB and PWM of module2)). Is it safe?

By module you mean the motor driver board? If you have it with its own external supply (as well as another to the motor side of the board) then you're not stressing the Arduino at all with just the INA, INB and PWM pins.

Even if you're driving the boards' logic 5V at the stared 50mA each you should be OK.... but on that, I'm not sure what current the Arduino can supply through Vin or 5V pins, the product page doesn't say.

Edit... have a look at at what Nick Gammon has to say.... 200mA output per board.

JimboZA: By module you mean the motor driver board? If you have it with its own external supply (as well as another to the motor side of the board) then you're not stressing the Arduino at all with just the INA, INB and PWM pins.

Even if you're driving the boards' logic 5V at the stared 50mA each you should be OK.... but on that, I'm not sure what current the Arduino can supply through Vin or 5V pins, the product page doesn't say.

Yes, we have separate source for our motors & separate source for the motor drivers as well (but 4 motor drivers in parallel on a single 9v battery passing a 5v regulator) is it ok?.. Here's our connection for the arduino uno and the 2 motor drivers

motor driver 1: INA to pin 2 INB to pin 4 PWM to pin 5 PWM motor driver 2: INA to pin 7 INB to pin 8 PWM to pin 10 PWM

Those connections would be good I guess… if it works, it works 8). Those are no different that you would have if you had a dual motor driver board hooked up, and there are loads of those around running fine. Especially since you have the board logic supplied from outside…

You could, if you have time and inclination, stick an ammeter in series on one of those control pins and see what current is drawn, then you could add it all up and be 100% sure.

Regarding driving the boards from a 9V battery through a 5V regulator, well just be aware that those PP3 style batteries have a bad reputation for running down quickly. Also, if you have a 7805 style reg, you’ll have the same current on both sides and be wasting (9-5)V x whatever the current is as power. But again, if it works it works.

unfortunately i can't find our ammeter

arjiii24: 4 motor drivers in parallel on a single 9v battery passing a 5v regulator) is it ok?..

If you're talking about those little PP3 9V batteries I suggest you bin that idea. They have tiny charge capacity and also can only supply a tiny current, and they're relatively expensive. To add insult to injury, if you are supplying the motors via a 5V regulator your regulator will be throwing most of the energy away as heat.

Do you really need to power the motors through a regulator? It's not normally necessary. You should be able to just choose a set of cells that produces the voltage the motors need and has enough current capacity to meet the peak current requirements of the motors. To choose the appropriate batteries you need to start by knowing how much voltage and current the motors need.

anyone please help me.

yes we changed the supplies of the motor drivers. we supplied each motor driver board with 4AA batteries and separate 12v sources for motors. The problem is were quite unsure if the arduino can drive 2 of these motor driver boards.

the arduino is supplying only the INA INB PWM of motor driver 1 and INA INB PWM of motor driver 2. will it not exceed the current limit of the arduino? please help anyone

Motor controller PWM and control inputs usually take negligible current and can be driven directly from an Arduino output pin.

You need to ensure that your Arduino has a regulated smooth supply for the logic circuits. Typically you would supply 7V or more to the Arduino, and use the Arduino’s integral regulator to generate 5V. Alternatively you can provide an external 5V regulated source and connect that directly to the Arduino’s 5V line, bypassing the regulator. Typically a motor shield would also need a regulated supply for the logic side and if the voltage is the same as your Arduino then it would be sensible to use the same supply for both. Remember that the Arduino and driver grounds need to be connected.

The main power supply for the motors is also connected to the motor driver but does not usually need to be smoothed or regulated and should be separate from the logic supply(s).

thanks mate :)

i noticed that when we connect all the drivers, the motors won’t run at the same time?
why is this?

here’s our code:

//main motor 1 (E-gizmo driver 1)
int PWM1 = 2;
int gdc1Pin1 = 26; //to INA1
int gdc1Pin2 = 28; //to INB1

//main motor 2 (E-gizmo driver 2)
int PWM2 = 4;
int gdc2Pin1 = 32; //to INA2
int gdc2Pin2 = 34; //to INB2

//swing arm motor front
int PWMf = 6;
int INAf = 38; 
int INBf = 40;

//swing arm motor back
int PWMb = 8;
int INAb = 44;
int INBb = 46;

int swArmF = 0;
int swArmB = 0;
int i = 0;
int j = 0;
int k = 0;
int l = 0;


void setup() {
  
     pinMode(PWM1, OUTPUT);
digitalWrite(PWM1, LOW);

     pinMode(PWM2, OUTPUT);
digitalWrite(PWM2, LOW);

     pinMode(PWMf, OUTPUT);
digitalWrite(PWMf, LOW);

     pinMode(PWMb, OUTPUT);
digitalWrite(PWMb, LOW);


     pinMode(gdc1Pin1, OUTPUT);
digitalWrite(gdc1Pin1, LOW);
     pinMode(gdc1Pin2, OUTPUT);
digitalWrite(gdc1Pin2, LOW);

     pinMode(gdc2Pin1, OUTPUT);
digitalWrite(gdc2Pin1, LOW);
     pinMode(gdc2Pin2, OUTPUT);
digitalWrite(gdc2Pin2, LOW);

     pinMode(INAf, OUTPUT);
digitalWrite(INAf, LOW);
     pinMode(INBf, OUTPUT);
digitalWrite(INBf, LOW);

     pinMode(INAb, OUTPUT);
digitalWrite(INAb, LOW);
     pinMode(INBb, OUTPUT);
digitalWrite(INBb, LOW); 

Serial.begin(9600); // set serial speed from USB(computer)
}

void loop(){
  
while (Serial.available() == 0); // do nothing if nothing sent
int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number

//stop
if (val == 0)
{
  analogWrite(PWM1, 0);
  analogWrite(PWM2, 0);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, LOW);
}
//forward
else if (val == 1) 
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc2Pin2, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
//backward
else if (val == 2)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
}
//right
else if (val == 3)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
}
//left
else if (val == 4)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
// val 5 to 7, speed control of forward
else if (val == 5)
{
  analogWrite(PWM1, 127);
  analogWrite(PWM2, 127);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
else if (val == 6)
{
  analogWrite(PWM1, 191);
  analogWrite(PWM2, 191);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
else if (val == 7)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
// val 8 to 10, speed control of backward
else if (val == 8)
{
  analogWrite(PWM1, 127);
  analogWrite(PWM2, 127);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
}
else if (val == 9)
{
  analogWrite(PWM1, 191);
  analogWrite(PWM2, 191);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
}
else if (val == 10)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
}
// val 11 to 13, speed control of right
else if (val == 11)
{
  analogWrite(PWM1, 127);
  analogWrite(PWM2, 127);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
  digitalWrite(gdc2Pin1, HIGH);
  //digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, LOW);
}
else if (val == 12)
{
  analogWrite(PWM1, 191);
  analogWrite(PWM2, 191);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
  digitalWrite(gdc2Pin1, HIGH);
  //digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, LOW);
}
else if (val == 13)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
  digitalWrite(gdc2Pin1, HIGH);
  //digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, LOW);
}
// val 14 to 16, speed control of left
else if (val == 14)
{
  analogWrite(PWM1, 127);
  analogWrite(PWM2, 127);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  //digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
else if (val == 15)
{
  analogWrite(PWM1, 91);
  analogWrite(PWM2, 191);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  //digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
else if (val == 16)
{
  analogWrite(PWM1, 255);
  analogWrite(PWM2, 255);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  //digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
}
//up control
if (val == 17)
{
  if(swArmB = 0)
  {
   for(i=0; i<4; i++)
    {
     //analogWrite(PWMf, 255);//adjust speed 
     analogWrite(PWMb, 255);//
     digitalWrite(INAb, HIGH);
     digitalWrite(INBb, LOW);
     swArmB++;
     if(j!=2)
     {
       analogWrite(PWMf, 255);//adjust speed 
       //analogWrite(PWMb, 255);//
       digitalWrite(INAf, HIGH);
       digitalWrite(INBf, LOW);
       j++;
       swArmF++;
     }
    }
  }
  //forward motion during upstairs
  analogWrite(PWM1, 127);
  analogWrite(PWM2, 127);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH); 
  l = k/3;
  if( l == 1 || l == 2 || l == 3 || l == 4)
  {
    if(swArmB < 8)
    {
     //analogWrite(PWMf, 255);//adjust speed 
     analogWrite(PWMb, 255);//
     digitalWrite(INAb, HIGH);
     digitalWrite(INBb, LOW);
     swArmB++;
    }
  }
}
//down control
else if (val == 18)
{
  if(swArmF = 0)
  {
   for(i=0; i<4; i++)
    {
     analogWrite(PWMf, 255);//adjust speed 
     //analogWrite(PWMb, 255);//
     digitalWrite(INAf, HIGH);
     digitalWrite(INBf, LOW);
     swArmB++;
     if(j!=2)
     {
       //analogWrite(PWMf, 255);//adjust speed 
       analogWrite(PWMb, 255);//
       digitalWrite(INAb, HIGH);
       digitalWrite(INBb, LOW);
       j++;
       swArmF++;
     }
    }
  }
  analogWrite(PWM1, 50);
  analogWrite(PWM2, 50);
  digitalWrite(gdc1Pin1, HIGH);
  digitalWrite(gdc1Pin2, LOW);
  digitalWrite(gdc2Pin1, LOW);
  digitalWrite(gdc2Pin2, HIGH);
  //backward fast
  delay(2000);
  analogWrite(PWM1, 50);
  analogWrite(PWM2, 50);
  digitalWrite(gdc1Pin1, LOW);
  digitalWrite(gdc1Pin2, HIGH);
  digitalWrite(gdc2Pin1, HIGH);
  digitalWrite(gdc2Pin2, LOW);
  
  l = k/3;
  if( l == 1 || l == 2 || l == 3 || l == 4)
  {
    if(swArmF < 8)
    {
     //analogWrite(PWMf, 255);//adjust speed 
     analogWrite(PWMb, 255);//
     digitalWrite(INAb, HIGH);
     digitalWrite(INBb, LOW);
     swArmF++;
    }
  }
}
//end up control
else if (val == 19)
{
  while(swArmF != 0)
  {
    analogWrite(PWMf, 255);//adjust speed 
    analogWrite(PWMb, 255);//
    digitalWrite(INAf, LOW);
    digitalWrite(INBf, HIGH);
    swArmF--;
  }
  while(swArmB != 0)
  {
    analogWrite(PWMf, 255);//adjust speed 
    analogWrite(PWMb, 255);//
    digitalWrite(INAb, LOW);
    digitalWrite(INBb, HIGH);
    swArmB--;
  }
  i = 0;
  j = 0;
  k = 0;
  l = 0;
  swArmB = 0;
  swArmF = 0;
}
//end down control
else if (val == 20)
{
   while(swArmF != 0)
  {
    analogWrite(PWMf, 255);//adjust speed 
    //analogWrite(PWMb, 255);//
    digitalWrite(INAf, LOW);
    digitalWrite(INBf, HIGH);
    swArmF--;
  }
  while(swArmB != 0)
  {
    //analogWrite(PWMf, 255);//adjust speed 
    analogWrite(PWMb, 255);//
    digitalWrite(INAb, LOW);
    digitalWrite(INBb, HIGH);
    swArmB--;
  }
  i = 0;
  j = 0;
  k = 0;
  l = 0;
  swArmB = 0;
  swArmF = 0;
}
else // if not one of above command, do nothing

Serial.println(val);
Serial.flush(); // clear serial port
 
}

by the way, we’re using arduino mega only for 4 motor drivers

please anyone help me.

how can i make the two motors run at the same time?

Well I for one don't have the energy to wade through that loooong code on a Friday night 8)

Normal suggestion in such cases is for you to create a very much shorter sketch but which still exhibits the same problem as an aid to anyone helping. Write a minimal sketch, simply to power the motors in one direction, see if they both run. If they do, then perhaps add a 50% PWM and maybe reverse direction.

Start from a known point where stuff works and add functionality until it stops behaving correctly...

Is there any way to make the motors run at the same time?

Is there any way to make the motors run at the same time?

If both boards are enabled and hooked up, and you're sending the right signals to them, both motors will be able to run at the same time.

That's why I asked you to write a very small sketch that is easy for others to follow, where you do nothing but set the right values on your Arduino pins which then get the right values to INA (say, High) and INB (say, Low) on both boards and see if they run. There's too much clutter in that long code for me to wade through- do this simple test and see if it works or not. If it doesn't work, then we'll need to see what's wrong. If it does work, then add PWM to both and see if that works....

I'm not inclined to help if you don't say anything about whether or not you tried my suggestion but just asked exactly the same question 6 hours later.

arjiii24: please anyone help me.

how can i make the two motors run at the same time?

hi,

even though, I control only one stepper motor and trying to use L293D, I have current and heating realted issues and I am planing to use some mosfet arrays to protect the driver circuit. So, I have an idea which I asked in the forum and waiting for th replies from the experienced users. maybe you want to follow the topic too...

This is the beginning of my project http://arduino.cc/forum/index.php/topic,152747.new/topicseen.html#new After having overheating I asked this question http://arduino.cc/forum/index.php/topic,153070.0.html

In my second topic I am trying to find some answers related to the mosfet array. If it is approved, I think you can use the same idea for your project. Since you are trying to use only one board, you can connect the output of your dirver circuit to the (4, 8 or 16) base of the mosftes and you supply the motor supply source to the mosfets. So the drive current flows over the mosfets instead of your circuit and, if something blows up, it will be the mosfets instead of your boards.... I also reckon that the mosfets must have high switching frequencies. I have 4 TIP3055 Auido grade mosfets and I will use them if I chactch a clue from somebody :)

It would be great if somebody who has a better electronic experience could also contribute my idea. And if you decide to try by yourself, please let me know what the result is :)

I have an update

I have just realized that the TIP 3055 is a power transistor :) Instead logic level n-channel MOSFETs are more proper. Such as IRFZ44N.

Cheers