Go Down

Topic: Do not know how to run forward the dc motors. (Read 1 time) previous topic - next topic

creativen

I am buying the motors shield this: http://www.dfrobot.com/wiki/index.php?title=Arduino_Motor_Shield_(L298N)_(SKU:DRI0009)


and plugged in to arduino uno, to control dc motors like in this robot kit: http://www.famosastudio.com/robotics/2wd-miniq-robot-kit-plus



I am using PWM mode.
And the programming code following from dfrobot:
Code: [Select]
//Arduino PWM Speed Control?
int E1 = 5; 
int M1 = 4;
int E2 = 6;                     
int M2 = 7;                       

void setup()
{
    pinMode(M1, OUTPUT);   
    pinMode(M2, OUTPUT);
}

void loop()
{
  int value;
  for(value = 0 ; value <= 255; value+=5)
  {
    digitalWrite(M1,HIGH);   
    digitalWrite(M2, HIGH);       
    analogWrite(E1, value);   //PWM Speed Control
    analogWrite(E2, value);   //PWM Speed Control
    delay(30);
  } 
}


the motor works rotating backward with this code, but how to run forward?
Please help! I heard this shield can have bidirectional rotation  :smiley-mr-green:

dxw00d

Did you read the dfrobot page you attempted to link to? There is a table about half way down that shows what the pins are used for in each mode. Some pins are described as direction pins. Setting a direction pin (M1/M2 in PWM mode) HIGH sets that motor to backward.

creativen


Did you read the dfrobot page you attempted to link to? There is a table about half way down that shows what the pins are used for in each mode. Some pins are described as direction pins. Setting a direction pin (M1/M2 in PWM mode) HIGH sets that motor to backward.


Oh yeah I read that mode.
But how to sets the motor to forward?

dxw00d

Quote
But how to sets the motor to forward?


Really? It's a direction pin. It can be set HIGH or LOW. HIGH sets the motor direction to backwards. Try the alternative option.

creativen

When I set to LOW, the motor is disabled, not moving forward.

Go Up