So I looked through the Arduino Mega2560 documentation and searched the web for a solution, and so far I haven't had any success.

What I'm trying to accomplish is fairly simple. I need to send a serial command over serial, ONLY if there is a serial connection between the PC and the Arduino. I've tried:


That doesn't work, and I think it's because the Arduino cannot distinguish between listening to the Serial port versus establishing a Serial connection.

Any help would be appreciated.


1 Answer 1


The Arduino Mega's "serial" connection comes from an external chip implementing USB-serial conversion. While this chip knows if a session is open with a host, the standard design has no way to share that information with the main ATmega.

In contrast, on a Leonardo type board the main processor implements the USB interface, so it does know.

Your options include changing the requirement, having the PC program send some data to the Arduino, changing the processor to an ATmega or ARM with integrated USB, or perhaps modifying the USB implementation.

  • Thank you for the clarification. I'll have to go with 'having the PC program send some data to the Arduino'. Commented Jun 30, 2016 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.