Koepel:
Bak81, I have to agree with aarg.
The problem is the Serial.readString(). I tested the sketch in Tinkercad and it worked. Somehow the Serial input of Tinkercad works better together with the Serial.readString().
We don't use the Serial.readString(), readBytesUntil() and so on, because it is not well defined if the result is a zero-terminated string and how it behaves when the buffer is full.
When you send a command, it can be "red", but there can be a linefeed and/or carriage return after it. For example "red\r\n".
When only sending "red" as three bytes 'r', 'e', 'd', then you have to rely on a timeout to detect that nothing else will follow.
A good sketch should detect the linefeed and/or carriage return and also have a timeout.
When you set the baudrate in the sketch to 9600, then you should also set the serial monitor to 9600 baud.
Can you test this ?
I have only tested it in Tinkercad 
const int redLed = 6; // set pin 6 to red LED
const int greenLed = 10; // set pin 10 to green LED
const int blueLed = 11; // set pin 11 to blue LED
String colorChoice; // variable for holding user input
unsigned long previousMillis; // for timeout
void setup()
{
Serial.begin(9600); //Open serial port to 9600baud
//setup outputs
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
Serial.println("Please choose your color. (red, green, blue, cyan, purple, magenta or yellow )"); //Prombt user for color
}
void loop()
{
bool processColor = false;
if( Serial.available() > 0)
{
int inChar = Serial.read();
previousMillis = millis(); // timestamp the last received character
if( inChar == '\n' || inChar == '\r' || inChar == '\0' || inChar == -1)
{
// Ignore the received character.
// If something valid was received before, then start processing it.
if( colorChoice.length() > 0)
{
processColor = true;
}
}
else
{
// The received byte is probably good data, add it to the others.
colorChoice += (char) inChar;
}
}
if( colorChoice.length() > 0) // busy with receiving data ?
{
if( millis() - previousMillis >= 200) // nothing for 200 ms ?
{
processColor = true; // start processing the data that was received up to now
}
}
if( processColor)
{
Serial.println(colorChoice); // for checking the input
if (colorChoice=="red")
{
analogWrite(redLed, 255);
analogWrite(greenLed, 0);
analogWrite(blueLed, 0);
}
else if (colorChoice =="green")
{
analogWrite(redLed, 0);
analogWrite(greenLed, 255);
analogWrite(blueLed, 0);
}
else if (colorChoice =="blue")
{
analogWrite(redLed, 0);
analogWrite(greenLed, 0);
analogWrite(blueLed, 255);
}
else if (colorChoice =="cyan")
{
analogWrite(redLed, 0);
analogWrite(greenLed, 255);
analogWrite(blueLed, 255);
}
else if (colorChoice == "purple" )
{
analogWrite(redLed, 128);
analogWrite(greenLed, 0);
analogWrite(blueLed, 128);
}
else if (colorChoice =="magenta")
{
analogWrite(redLed, 255);
analogWrite(greenLed, 0);
analogWrite(blueLed, 255);
}
else if (colorChoice=="yellow")
{
analogWrite(redLed, 255);
analogWrite(greenLed, 255);
analogWrite(blueLed, 0);
}
else
{
//no correct input from user
Serial.println(""); //print blank line
Serial.println("No valid color"); //Inform user about wrong input.
Serial.println(""); //print blank line
}
colorChoice = ""; // clear the line
}
}
The more I look at this sketch, the worse it is. Someone could keep on sending serial data, causing the heap to fill and crash the Arduino board. It would be better not to use the String object and use a normal array as buffer and check for overflow.
The code works perfect. But now it is way of how this teacher, toptechboy was doing it. I can see I have to read up on some of the codes you used. I want to understand them and know the exactly meaning of them, so I can use them myselve in a given situation.
Thank you for your time and help