ESP32/Setup and uploading/04. Hello world over serial
Your chip
Your language
Setup and uploading · 04 of 81

Hello world over serial

The first program that proves the board is running your code and can talk back. Two lines of setup, one line of output, and the two settings that decide whether you see any of it.

/esp32/hello-world-over-serial · arduino · S3

What the two lines do

Serial.begin(115200) starts the UART that runs over the same USB cable that powers the board. Serial.println sends characters down it. That is the whole mechanism, and for most projects it stays the only debugger you use.

The two numbers have to match

Serial Monitor, running
115200 baud
Serial.begin() in the sketch
The dropdown in the Serial Monitor
delay() in the loop1000 ms
Lines per second
1
Readable
yes
Matched, and one line a second. That is the whole of Serial.begin(115200) plus a delay — and it is the only debugger most projects ever need.

Drag the delay down and you will see the second failure, which is subtler than garbled text: the output is perfectly correct and completely unreadable, and Serial.print is now the slowest thing in your loop. At 115200 baud each character costs about 87 µs, so a forty-character line printed every pass of a tight loop is milliseconds of work the loop was supposed to be doing something else with.

Print things worth printing

millis() and ESP.getFreeHeap() cost nothing and answer the two questions you will actually have later: how long has it been up, and is something leaking. Add them to the loop of every project now and you will not have to add them at two in the morning.

A note on the first 200 ms

On boards with native USB — S3, C3, C6, P4 — the port is created by the chip itself, and it does not exist until a moment after boot. Anything printed in that window goes nowhere. The short delay after Serial.begin is not superstition; it is waiting for the host to enumerate a device that has only just appeared.

On your S3
ChipXtensa LX7 · 2 × 240 MHz
Board settingESP32S3 Dev Module
Default I2CSDA 8 · SCL 9
Watch out forThe port vanishes after upload

The code

Nine lines, no wiring. Upload it, open the Serial Monitor, set the dropdown to 115200, and a line appears every second.

hello.ino
void setup() {
  Serial.begin(115200);
  delay(200);              // let the USB serial port come up
  Serial.println("Hello, World!");
}

void loop() {
  Serial.printf("up %lu ms, heap %u\n", millis(), ESP.getFreeHeap());
  delay(1000);
}

The number in Serial.begin and the number in the Serial Monitor dropdown are two separate settings and neither knows about the other. Getting them to agree is the whole trick.

When it does not work

The monitor prints nothing at all

Either the wrong port or a board that has not been reset. Silence with a correct port usually means the sketch printed its greeting before you opened the monitor — opening the Serial Monitor resets most boards, so press EN and watch the first line arrive.

The monitor prints boxes and question marks

The two baud rates disagree. Readable-but-wrong characters are the signature of a mismatch, not of a broken board. Set both to 115200 and it clears immediately.

There is a wall of garbage before my first line

That is the ROM bootloader talking at 115200 in a fixed format before your sketch starts. It is normal. If it repeats every few seconds, it is a boot loop and the text after "rst:" names the cause.

printf prints the literal %d

Serial.printf exists on ESP32 and not on an Uno, so old sketches use Serial.print with string concatenation. Both work here; mixing the two styles in one line is what produces this.

Where this goes next

The other traditional first program, and the one that needs a resistor. Two components, one piece of arithmetic, and a GPIO that survives it.

Blink an LED

Edit this page — content/esp32/hello-world-over-serial.mdx

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse ESP32 on the forum