Hi all, this is my first post here. I'm using an Arduino Uno and I've been experimenting with the USB COM connection usng the Serial class, and it seems to be manageable so far. Now I'm wondering if there is a way to detect if the USB is disconnected (assuming I have an external source that powers the Uno board)?

It seems like there is no way to do it using the Serial class, short of requiring some sort of a heartbeat or querying the host. Does anyone have any wisdom to share?

It seems like there is no way to do it using the Serial class, short of requiring some sort of a heartbeat or querying the host.

You're right. There isn't. Typically, though, opening and closing the serial port, by an application on the PC, resets the Arduino. So, your heartbeat/query can be done in setup(), not continuously in loop(). Unless you've modified your Arduino to not reset on serial port connections.

Hi Paul, sorry it took me a while to test this, You are right in that properly closing the serial port (e.g. closing the serial monitor) will reset the board, but I seem to observe a different behavior when I just unplug the USB plug from on my stock Uno board.

With a separate power supply, unplugging the USB cable seems to not reset the board and the loop continues to run. However, I did notice that if I plug in the USB again, then the board is automatically reset.