Read from serial imput more than 1 character

Hello

I need to read from serial input numbers of two or more digits but in Monitor Serie when I introduce 2 numbers I get separated character.
I want to read for example: 32 and use switch case to test.
Can you help me, please?
thank you

this is the code from Arduino example.

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

Read the updated Serial Input Basics thread for ideas.

Many thanks :slight_smile:

After uploading the sketch, you entered 32 in the InputBox of the Serial Monitor and then clicked on the Send button. You have got the following responses on the OutputBox of the Serial Monitor:

I received: 51
I received: 50

You got the above responses which are correct, and they are exactly what you have wanted.

1. You entered 32 and clicked on Send button.

2. The ASCII code of 3 which is 0x33 got transmitted to the UNO.

3. UNO received it and sent back the decimal value of it (0x33 = 3x161 + 3x160 = 51) in two frames (0x35, 0x31) to the Serial Monitor. As a result, the text – I received: 51 has appeared on the OutputBox of the Serial Monitor.

4. The ASCII code of 2 which is 0x32 got transmitted to the UNO.

5. UNO received it and sent back the decimal value of it (0x32 = 3x161 + 2x160 = 50) in two frames (0x35, 0x30) to the Serial Monitor. As a result, the text – I received: 50 has appeared on the OutputBox of the Serial Monitor.

I have just explained why are you seeing 51 and 50.

Do you want to see exactly 32? (Your question is not clear to me.)