How to send float over serial

I've had a little trouble trying to figure out how to send a float value from the serial monitor to the Arduino. Right now, I'm using Serial.parseFloat(), but that drops the decimal point, which doesn't help. I've heard of people using dtostrf() or ftoa(), but those are for the Arduino sending data, not receiving. Is there some way to count the digits before the decimal point, and then add the ones after?

One of the examples in serial input basics should be suitable. There is also a parse example.

...R

Right now, I'm using Serial.parseFloat(), but that drops the decimal point, which doesn't help.

That seems highly unlikely.

Where IS your code that proves that assertion?

I tried the value 0.750 in Serial.print(Serial.parseFloat()), and it came up with 750, which is my basis for saying that. The program is a resistor calculator which calculates the resistor values for a given ratio - it probably has lots of other bugs as well :slight_smile: Here it is:

float percent01[] PROGMEM = {1.00, 1.01, 1.02, 1.04, 1.05, 1.06, 1.07, 1.09, 1.10, 1.11, 1.13, 1.14, 
                             1.15, 1.17, 1.18, 1.20, 1.21, 1.23, 1.24, 1.26, 1.27, 1.29, 1.30, 1.32, 
                             1.33, 1.35, 1.37, 1.38, 1.40, 1.42, 1.43, 1.45, 1.47, 1.49, 1.50, 1.52, 
                             1.54, 1.56, 1.58, 1.60, 1.62, 1.64, 1.65, 1.67, 1.69, 1.72, 1.74, 1.76, 
                             1.78, 1.80, 1.82, 1.84, 1.87, 1.89, 1.91, 1.93, 1.96, 1.98, 2.00, 2.03, 
                             2.05, 2.08, 2.10, 2.13, 2.15, 2.18, 2.21, 2.23, 2.26, 2.29, 2.32, 2.34, 
                             2.37, 2.40, 2.43, 2.46, 2.49, 2.52, 2.55, 2.58, 2.61, 2.64, 2.67, 2.71,
                             2.74, 2.77, 2.80, 2.84, 2.87, 2.91, 2.94, 2.98, 3.01, 3.05, 3.09, 3.12, 
                             3.16, 3.20, 3.24, 3.28, 3.32, 3.36, 3.40, 3.44, 3.48, 3.52, 3.57, 3.61,
                             3.65, 3.70, 3.74, 3.79, 3.83, 3.88, 3.92, 3.97, 4.02, 4.07, 4.12, 4.17, 
                             4.22, 4.27, 4.32, 4.37, 4.42, 4.48, 4.53, 4.59, 4.64, 4.70, 4.75, 4.81, 
                             4.87, 4.93, 4.99, 5.05, 5.11, 5.17, 5.23, 5.30, 5.36, 5.42, 5.49, 5.56, 
                             5.62, 5.69, 5.76, 5.83, 5.90, 5.97, 6.04, 6.12, 6.19, 6.26, 6.34, 6.42, 
                             6.49, 6.57, 6.65, 6.73, 6.81, 6.90, 6.98, 7.06, 7.15, 7.23, 7.32, 7.41, 
                             7.50, 7.59, 7.68, 7.77, 7.87, 7.96, 8.06, 8.16, 8.25, 8.35, 8.45, 8.56, 
                             8.66, 8.76, 8.87, 8.98, 9.09, 9.20, 9.31, 9.42, 9.53, 9.65, 9.76, 9.88 };





float percent1[] PROGMEM = {1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 
                            1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 
                            1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.00, 2.10, 2.15, 2.21, 2.26, 2.32, 
                            2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 
                            3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 
                            4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 
                            5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 
                            7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76 }; 
                           
                           
float percent2[] PROGMEM = {1.00, 1.05, 1.10, 1.15, 1.21, 1.27, 1.33, 1.40, 1.47, 1.54, 1.62, 1.69, 
                            1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49, 2.61, 2.74, 2.87, 3.01, 
                            3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 
                            5.62, 5.90, 6.19, 6.49, 6.81, 7.15, 7.50, 7.87, 8.25, 8.66, 9.09, 9.53 };


float percent5[] PROGMEM = {1.00, 1.10, 1.20, 1.30, 1.50, 1.60, 1.80, 2.00, 2.20, 2.40, 2.70, 3.00, 
                            3.00, 3.60, 3.90, 4.30, 4.70, 5.10, 5.60, 6.20, 6.80, 7.50, 8.20, 9.10 };


float resistors[2];
float last_error = 10;
float ratio;



void setup(){
  
  Serial.begin(9600);
  
  Serial.println("Resistor ratio calculator v1.0\n\n");
  
   
  Serial.println("To start, enter the desired ratio of R1/R2\n");
  
  while(!Serial.available());
  ratio = Serial.parseFloat() / 1000;
  
  
  Serial.println("Then enter the tolerance of the resistors you want to\n use (tolerances of 0.1, 0.25, 0.5, 1, 2, and 5 percent are accepted)\n");
  
  while(!Serial.available());
  float tolerance = Serial.parseFloat() / 1000;
  
  if(tolerance != 0.1 || tolerance != .25 || tolerance != 0.25 || tolerance != 1 || tolerance != 5){
    Serial.println("Tolerance value not accepted");
    while(true);
  }
  
  Serial.println("Enter a character to begin calculation\n\n");
  
  while(!Serial.available());
  
  Serial.println("Calculating (could take up to 2 minutes)...\n\n");
  
 
  if(tolerance == 0.1 || tolerance == 0.25 || tolerance == 0.5){
        
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 192; i++){
        
          for(int j = i + 1; j < 192; j++){
        
            if(abs(((percent01[i] * ki) / (percent01[j] * kj)) - ratio) < last_error){
              last_error = ((percent01[i] * ki)/ (percent01[j]) * kj) - ratio;
              resistors[1] = percent01[i] * ki;
              resistors[2] = percent01[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 1){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 96; i++){
        
          for(int j = i + 1; j < 96; j++){
        
            if(abs(((percent1[i] * ki) / (percent1[j] * kj)) - ratio) < last_error){
              last_error = ((percent1[i] * ki)/ (percent1[j]) * kj) - ratio;
              resistors[1] = percent1[i] * ki;
              resistors[2] = percent1[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 2){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 48; i++){
        
          for(int j = i + 1; j < 48; j++){
        
            if(abs(((percent2[i] * ki) / (percent2[j] * kj)) - ratio) < last_error){
              last_error = ((percent2[i] * ki)/ (percent2[j]) * kj) - ratio;
              resistors[1] = percent2[i] * ki;
              resistors[2] = percent2[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 5){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 24; i++){
        
          for(int j = i + 1; j < 24; j++){
        
            if(abs(((percent5[i] * ki) / (percent5[j] * kj)) - ratio) < last_error){
              last_error = ((percent5[i] * ki) / (percent5[j]) * kj) - ratio;
              resistors[1] = percent5[i] * ki;
              resistors[2] = percent5[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
       
  Serial.println("Calculation complete!\n");
  
  Serial.print("Target ratio: ");
  Serial.println(ratio);
  Serial.print("Actual ratio: ");
  Serial.println(ratio + last_error);
  Serial.print("R1 = ");
  Serial.println(resistors[1], 2);
  Serial.print("R2 = ");
  Serial.println(resistors[2], 2);
  Serial.print("Error: ");
  Serial.print(100 - ((100 * ratio) / (ratio + last_error)), 2);
  Serial.println("%\n");
  
}

void loop(){}

parseFloat() and parseInt() should be taken out and shot. They really aren’t very useful for anything. Writing your own parsing routine will help you understand so much more about what the microprocessor is really doing.

I was able to get it to work by replacing each of your while(!Serial.available()); with the following code:

    c = Serial.peek();
    while((c<'0' || c>'9') && c!='-' && c!='.') {
      Serial.read(); //strip any non-numeric chars
      while(Serial.available()==0);
      c = Serial.peek();
    }

The reason why this is necessary is if you have other characters like a newline (enter key) then you need to get rid of them before letting parseFloat() see the serial stream.

I fixed a few more bugs and improved the interface so now it can at least get to the calculation part.

float percent01[] PROGMEM = {1.00, 1.01, 1.02, 1.04, 1.05, 1.06, 1.07, 1.09, 1.10, 1.11, 1.13, 1.14, 
                             1.15, 1.17, 1.18, 1.20, 1.21, 1.23, 1.24, 1.26, 1.27, 1.29, 1.30, 1.32, 
                             1.33, 1.35, 1.37, 1.38, 1.40, 1.42, 1.43, 1.45, 1.47, 1.49, 1.50, 1.52, 
                             1.54, 1.56, 1.58, 1.60, 1.62, 1.64, 1.65, 1.67, 1.69, 1.72, 1.74, 1.76, 
                             1.78, 1.80, 1.82, 1.84, 1.87, 1.89, 1.91, 1.93, 1.96, 1.98, 2.00, 2.03, 
                             2.05, 2.08, 2.10, 2.13, 2.15, 2.18, 2.21, 2.23, 2.26, 2.29, 2.32, 2.34, 
                             2.37, 2.40, 2.43, 2.46, 2.49, 2.52, 2.55, 2.58, 2.61, 2.64, 2.67, 2.71,
                             2.74, 2.77, 2.80, 2.84, 2.87, 2.91, 2.94, 2.98, 3.01, 3.05, 3.09, 3.12, 
                             3.16, 3.20, 3.24, 3.28, 3.32, 3.36, 3.40, 3.44, 3.48, 3.52, 3.57, 3.61,
                             3.65, 3.70, 3.74, 3.79, 3.83, 3.88, 3.92, 3.97, 4.02, 4.07, 4.12, 4.17, 
                             4.22, 4.27, 4.32, 4.37, 4.42, 4.48, 4.53, 4.59, 4.64, 4.70, 4.75, 4.81, 
                             4.87, 4.93, 4.99, 5.05, 5.11, 5.17, 5.23, 5.30, 5.36, 5.42, 5.49, 5.56, 
                             5.62, 5.69, 5.76, 5.83, 5.90, 5.97, 6.04, 6.12, 6.19, 6.26, 6.34, 6.42, 
                             6.49, 6.57, 6.65, 6.73, 6.81, 6.90, 6.98, 7.06, 7.15, 7.23, 7.32, 7.41, 
                             7.50, 7.59, 7.68, 7.77, 7.87, 7.96, 8.06, 8.16, 8.25, 8.35, 8.45, 8.56, 
                             8.66, 8.76, 8.87, 8.98, 9.09, 9.20, 9.31, 9.42, 9.53, 9.65, 9.76, 9.88 };





float percent1[] PROGMEM = {1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 
                            1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 
                            1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.00, 2.10, 2.15, 2.21, 2.26, 2.32, 
                            2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 
                            3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 
                            4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 
                            5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 
                            7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53, 9.76 }; 
                           
                           
float percent2[] PROGMEM = {1.00, 1.05, 1.10, 1.15, 1.21, 1.27, 1.33, 1.40, 1.47, 1.54, 1.62, 1.69, 
                            1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49, 2.61, 2.74, 2.87, 3.01, 
                            3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 
                            5.62, 5.90, 6.19, 6.49, 6.81, 7.15, 7.50, 7.87, 8.25, 8.66, 9.09, 9.53 };


float percent5[] PROGMEM = {1.00, 1.10, 1.20, 1.30, 1.50, 1.60, 1.80, 2.00, 2.20, 2.40, 2.70, 3.00, 
                            3.00, 3.60, 3.90, 4.30, 4.70, 5.10, 5.60, 6.20, 6.80, 7.50, 8.20, 9.10 };


float resistors[2];
float last_error = 10;
float ratio;



void setup(){
  char c;
  float tolerance=0;
  
  Serial.begin(9600);
  
  Serial.println("Resistor ratio calculator v1.0\n\n");
  
  do { 
    Serial.println("To start, enter the desired ratio of R1/R2\n");
    
    c = Serial.peek();
    while((c<'0' || c>'9') && c!='-' && c!='.') {
      Serial.read(); //strip any non-numeric chars
      while(Serial.available()==0);
      c = Serial.peek();
    }
    ratio = Serial.parseFloat();// / 1000;
    
    Serial.print("OK, I got: ");
    Serial.println(ratio);
    
    
    Serial.println("Then enter the tolerance of the resistors you want to\n use (tolerances of 0.1, 0.25, 0.5, 1, 2, and 5 percent are accepted)\n");
  
    c = Serial.peek();
    while((c<'0' || c>'9') && c!='-' && c!='.') {
      Serial.read(); //strip any non-numeric chars
      while(Serial.available()==0);
      c = Serial.peek();
    }
    tolerance = Serial.parseFloat();// / 1000;
    
    if(tolerance != 0.1 && tolerance != .25 && tolerance != 0.25 && tolerance != 1 && tolerance != 5){
      Serial.print("Tolerance value ");
      Serial.print(tolerance);
      Serial.println(" not accepted\n\n");
    }
  } while (tolerance != 0.1 && tolerance != .25 && tolerance != 0.25 && tolerance != 1 && tolerance != 5);
  
  Serial.println("Calculating (could take up to 2 minutes)...\n\n");
  
 
  if(tolerance == 0.1 || tolerance == 0.25 || tolerance == 0.5){
        
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 192; i++){
        
          for(int j = i + 1; j < 192; j++){
        
            if(abs(((percent01[i] * ki) / (percent01[j] * kj)) - ratio) < last_error){
              last_error = ((percent01[i] * ki)/ (percent01[j]) * kj) - ratio;
              resistors[1] = percent01[i] * ki;
              resistors[2] = percent01[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 1){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 96; i++){
        
          for(int j = i + 1; j < 96; j++){
        
            if(abs(((percent1[i] * ki) / (percent1[j] * kj)) - ratio) < last_error){
              last_error = ((percent1[i] * ki)/ (percent1[j]) * kj) - ratio;
              resistors[1] = percent1[i] * ki;
              resistors[2] = percent1[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 2){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 48; i++){
        
          for(int j = i + 1; j < 48; j++){
        
            if(abs(((percent2[i] * ki) / (percent2[j] * kj)) - ratio) < last_error){
              last_error = ((percent2[i] * ki)/ (percent2[j]) * kj) - ratio;
              resistors[1] = percent2[i] * ki;
              resistors[2] = percent2[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
  else if(tolerance == 5){
    
    for(long ki = 1; ki < 100000001; ki *= 10){
      
      for(long kj = ki; kj < 10000001; kj *= 10){
      
        for(int i = 0; i < 24; i++){
        
          for(int j = i + 1; j < 24; j++){
        
            if(abs(((percent5[i] * ki) / (percent5[j] * kj)) - ratio) < last_error){
              last_error = ((percent5[i] * ki) / (percent5[j]) * kj) - ratio;
              resistors[1] = percent5[i] * ki;
              resistors[2] = percent5[j] * kj;
            }
          }
        }
      }
    }
  }
  
  
       
  Serial.println("Calculation complete!\n");
  
  Serial.print("Target ratio: ");
  Serial.println(ratio);
  Serial.print("Actual ratio: ");
  Serial.println(ratio + last_error);
  Serial.print("R1 = ");
  Serial.println(resistors[1], 2);
  Serial.print("R2 = ");
  Serial.println(resistors[2], 2);
  Serial.print("Error: ");
  Serial.print(100 - ((100 * ratio) / (ratio + last_error)), 2);
  Serial.println("%\n");
  
}

void loop(){}

Hi CWashburn,

*I tried the value 0.750 in Serial.print(Serial.parseFloat()), and it came up with 750, which is my basis for saying that. The program is a resistor calculator which calculates the resistor values for a given ratio - it probably has lots of other bugs as well :slight_smile: *

If you want to print the float value 0.750 via Serial Port exactly. Try this:

  • Define a character array buffer from the start(Ex: char buffer [100]:wink:
    The array number will depend on how many decimal places are expected to print.
    You can define how many decimal places.
  • include the header file name at the start along with your libraries written like this:
    #include ‚ÄúfloatToString.h‚ÄĚ
  • Add this library attached on this message (floatToString.h).
    Do this by accessing, Sketch Tab---->Add file. Add (floatToString.h)
  • After doing this, print the desired float value via Serial Port with this syntax:
    Serial.print(floatToString(buffer,‚Äúfloat variable name‚ÄĚ,3));
    The number is to adjust the decimal places.

Best Regards,
Leo

floatToString.h (2.98 KB)

That would be useful for output, but it appears that the OP‚Äôs problem is how he can get a ‚Äúfloat‚ÄĚ from the serial monitor, (which I assume he intended to manually type on the screen ), into the Arduino.

My answer would be, it depends. It depends on what else you expect to be typing into the screen. It also depends on whether you want the arduino to wait indefinitely while you are typing the number in, or if you want it to control something else, as well.

A simple function which will wait for a float input, and won’t return until it gets some kind of line end, could look like this

bool getFloat( float* f )
{
    int f1=0 ;
    int f2=0 ;
    int mul=1 ;
    bool gotdp=false;
    bool gotminus=false ;
    while ( true )
    {
        if ( Serial.available() > 0 )
        {
            int c = Serial.read() ;
            if ( c >='0' && c<='9' )
            {
                  if ( gotdp ) 
                  {
                        f2=(10*f2)+(c-'0');
                        mul*=10 ;
                  }
                  else           f1=(10*f1)+(c-'0');
            }
            else if ( c == '.' )  gotdp=true ;
            else if ( c == '-')   gotminus=true ;
            else if ( c == '\r' || c=='\n' )
             {
                   float res = ( float ) f1 ;
                   if ( f2 != 0 )  res += ((float)f2)/((float)mul) ;
                   if ( gotminus ) res=-res ;
                   *f = res ;
                    return true ;
             }
             else
             { 
                  // ignore anything else
             }
         }

    }

}

which you would call by

float f ;
bool b ;
b = getFloat( &f );
if ( b )
{
    // do something using f
}
else
{
    Serial.println("getFloat( ) failed");
}

This:

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Serial.println("Enter a float");
  while(Serial.available() == 0)
  {
  }
  
  float val = Serial.parseFloat();
  Serial.print("You entered: [");
  Serial.print(val);
  Serial.println("]");
}

Does EXACTLY what it is supposed to, with respect to entering and printing floats.

1 Like

Thanks for everyone's input! Would something to this effect work?

float readFloat(){
  
  float a = 0;
  float b = 0;
  
  while(Serial.peek() != '.'){
    a = (a * 10) + Serial.read();
  }
  
  Serial.read();
  
  while(Serial.peek() != -1){
    b = (b * 10) + Serial.read();
  }
  
  while(b >= 1){
    b /= 10;
  }
  
  return a + b;
}

No, because the serial data coming in is very very very very slow. Your processor can do literally hundreds of thousands of calculations between each serial character. You need to wait for each character and then you need some kind of terminator (like newline) to know when the data has all been entered..

When you say you entered "0.750" are you sure you're not typing ".750"? I suspect that parseFloat() will ignore the leading "." and then parse the rest of the number. When I tested my code, it was doing that.

I tried your code with 0.750, and it got the '0.750' part right, but all the output values overflowed.

Serial.parseInt handles the input of 0.750 just fine. The parseInt() function just requires a leading zero before the decimal point of a number less than 1. Try it with the sample code PaulS posted

I tried your code with 0.750, and it got the '0.750' part right, but all the output values overflowed.

Then, your code is wrong.

Did you try the code in the link in Reply #1 ?

...R

This adresses some of the issues:

#include <Streaming.h>
const float E192[]  = {1.00, 1.01, 1.02, 1.04, 1.05, 1.06, 1.07, 1.09, 1.10, 1.11, 1.13, 1.14, 
                       1.15, 1.17, 1.18, 1.20, 1.21, 1.23, 1.24, 1.26, 1.27, 1.29, 1.30, 1.32, 
                       1.33, 1.35, 1.37, 1.38, 1.40, 1.42, 1.43, 1.45, 1.47, 1.49, 1.50, 1.52, 
                       1.54, 1.56, 1.58, 1.60, 1.62, 1.64, 1.65, 1.67, 1.69, 1.72, 1.74, 1.76, 
                       1.78, 1.80, 1.82, 1.84, 1.87, 1.89, 1.91, 1.93, 1.96, 1.98, 2.00, 2.03, 
                       2.05, 2.08, 2.10, 2.13, 2.15, 2.18, 2.21, 2.23, 2.26, 2.29, 2.32, 2.34, 
                       2.37, 2.40, 2.43, 2.46, 2.49, 2.52, 2.55, 2.58, 2.61, 2.64, 2.67, 2.71,
                       2.74, 2.77, 2.80, 2.84, 2.87, 2.91, 2.94, 2.98, 3.01, 3.05, 3.09, 3.12, 
                       3.16, 3.20, 3.24, 3.28, 3.32, 3.36, 3.40, 3.44, 3.48, 3.52, 3.57, 3.61,
                       3.65, 3.70, 3.74, 3.79, 3.83, 3.88, 3.92, 3.97, 4.02, 4.07, 4.12, 4.17, 
                       4.22, 4.27, 4.32, 4.37, 4.42, 4.48, 4.53, 4.59, 4.64, 4.70, 4.75, 4.81, 
                       4.87, 4.93, 4.99, 5.05, 5.11, 5.17, 5.23, 5.30, 5.36, 5.42, 5.49, 5.56, 
                       5.62, 5.69, 5.76, 5.83, 5.90, 5.97, 6.04, 6.12, 6.19, 6.26, 6.34, 6.42, 
                       6.49, 6.57, 6.65, 6.73, 6.81, 6.90, 6.98, 7.06, 7.15, 7.23, 7.32, 7.41, 
                       7.50, 7.59, 7.68, 7.77, 7.87, 7.96, 8.06, 8.16, 8.25, 8.35, 8.45, 8.56, 
                       8.66, 8.76, 8.87, 8.98, 9.09, 9.20, 9.31, 9.42, 9.53, 9.65, 9.76, 9.88 };
float R1;//for calculations
float R2;//for calculations
float R1f;//found/final value
float R2f;//found/final value

float error;
float last_error = 10;
float ratio;
char inBuffer[50];//input buffer
int stepLength;

void setup(){  
  Serial.begin(115200);
  Serial<<("Resistor ratio calculator v1.0\n\nTo start, enter the desired ratio of R1/R2")<<endl;
  readBuffer();
  ratio = atof(inBuffer);
  if(ratio>1.0) Serial<<"ratio>1, using inverted value: "<<(ratio=1/ratio)<<endl;
  Serial<<"Then enter the resistor E-series number 24|48|96|192"<<endl;
  readBuffer();
  stepLength = 192/atoi(inBuffer);
  switch(stepLength){
    case 1:
    case 2:
    case 4:
    case 8: break;
    default: 
      Serial<<("series not recognized, using default E24")<<endl;
      stepLength = 8;
  }//switch(steplength)
  Serial<<("Calculating (could take up to 2 minutes)...")<<endl;
  //iterate through all values an find smallest error
    for(long kj = 1; kj<10000001; kj*=10){
      for(int i = 0; i <192; i+=stepLength){
        R1 = E192[i];
        for(int j = i+stepLength; j<192; j+=stepLength){
          R2 = E192[j];
          error = abs(R1/R2*kj-ratio);     
          if(error < last_error){
            last_error = error;
            R1f = R1;
            R2f = R2;
          }//if(error<lasterror)
        }//for(j)
      }//for(i)
    }//for(kj)
  Serial<<("Calculation complete!")<<endl;
  Serial<<("Target ratio: ")<<(ratio)<<endl;
  Serial<<("Actual ratio: ")<<(R1f/R2f)<<endl;
  Serial<<("R1 = ")<<R1f<<endl;
  Serial<<("R2 = ")<<R2f<<endl;
  Serial<<("Error: ")<<(last_error*100.0)<<("%\n")<<endl;
}//setup()

void loop(){}

void readBuffer(){
  int i = 0;
  int done = 0;
  while(!done){
    char c = Serial.read();//get character from serial buffer
    if(c !=-1) inBuffer[i++] = c;//store character if available
    done = (c=='\n')||i>=48;//read until newline or full buffer
  }//while(!done)
  inBuffer[i] = 0;//place termination character
}//readBuffer()
float resistors[2];
...

              resistors[1] = percent01[i] * ki;
              resistors[2] = percent01[j] * kj;
...
              resistors[1] = percent1[i] * ki;
              resistors[2] = percent1[j] * kj;
...
  Serial.println(resistors[1], 2);
  Serial.print("R2 = ");
  Serial.println(resistors[2], 2);

This is all wrong. Arrays in C start at zero. Index 2 is not defined here.

http://www.gammon.com.au/serial

Oops, I knew that. :)