Changing the Speed of Arduino Uno

I'm trying to figure out if I can change the speed of the motor midway through. I'm not really sure what any of this means.

// Definitions Arduino pins connected to input H Bridge
int enA = 9;
int enB = 11;
int Speed1 = 50;
int Speed2 = 50;
int IN1 = 4;
int IN2 = 6;
int IN3 = 3;
int IN4 = 5;

void setup()
{
  // Set the output pins


  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
}


void loop()
{
  analogWrite(enA, Speed1);
  analogWrite(enB, Speed2);

  // Rotate the Motor A clockwise
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  delay(1568);
  // Motor A
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  delay(392);

  // Rotate the Motor A counter clockwise
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  delay(1568);
  // Motor A
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  delay(392);

  // Rotate the Motor B clockwise
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  delay(1568);
  // Motor A
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, HIGH);
  delay(392);

  // Rotate the Motor B counter clockwise
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  delay(1568);
  // Motor A
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, HIGH);
  delay(392);

(there is more it's just not relevant)

Try changing Speed1, Speed2 or both.

Is the Arduino connected to anything, like a motor controller and one or two motors?

I'm not really sure what any of this means.

Google "arduino motor control" for countless tutorials.

You must also do this bit again when you want the speed change to take effect:

  analogWrite(enA, Speed1);
  analogWrite(enB, Speed2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.