user86271: I am newbie in Arduino and writing a program where I want to control the flow by using Serial monitor input (PI controller).
I've read that using String() although easier it is slower than using char. But to use char I would need more lines of code to convert the input into a string for comparison and more knowledge to make the program robust. For the control I will enter small strings like Ramp, Increase, Decrease, Lock, Stop and any other inputs will not be used. Generally, there are not going to be much inputs. The strings are basically going to be put into if-statements leading to functions.
if(Serial.available()){

string = Serial.readString() 
or some function to read out all the bytes of the string and return a char containing it;

if(string="Ramp") {
do_this();
}
else_if(string="Increase"){
do_that()
}
//If nothing matches, continue with code.
}

Since I need to finish this project soon, I am wondering if it's going to increase the loop time significantly if I use String() or I shouldn't bother learning and using char right now (at a later stage, for sure).

user42015: Yes, String has a bit more overhead than plain c-strings (aka char arrays), though the additional execution time will be way too small for you to notice (especially when you type the commands in by hand).
It will be no problem to use String in your sketch, though you should do it right and use String.reserve() to allocate enough memory space in the String object to hold the longest string, that you have. Also don't just add Strings together. That way you can avoid memory fragmentation (effectively making swiss cheese out of your RAM) and still use String.
Though when you are not in a hurry anymore, learning how to use c-strings will be worthwhile.

user7508: Using Serial.readString() will make your program very slow. This is
because readString() does not know when to stop reading. When the
serial input buffer gets empty, it will wait just in case more
characters may come later. Only when it times out does it return the
string that it could read. The default timeout is one second, so your
program will be unresponsive for a full second after receiving a command
and before acting on it.
You can shorten the timeout using Serial.setTimeout(), but this may
make your program harder to test interactively by typing commands on a
terminal emulator.
I recommend you add a terminating character (say, '\n') to each of
your messages, then replace Serial.readString() with
Serial.readStringUntil(). This method will return immediately when it
finds the terminating character. Note that this character will not
appear on the returned string object. readStringUntil() also obeys a
timeout, but only when it cannot find the terminating character.
Or you can learn the clean way to read Serial on the Arduino.
Yes, it is a bit harder, but not a horrible thing to do.

86271: <p>I am newbie in Arduino and writing a program where I want to control the flow by using Serial monitor input (PI controller).
I've read that using String() although easier it is slower than using char. But to use char I would need more lines of code to convert the input into a string for comparison and more knowledge to make the program robust. For the control I will enter small strings like Ramp, Increase, Decrease, Lock, Stop and any other inputs will not be used. Generally, there are not going to be much inputs. The strings are basically going to be put into if-statements leading to functions.</p>
<pre><code>if(Serial.available()){

string = Serial.readString() 
or some function to read out all the bytes of the string and return a char containing it;

if(string=&quot;Ramp&quot;) {
do_this();
}
else_if(string=&quot;Increase&quot;){
do_that()
}
//If nothing matches, continue with code.
}
</code></pre>
<p>Since I need to finish this project soon, I am wondering if it's going to increase the loop time significantly if I use String() or I shouldn't bother learning and using char right now (at a later stage, for sure).</p>
 42015: <p>Yes, <code>String</code> has a bit more overhead than plain c-strings (aka <code>char</code> arrays), though the additional execution time will be way too small for you to notice (especially when you type the commands in by hand).</p>
<p>It will be no problem to use <code>String</code> in your sketch, though you should do it right and use <code>String.reserve()</code> to allocate enough memory space in the <code>String</code> object to hold the longest string, that you have. Also don't just add <code>String</code>s together. That way you can avoid memory fragmentation (effectively making swiss cheese out of your RAM) and still use <code>String</code>.</p>
<p>Though when you are not in a hurry anymore, learning how to use c-strings will be worthwhile.</p>
 7508: <p>Using <code>Serial.readString()</code> will make your program <em>very</em> slow. This is
because <code>readString()</code> does not know when to stop reading. When the
serial input buffer gets empty, it will wait just in case more
characters may come later. Only when it times out does it return the
string that it could read. The default timeout is one second, so your
program will be unresponsive for a full second after receiving a command
and before acting on it.</p>
<p>You can shorten the timeout using <code>Serial.setTimeout()</code>, but this may
make your program harder to test interactively by typing commands on a
terminal emulator.</p>
<p>I recommend you add a terminating character (say, <code>'\n'</code>) to each of
your messages, then replace <code>Serial.readString()</code> with
<code>Serial.readStringUntil()</code>. This method will return immediately when it
finds the terminating character. Note that this character will <em>not</em>
appear on the returned string object. <code>readStringUntil()</code> also obeys a
timeout, but only when it cannot find the terminating character.</p>
<p>Or you can learn the clean way to <a href="https://majenko.co.uk/blog/our-blog-1/reading-serial-on-the-arduino-27" rel="nofollow noreferrer">read Serial on the Arduino</a>.
Yes, it is a bit harder, but not a horrible thing to do.</p>
