Source: https://mokxi.com/learn/arduino-serial-monitor-garbage

Learn

# Arduino serial monitor showing garbage, or nothing at all

Written by the Mokxi team

Start building free

Or see every lesson.

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

Click to open it in the editor

It prints hello at 9600 baud. Set the chip’s baud property to 19200 and the monitor shows garbage.

Garbage in the serial monitor, a row of question marks, boxes and stray symbols where your text should be, has one cause nine times out of ten: the monitor is listening at a different speed from the one the sketch sends at. A blank monitor has a short list of causes too. This page reproduces the ones a simulation can, and says plainly where Mokxi behaves differently from the board on your desk.

The circuit above is an ATtiny85 printing "hello from an ATtiny85" and then "up 2 s" at 9600 baud. It is here because of how its monitor works. The ATtiny85 has no serial hardware of its own, so Mokxi’s monitor for it is a USB-serial adapter clipped to its pins, set to the speed in the chip’s baud property. That is the one board in Mokxi where the monitor can be at the wrong speed, exactly as on a desk. Click the chip, set baud to 19200 and run it again: the monitor fills with garbage.

## Garbage: the baud rates do not match

A serial line has no clock wire. The sender and the receiver agree on a speed in advance, and the receiver times every bit from the moment the line first drops. If the two numbers differ, the receiver samples the bits at the wrong moments and turns them into the wrong bytes. Those bytes are rarely printable letters, so the monitor shows them as replacement marks and odd symbols.

On the ATtiny85 we ran a sketch with Serial.begin(4800) while the monitor stayed at 9600. Instead of "hello from an ATtiny85" it printed a line of � marks with a couple of stray symbols among them. We then ran the 9600 baud hello with the monitor set to 19200 and 38400, and got the same kind of garbage. With the monitor at 4800, half the speed, it showed nothing at all: every byte failed its stop bit check and the adapter dropped it, which real adapters often do too.

The fix is to make the two numbers the same. In the Arduino IDE the speed is the drop-down in the corner of the Serial Monitor; set it to the number in your Serial.begin(). 9600 and 115200 are the common choices, and 115200 is the usual one on ESP32 boards.

Send at 4800 while the monitor listens at 9600: garbage

## Where Mokxi differs: an Uno cannot be at the wrong baud

On an Uno, a Nano, a Mega or an ESP32 in Mokxi, the monitor reads the bytes straight from the chip’s serial hardware, not from the pins. There is no speed for it to get wrong: a sketch on an Uno with Serial.begin(4800) printed "hello at 4800" cleanly. That is kinder than a real board, where the same sketch with the monitor at 9600 prints garbage. So if your sketch prints clean text in Mokxi and garbage on your desk, the speed setting is the first thing to check.

Garbage between two boards is reproduced faithfully, because there the bytes really travel on pins. An HC-05 Bluetooth module set to the wrong speed fills its box with garbage, and two boards joined with SoftwareSerial at different speeds do too.

## ESP32: a burst of garbage at reset, then your text

On a real ESP32, the chip’s boot ROM prints a few lines about the reset before your sketch starts, at 115200 baud. With the monitor at 9600 they arrive as a burst of garbage, and then your own text appears normally, because your sketch set its own speed. Set your sketch and the monitor to 115200 and the boot lines become readable too. The ESP8266’s boot ROM prints at 74880, so some garbage at reset is normal there with almost any setting.

Mokxi has no boot ROM on its ESP32 boards, so the monitor starts with the first line your sketch prints. A burst of garbage at reset is one thing the simulation cannot show you.

## Blank: no Serial.begin()

On a real Uno, nothing comes out of the serial port until Serial.begin() turns it on, so a sketch that prints without calling it leaves the monitor blank, and a simulated Uno does the same: a sketch with no Serial.begin() at all printed nothing on it. An ESP32-C3 is the same: its core has no serial driver until Serial.begin() installs one, and the same sketch printed nothing there either. The Arduino Nano ESP32 and the XIAO ESP32-S3 are the exception, because their core starts the USB port before setup(), which is not something to rely on. Always start the port in setup(), and if you need to know the sketch got that far, print one line at the end of setup().

## Blank on a Leonardo, Micro or Pro Micro: while (!Serial)

These boards have no separate USB chip. The ATmega32U4 talks USB itself, and its serial port only exists once your computer has opened it. Anything printed before you open the monitor is lost, which is why sketches for them start with while (!Serial) {}: it waits until the monitor is open.

That line has a catch. On a board running from a battery or a phone charger, nothing ever opens the port, so the sketch waits forever and seems dead. In Mokxi there is no computer to enumerate the board, so while (!Serial) returns at once: a Leonardo sketch that waits on it and then prints millis() printed "ready at 0". Use a timeout on a desk, such as while (!Serial && millis() < 3000) {}.

## Blank: the other usual causes

The wrong port, or the wrong board, is selected in the IDE. Only one program can have a serial port open at a time, so a second IDE window or another serial terminal keeps the monitor from seeing anything. On an Uno, pins 0 and 1 are the same serial line as the USB port, so a module wired to them can garble or block what you print; in Mokxi those two pins stay ordinary pins and the monitor is not affected.

If the text appears once and then the same first lines appear again and again, the board is resetting. That is usually power: a motor, a servo or an ESP32’s radio pulling the supply down. Mokxi does not model a sagging supply, so a reset loop like that is a real-hardware fault.

## Questions

Why does my Arduino serial monitor show question marks and random characters?

The monitor’s baud rate does not match the number in Serial.begin(). Set the drop-down in the Serial Monitor to the same number, such as 9600 or 115200.

Why does my ESP32 print garbage when it starts?

Its boot ROM prints reset messages at 115200 before your sketch runs. At any other monitor speed they look like garbage, then your own text follows. Use 115200 in both places.

Why is my serial monitor blank?

Check that Serial.begin() is called in setup(), that the right port and board are selected, that no other program has the port open, and, on a Leonardo or Pro Micro, that the sketch waits for the port with while (!Serial).

What baud rate should I use?

Any standard speed works if both ends agree. 9600 is the classic Arduino choice and 115200 the usual ESP32 one. Faster means less time spent printing.

Related

## Keep going

UART Serial Explained: Baud, Frames and the Wire Arduino Simulator: Serial Monitor and Logic Analyzer How to Debug Arduino Code: Prints to Breakpoints Arduino HC-05 Bluetooth: Wiring, Code, AT Commands ESP32 Not Connecting to WiFi: Causes and Fixes Arduino Serial.print vs println, and Decimals Help: the serial monitor shows nothing The HC-05 Bluetooth module simulator, garbage at 4800 baud The ATtiny85 simulator

Sources

## Where the facts on this page come from

- Arduino reference: Serial.begin() and the speed both ends must share
- Arduino reference: if (Serial) on boards with native USB

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
