Connecting a motor driver to arduino

Hi , I had a topic about this on the previous forum , and the only thing I understood was that these motors have been purchased from Ebay .
I have some ideas about wiring these but then the programming is likely to be confusing as I don't know what is each pin on the driver (for example they say if this pin gets logic current motor goes forward if the other pin receives current it goes backwards if both get current it 'brake's or whatever )
This is the driver (if I'd take a photo of it , it'd be blurry , so attached is one from the shop)

I have found an answer to my question and I was wondering if it's correct :
Based on the internal wiring I found on Here :
Giving logic voltage to IN1 and IN2 (or 3 & 4) will turn the motor on in one direction because it switches two transistors that result in the motor spinning .
But I don't know about reverse .
I'd be more than grateful if anyone would help me . Thanks in advance .

l298n_dual_h_bridge_arduino(3)-350x350.jpg

Have you got a motor to hand or if not a multi meter?

If either then surely you can test by powering it up and taking each input either high or low.

Have you researched H-BRIDGE to understand how one works ?
The answer to your question is in understanding how an H-Bridge works. The only reason it exists is to be able to reverse the direction of the motor. (PWM control can be done with a single switching device).
If IN1 = LOW , and IN2= HIGH,
direction = one direction
IN2 = HIGH, IN1 = LOW,
direction = OTHER direction.

Get it ?

You also need to HIGH the ENable pin for each motor to get it going, not just hi/lo or lo/hi on the IN pins.

Normal practice is also to use the EN as PWM if you want speed control.

You need to be aware of the L298 chip on there being a voltage hog.... it loses 2V under all circumstances, up to almost 5V at high current. So you need to budget for that on your power supply.

raschemmel:
Have you researched H-BRIDGE to understand how one works ?
The answer to your question is in understanding how an H-Bridge works. The only reason it exists is to be able to reverse the direction of the motor. (PWM control can be done with a single switching device).
If IN1 = LOW , and IN2= HIGH,
direction = one direction
IN2 = HIGH, IN1 = LOW,
direction = OTHER direction.

Get it ?

Hi , thanks . I'll try that .

JimboZA:
You also need to HIGH the ENable pin for each motor to get it going, not just hi/lo or lo/hi on the IN pins.

Normal practice is also to use the EN as PWM if you want speed control.

You need to be aware of the L298 chip on there being a voltage hog.... it loses 2V under all circumstances, up to almost 5V at high current. So you need to budget for that on your power supply.

Hi , thanks . I'll give higher voltage . However the motors I have are rated for 12v but they even work at 1.5v :smiley:

ChilliTronix:
Have you got a motor to hand or if not a multi meter?

If either then surely you can test by powering it up and taking each input either high or low.

Hi , I'll also try that , thanks .

But I don't understand what should I do if I wanted to test a stepper (I only use this driver for testing) . I've seen a sample code :

int ENA=2;//connected to Arduino's port 2
int IN1=3;//connected to Arduino's port 3
int IN2=4;//connected to Arduino's port 4
int ENB=5;//connected to Arduino's port 5
int IN3=6;//connected to Arduino's port 6
int IN4=7;//connected to Arduino's port 7
 
int _step = 0; 
boolean dir = false; //gre
void setup()
{
 pinMode(ENA,OUTPUT);
 pinMode(ENB,OUTPUT);
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT);
 pinMode(IN4,OUTPUT);
 digitalWrite(ENA,HIGH);//enable motorA
 digitalWrite(ENB,HIGH);//enable motorB
}

void loop() 
{ 
  switch(_step){ 
  case 0: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, HIGH); 
    break;  
  case 1: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, HIGH); 
    digitalWrite(IN4, HIGH); 
    break;  
  case 2: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, HIGH); 
    digitalWrite(IN4, LOW); 
    break;  
  case 3: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, HIGH); 
    digitalWrite(IN3, HIGH); 
    digitalWrite(IN4, LOW); 
    break;  
  case 4: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, HIGH); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, LOW); 
    break;  
  case 5: 
    digitalWrite(IN1, HIGH);  
    digitalWrite(IN2, HIGH); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, LOW); 
    break;  
  case 6: 
    digitalWrite(IN1, HIGH);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, LOW); 
    break;  
  case 7: 
    digitalWrite(IN1, HIGH);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, HIGH); 
    break;  
  default: 
    digitalWrite(IN1, LOW);  
    digitalWrite(IN2, LOW); 
    digitalWrite(IN3, LOW); 
    digitalWrite(IN4, LOW); 
    break;  
  } 
  if(dir){ 
    _step++; 
  }
  else{ 
    _step--; 
  } 
  if(_step>7){ 
    _step=0; 
  } 
  if(_step<0){ 
    _step=7; 
  } 
  delay(10); 
}

which is for a similar driver , but I guess it would work with this too ? (both are L298Ns and similar circuit)

Hi, don't forget gnd of arduino needs to be connected to gnd of driver as well as gnd of motor power supply.

Tom..... :slight_smile:

Yes thanks , I won't forget that . I actually knew that but I didn't know the reason until some weeks ago where am article explained why exactly do we have to do that .

Have you researched H-BRIDGE to understand how one works ?

Ok, let's try this again;

Have you researched STEPPER MOTORS ? Do you understand HOW one works ?

which is for a similar driver , but I guess it would work with this too ? (both are L298Ns and similar circuit)

I doubt it. It is possible to make a stepper driver by adding circuitry to handle the DIR and STEP signals but
I have NEVER seen an L298 on the internet so equipped. They all have INX and ENX, lines. No DIR and
no STEP pins. For those kind of inputs you need a driver like the RAMPS A4988 or Pololu A4988.

Hi , thanks . I think these wont work with step/dir as they require 6 wires to control a stepper . I wanted to test my motors before buying A4988 s so if the motors were destroyed or had problems with becoming a bipolar (blue smoke and roasted transistor smell ;D ) I'd also buy some motors .