user60916: I would like to know how to set the current position for the DC motors to zero and store the current position in an array. after that I would like it to loop in the array to run all steps that was stored in the array?
Am using Genuino UNO board, I have 4 DC motors and each 2 wheels are connected to an H-bridge. 
I have an application that have a "save" button and a "Run" button.
For the save button, I would like it to set the current position for each wheel to zero first then store the positions of each wheel in an array. 
For the run button, I would like it to loop in the array that was made by the save button and show the output on each wheels.
basically what am trying to achieve is to make the robotic car that can move any direction I tell it to move in the same time  I can control the wheel speed.
all that move are being sent via Bluetooth as numbers.
I hope it's clear now 
here is my code 
#include <SoftwareSerial.h>


SoftwareSerial Bluetooth(0, 1); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)

// Define the motors and the pins  
// Motor A1

int enA1 = 2;
int in11 = 3;
int in21 = 4;


// Motor B1

int enB1 = 5;
int in31 = 6;
int in41 = 7;

//other H-bridge 

// Motor A2

int enA2 = 8;
int in12 = 9;
int in22 = 10;


// Motor B2

int enB2 = 11;
int in32 = 12;
int in42 = 13;

int wheelSpeed = 125;
int dataIn, m;
//lbw left back wheel / lfw left fron wheel / rbw right back wheel / rfw right front wheel
int lbw[50], lfw[50], rbw[50], rfw[50]; // for storing positions/steps
int index = 0;

void setup() {
  // put your setup code here, to run once:

  Bluetooth.begin(9600); // Default baud rate of the Bluetooth module
  Bluetooth.setTimeout(1);
  Serial.print("connected");
  Serial.print("-------------------");
  delay(20);

  pinMode(enA1, OUTPUT);
  pinMode(enB1, OUTPUT);
  pinMode(in11, OUTPUT);
  pinMode(in21, OUTPUT);
  pinMode(in31, OUTPUT);
  pinMode(in41, OUTPUT);
  pinMode(enA2, OUTPUT);
  pinMode(enB2, OUTPUT);
  pinMode(in12, OUTPUT);
  pinMode(in22, OUTPUT);
  pinMode(in32, OUTPUT);
  pinMode(in42, OUTPUT);
}

void loop() {
  // Check for incoming data

 if (Bluetooth.available() > 0) {
    dataIn = Bluetooth.read();  // Read the data

    if (dataIn == 0) {
      m = 0;
    }
    if (dataIn == 1) {
      m = 1;
    }
    if (dataIn == 2) {
      m = 2;
    }
    if (dataIn == 3) {
      m = 3;
    }
    if (dataIn == 4) {
      m = 4;
    }
    if (dataIn == 5) {
      m = 5;
    }
    if (dataIn == 6) {
      m = 6;
    }
    if (dataIn == 7) {
      m = 7;
    }
    if (dataIn == 8) {
      m = 8;

    }
    if (dataIn == 9) {
      m = 9;
    }
    if (dataIn == 10) {
      m = 10;
    }
    if (dataIn == 11) {
      m = 11;
    }

    if (dataIn == 12) {
      m = 12;
    }
    if (dataIn == 14) {
      m = 14;
    }
    // Set speed
    if (dataIn >= 16) {
      wheelSpeed = dataIn * 10;
      Serial.println(wheelSpeed);
    }
  }
  if (m == 4) {
    moveSidewaysLeft();
  }
  if (m == 5) {
    moveSidewaysRight();
  }
  if (m == 2) {
    moveForward();
  }
  if (m == 7) {
    moveBackward();
  }
  if (m == 3) {
    moveRightForward();
  }
  if (m == 1) {
    moveLeftForward();
  }
  if (m == 8) {
    moveRightBackward();
  }
  if (m == 6) {
    moveLeftBackward();
  }
  if (m == 9) {
    rotateLeft();
  }
  if (m == 10) {
    rotateRight();
  }

  if (m == 0) {
    stopMoving();
  }
  //Serial.println(dataIn);
  // If button "SAVE" is pressed
  if (m == 12) {
    if (index == 0) {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW);  
        digitalWrite(in31, LOW);  
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW);  
        digitalWrite(in32, LOW);  
        digitalWrite(in42, LOW); 

    }


    // save position into the array 
  }
  //if (m == 14) {
   // runSteps();
    //if (dataIn != 14) {
      //stopMoving();
      // Clear the array data to 0
   // }
  //}

}

//method to read the array from what was saved by the save button and run it step by step
//void runSteps() {}

void moveForward() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW);
        Serial.println("Motor: move Forward");
}

void moveBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);
        Serial.println("Motor: move Backward");
}

void moveSidewaysLeft() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW);
        Serial.println("Motor: move Sideways Left");
}
void moveSidewaysRight() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);   
        Serial.println("Motor: move Sideways right");
}

void moveRightForward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move Right Forward");
}


void moveLeftBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move left Back ward");
}

void moveLeftForward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move Left Forward");
}

void moveRightBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);   
        Serial.println("Motor: move Right Backward");
}

void rotateLeft() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH); 
        Serial.println("Motor: rotate Left");
  }

void rotateRight() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW); 
        Serial.println("Motor: rotate Right");
  }

void stopMoving() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW); 
        Serial.println("Motor: off");
  }


user42015: As I understood it from your comments, your aim is not really to store the actual positions of the wheels or your robot, but to save and repeat the actions, that the robot did. (Meaning you don't have a "position" here, but only a measurement of wheel speed)
If that is true, then you can save this in a 2-dimensional array with the element form {speed_wheel_1, speed_wheel2, duration}. So each action is defined by the speeds of both wheels and the duration of the action, for example:
Driving forward at full speed for 3s, turn on the spot to the left with half speed for 1.5s, drive a curve with motor left full speed and motor right half speed for 5s

This would translate to the following elements:
{100, 100, 3000}
{-50, 50, 1500}
{100, 50, 5000}

The speeds have to be read in percent here and the durations in milliseconds.

Obviously you are controlling the robot over serial. I don't completely understand your code (also as you didn't show us the full code), so I will give some hints, how you can go on from here:
You are obtaining the speeds from serial into the variable wheelSpeed. We cannot see, how you are using this variable later, but you can use it in some way to set the speed fields of a new array element.
Then you need the duration. The Arduino framework has a function for that: millis(). It will return the number of milliseconds since the startup, much like a clock. When an action starts (when the corresponding serial command is received), you have to set a timestamp:
unsigned long timestamp;
...
timestamp = millis();

When the action ends (either because it actually only had a limited duration, or because another command is received), you calculate the difference between the current millis value and the timestamp. This is the duration.
So the corresponding code parts will look like this:
unsigned long timestamp = 0; // Define timestamp at global scope
unsigned int current_element = 0; // A variable to keep track of the current array element
int actions[10][3]; // Array to hold up to 10 actions

void start_action(byte speed_left, byte speed_right){
    actions[current_element][0] = speed_left;
    actions[current_element][1] = speed_right;
    timestamp = millis();
    // Start the action with the provided speeds here
}

void end_action(unsigned int element_index){
    actions[current_element][2] = millis() - timestamp;
    current_element++;
    if(current_element >= 10){
        // Do something to prevent more actions. Maybe just disable recording.
}

For repeating the actions, you just have to cycle over the array and set the corresponding speeds for the corresponding time.
If you want to go fancy, you can ditch the 2-dimensional array and instead define a struct for an action:
struct Action{
    int speed_left;
    int speed_right;
    unsigned long duration;
};

Then you can create a simple array of the Action objects and reference the fields by name:
Action actions[10];
...
actions[1].duration = millis() - timestamp;


60916: <p>I would like to know how to set the current position for the DC motors to zero and store the current position in an array. after that I would like it to loop in the array to run all steps that was stored in the array?</p>

<p>Am using Genuino UNO board, I have 4 DC motors and each 2 wheels are connected to an H-bridge. </p>

<p>I have an application that have a "save" button and a "Run" button.
For the save button, I would like it to set the current position for each wheel to zero first then store the positions of each wheel in an array. 
For the run button, I would like it to loop in the array that was made by the save button and show the output on each wheels.</p>

<p>basically what am trying to achieve is to make the robotic car that can move any direction I tell it to move in the same time  I can control the wheel speed.
all that move are being sent via Bluetooth as numbers.</p>

<p>I hope it's clear now </p>

<p>here is my code </p>

<pre><code>#include &lt;SoftwareSerial.h&gt;


SoftwareSerial Bluetooth(0, 1); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)

// Define the motors and the pins  
// Motor A1

int enA1 = 2;
int in11 = 3;
int in21 = 4;


// Motor B1

int enB1 = 5;
int in31 = 6;
int in41 = 7;

//other H-bridge 

// Motor A2

int enA2 = 8;
int in12 = 9;
int in22 = 10;


// Motor B2

int enB2 = 11;
int in32 = 12;
int in42 = 13;

int wheelSpeed = 125;
int dataIn, m;
//lbw left back wheel / lfw left fron wheel / rbw right back wheel / rfw right front wheel
int lbw[50], lfw[50], rbw[50], rfw[50]; // for storing positions/steps
int index = 0;

void setup() {
  // put your setup code here, to run once:

  Bluetooth.begin(9600); // Default baud rate of the Bluetooth module
  Bluetooth.setTimeout(1);
  Serial.print("connected");
  Serial.print("-------------------");
  delay(20);

  pinMode(enA1, OUTPUT);
  pinMode(enB1, OUTPUT);
  pinMode(in11, OUTPUT);
  pinMode(in21, OUTPUT);
  pinMode(in31, OUTPUT);
  pinMode(in41, OUTPUT);
  pinMode(enA2, OUTPUT);
  pinMode(enB2, OUTPUT);
  pinMode(in12, OUTPUT);
  pinMode(in22, OUTPUT);
  pinMode(in32, OUTPUT);
  pinMode(in42, OUTPUT);
}

void loop() {
  // Check for incoming data

 if (Bluetooth.available() &gt; 0) {
    dataIn = Bluetooth.read();  // Read the data

    if (dataIn == 0) {
      m = 0;
    }
    if (dataIn == 1) {
      m = 1;
    }
    if (dataIn == 2) {
      m = 2;
    }
    if (dataIn == 3) {
      m = 3;
    }
    if (dataIn == 4) {
      m = 4;
    }
    if (dataIn == 5) {
      m = 5;
    }
    if (dataIn == 6) {
      m = 6;
    }
    if (dataIn == 7) {
      m = 7;
    }
    if (dataIn == 8) {
      m = 8;

    }
    if (dataIn == 9) {
      m = 9;
    }
    if (dataIn == 10) {
      m = 10;
    }
    if (dataIn == 11) {
      m = 11;
    }

    if (dataIn == 12) {
      m = 12;
    }
    if (dataIn == 14) {
      m = 14;
    }
    // Set speed
    if (dataIn &gt;= 16) {
      wheelSpeed = dataIn * 10;
      Serial.println(wheelSpeed);
    }
  }
  if (m == 4) {
    moveSidewaysLeft();
  }
  if (m == 5) {
    moveSidewaysRight();
  }
  if (m == 2) {
    moveForward();
  }
  if (m == 7) {
    moveBackward();
  }
  if (m == 3) {
    moveRightForward();
  }
  if (m == 1) {
    moveLeftForward();
  }
  if (m == 8) {
    moveRightBackward();
  }
  if (m == 6) {
    moveLeftBackward();
  }
  if (m == 9) {
    rotateLeft();
  }
  if (m == 10) {
    rotateRight();
  }

  if (m == 0) {
    stopMoving();
  }
  //Serial.println(dataIn);
  // If button "SAVE" is pressed
  if (m == 12) {
    if (index == 0) {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW);  
        digitalWrite(in31, LOW);  
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW);  
        digitalWrite(in32, LOW);  
        digitalWrite(in42, LOW); 

    }


    // save position into the array 
  }
  //if (m == 14) {
   // runSteps();
    //if (dataIn != 14) {
      //stopMoving();
      // Clear the array data to 0
   // }
  //}

}

//method to read the array from what was saved by the save button and run it step by step
//void runSteps() {}

void moveForward() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW);
        Serial.println("Motor: move Forward");
}

void moveBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);
        Serial.println("Motor: move Backward");
}

void moveSidewaysLeft() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW);
        Serial.println("Motor: move Sideways Left");
}
void moveSidewaysRight() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);   
        Serial.println("Motor: move Sideways right");
}

void moveRightForward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move Right Forward");
}


void moveLeftBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move left Back ward");
}

void moveLeftForward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW);   
        Serial.println("Motor: move Left Forward");
}

void moveRightBackward() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH);   
        Serial.println("Motor: move Right Backward");
}

void rotateLeft() {
        digitalWrite(in11, HIGH); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, HIGH); 
        digitalWrite(in12, HIGH); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, HIGH); 
        Serial.println("Motor: rotate Left");
  }

void rotateRight() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, HIGH); 
        digitalWrite(in31, HIGH); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, HIGH); 
        digitalWrite(in32, HIGH); 
        digitalWrite(in42, LOW); 
        Serial.println("Motor: rotate Right");
  }

void stopMoving() {
        digitalWrite(in11, LOW); 
        digitalWrite(in21, LOW); 
        digitalWrite(in31, LOW); 
        digitalWrite(in41, LOW); 
        digitalWrite(in12, LOW); 
        digitalWrite(in22, LOW); 
        digitalWrite(in32, LOW); 
        digitalWrite(in42, LOW); 
        Serial.println("Motor: off");
  }
</code></pre>
 42015: <p>As I understood it from your comments, your aim is not really to store the actual positions of the wheels or your robot, but to save and repeat the actions, that the robot did. (Meaning you don't have a "position" here, but only a measurement of wheel speed)</p>

<p>If that is true, then you can save this in a 2-dimensional array with the element form <code>{speed_wheel_1, speed_wheel2, duration}</code>. So each action is defined by the speeds of both wheels and the duration of the action, for example:</p>

<pre><code>Driving forward at full speed for 3s, turn on the spot to the left with half speed for 1.5s, drive a curve with motor left full speed and motor right half speed for 5s
</code></pre>

<p>This would translate to the following elements:</p>

<pre><code>{100, 100, 3000}
{-50, 50, 1500}
{100, 50, 5000}
</code></pre>

<p>The speeds have to be read in percent here and the durations in milliseconds.</p>

<hr>

<p>Obviously you are controlling the robot over serial. I don't completely understand your code (also as you didn't show us the full code), so I will give some hints, how you can go on from here:</p>

<p>You are obtaining the speeds from serial into the variable <code>wheelSpeed</code>. We cannot see, how you are using this variable later, but you can use it in some way to set the speed fields of a new array element.</p>

<p>Then you need the duration. The Arduino framework has a function for that: <code>millis()</code>. It will return the number of milliseconds since the startup, much like a clock. When an action starts (when the corresponding serial command is received), you have to set a timestamp:</p>

<pre><code>unsigned long timestamp;
...
timestamp = millis();
</code></pre>

<p>When the action ends (either because it actually only had a limited duration, or because another command is received), you calculate the difference between the current millis value and the timestamp. This is the duration.</p>

<p>So the corresponding code parts will look like this:</p>

<pre><code>unsigned long timestamp = 0; // Define timestamp at global scope
unsigned int current_element = 0; // A variable to keep track of the current array element
int actions[10][3]; // Array to hold up to 10 actions

void start_action(byte speed_left, byte speed_right){
    actions[current_element][0] = speed_left;
    actions[current_element][1] = speed_right;
    timestamp = millis();
    // Start the action with the provided speeds here
}

void end_action(unsigned int element_index){
    actions[current_element][2] = millis() - timestamp;
    current_element++;
    if(current_element &gt;= 10){
        // Do something to prevent more actions. Maybe just disable recording.
}
</code></pre>

<p>For repeating the actions, you just have to cycle over the array and set the corresponding speeds for the corresponding time.</p>

<p>If you want to go fancy, you can ditch the 2-dimensional array and instead define a struct for an action:</p>

<pre><code>struct Action{
    int speed_left;
    int speed_right;
    unsigned long duration;
};
</code></pre>

<p>Then you can create a simple array of the <code>Action</code> objects and reference the fields by name:</p>

<pre><code>Action actions[10];
...
actions[1].duration = millis() - timestamp;
</code></pre>
