The first program that receives serial is just an echo: whatever the host sends to the chip, the chip sends straight back. It's not useful, but it proves the receive path works — and once that works, you can build anything that requires the chip to listen.

The receive idiom: available, then read

The Arduino runtime maintains a receive buffer that the USART fills in the background. Your code asks Serial.available() for the byte count, then Serial.read() to pop one byte. The echo loop is three lines: if (Serial.available()) { char c = Serial.read(); Serial.write(c); }. That's it.

The buffer matters because serial is asynchronous. Bytes can arrive while your sketch is doing other things. By the time you check available(), there may be one byte waiting or twenty. The standard pattern is "drain everything available each loop pass" — read in a tight while-loop until the buffer is empty.

The same idiom scales to everything

An echo is the simplest case of "read input, act on it." A line parser, a command interpreter, a JSON streamer — they're all built on the same foundation: poll available(), read a byte, accumulate into a buffer, look for a delimiter (often newline), then act when a complete message has arrived. Build that pattern in your head with echo; reuse it forever.