         // now I have to add sensors one by one
         int j = i + 4;
         i += 5;
-        while (j < str_length) {
+        int k = 0;
+        while (k < num_sensors){
           if (tmp_str[j] == 'P' || tmp_str[j] == 'p') {
             int sensor_index;
             sscanf(tmp_str + j + 1, "%d", &sensor_index);

        int motor_index, num_sensors;
        char motor_type = tmp_str[i + 1];
        sscanf(tmp_str + i + 2, "%d%d", &motor_index, &num_sensors);
        if (motor_type == 'S' || motor_type == 's') // attach to stepper motors controller
          stepper_motors_controller.set_num_attached_sensors(motor_index, num_sensors);
        else if (motor_type == 'D' || motor_type == 'd') // attach to DC motors controller

void setup()
{
  first_start = 0;
  strcpy(firmware_version, "2016.05.12.0");

  current_buffer[0] = 0;

