Problem reading exactly 3 bytes from serial monitor

Hello,

I am trying to get Arduino to read 3 characters input from the serial monitor. The goal is to have the user type in a 3 character message, such as ABC, and have Arduino read these characters from the buffer and save them to variables called byte1, byte2, and byte3. I then want to execute different code based on what the message is. However, if I type ABC in the serial monitor, Serial.available() does not return 3. I am fairly new to Arduino, and perhaps I am not understanding the various variable types.

Here is my code:

byte byte1;
byte byte2;
byte byte3;



void setup(){
  
  //Initialize serial communication
  Serial.begin(9600);
 }
  
void loop() {
  
  //Read Buffer
  if (Serial.available()== 3) {
    
    //Read buffer, store each byte to a variable
    byte1 = Serial.read();
    delay(100);
    byte2 = Serial.read();
    delay(100);
    byte3 = Serial.read();
  }
  
}

Any suggestions?

Thanks :slight_smile:

Why wait waste 90-odd character periods between reading characters?

However, if I type ABC in the serial monitor,

Serial monitor doesn't send anything until you hit "send", and then it may send more than you typed, depending on how "line-endings" is set.
If you want to read a character as it is sent, use a proper terminal emulator.

if (Serial.available()== 3) {

try

if (Serial.available() >= 2) {