motor PWM help????

hi there i bought this l298d motor shield on . i know how to run the motor forward and backward. but i don't how to control the speed of it.

can anyone explain me with example code

circuit diagram

for more details

I suspect you will find many topics here about similar devices - have you looked?

You could also read the L298 datasheet.

It would help if you had explained how you you make the motor run forwards and backwards.

My guess is that if you apply a PWM signal [analogWrite(pin, value)] to one or other of the input connections it will control the speed. Use the other connection for the other direction.

...R

this is the code i used to make the two motors go forward and backward

int IN1 = 9;
int IN2 = 10;
int IN3 = 5;
int IN4 = 6;

void setup(){
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop(){
        //motor runs forward
        //first motor
  `    digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        //secound motor  
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);

        delay(50);
        
         //motor runs backward
  `    digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);

        delay(50);
}

Where is the data sheet?

Mark

holmes4:
Where is the data sheet?

Mark

The picture shows four inputs and in the absence of any other info I would guess these correspond to the four motor outputs i.e. when you send an input high the corresponding output is driven high.

Each pair of motor output pins would correspond to two of these input pins. When both pins are in the same state (both high or both low) the motor is stopped. When one pin is driven high and the other low the motor is powered in one direction. When the polarity of the pins is reversed it is driven in the opposite direction. To control the speed you would apply PWM to one of the pins. If you apply PWM to the pin that is nominally HIGH then 0 corresponds to no power and 255 corresponds to full power. If you apply PWM to the pin that is nominally LOW then 255 corresponds to no power and 0 corresponds to full power.

PeterH:
The picture shows four inputs and in the absence of any other info I would guess these correspond to the four motor outputs i.e. when you send an input high the corresponding output is driven high.

Each pair of motor output pins would correspond to two of these input pins. When both pins are in the same state (both high or both low) the motor is stopped. When one pin is driven high and the other low the motor is powered in one direction. When the polarity of the pins is reversed it is driven in the opposite direction. To control the speed you would apply PWM to one of the pins. If you apply PWM to the pin that is nominally HIGH then 0 corresponds to no power and 255 corresponds to full power. If you apply PWM to the pin that is nominally LOW then 255 corresponds to no power and 0 corresponds to full power.

thanks
it working now
this is code i used

int motorPin1 = 3;
int motorPin2 = 5;


void setup() {
  // put your setup code here, to run once:
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  
}

void loop() {
  // put your main code here, to run repeatedly: 
  delay(10);
      
        analogWrite(motorPin1, 120);
        analogWrite(motorPin2, LOW);
        
       delay(1000);
      
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        
        delay(1000);
}