             // now I have to add sensors one by one
             int j = i + 3;
             while (j < str_length){
-              if (tmp_str[i] == 'P' || tmp_str[i] == 'p'){
+              if (tmp_str[j] == 'P' || tmp_str[j] == 'p'){
                 int sensor_index;
                 sscanf(tmp_str + j + 1, "%d", &sensor_index);
                 motors_control.add_sensor(motor_index, POTENTIOMETER, sensor_index);

            //Serial.print(infrareds_control.get_infrared_value(sensor_index));
            i++;
          }
    }
    else
      i++;
  }
}
//--------------------------------------------------------------------------------------------
//Main loop
void loop() {
  
  if (!is_command_running && (Serial.available() || current_buffer[0])) {
    int num_read = 0;
    char arduino_buffer[65];

  Serial.println(F("Bx# // Gets the status of the button x."));
  Serial.println(F("Px# // Gets the position of the potentiometer x."));
  Serial.println(F("Ix# // Gets the status of infrared sensor x."));
  Serial.println(F("G# // Prints for each motor: [sensor index, sensor type, sensor value, is whithin limits]"));
//  Serial.println(F("PL# // sets the min (lower) position for potentiometer x."));
//  Serial.println(F("PU# // sets the max (upper) position for potentiometer x."));
  
