How tell Arduino to wait for Serial to be available before continuing

Use the "Serial" and "yield" function together or in combination with a timer or a macro.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 09/28/2023 at 10:36
Last Updated on 09/28/2023 at 11:21
<p>A flower that represents Arduino with the text "Wait for Serial" beneath it.</p>

Use the "Serial" and "yield" function together or in combination with a timer or a macro.

SubscribeDownload Open Source Project

There are three ways to get Arduino to wait for Serial, all of which make use of the Serial and yield functions.

Learn more about the Yield function

A | Standalone

The simplest way to tell Arduino to wait until Serial is available is to use the following line of code.

This can be inconvenient as if Serial is not found (i.e. the board is not plugged into a computer via a USB) the code will not continue.

B | With a Macro

Another way to achieve this is to define a macro that dictates if WAIT_FOR_SERIAL or DEBUG_ENABLED is enabled.

This can be inconvenient as you need to manually set the Macro to be true if you want the board to wait for Serial.

C | With a Timer

A third way to achieve this to create logic that waits for the Serial to be available for a maximum period of time before proceeding.

This is the recommended approach as it will work regardless of whether Serial can be found or not.

Looking to learn more about things you can do with Arduino ?

Search our blog to find educational content on Arduino.

Search our Blog

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe