LED ON if Serial disconnected?

Is it possible to create a code that turns a LED ON if serial communication ends? Lets say if the program (on the computer) that Arduino is talking to, hangs?

No. serial happens even if you have unpluged the Arduino. The byte is send but there is no ack from the other end so you don’t know what happened to it.

You could set things up so that the led blinks if the program is running correctly (see blink without delay). But as the serial com is two unidirectional channels that about the best you can do.

Mark

If you use an Arduino Leonardo, or an Arduino Due with the Native USB port, you can monitor the status of the CDCACM USB serial port:

if (!Serial) {
  digitalWrite(13, HIGH);
} else {
  digitalWrite(13, LOW);
}

You can't do it on boards where you communicate with an FT232 or other interface chip (like the Uno uses an 8U2 or 16U2).

Another, more difficult, option would be to modify the firmware of the 8U2/16U2 so it provides a signal to the main MCU on the connection status of the serial.

holmes4:
No. serial happens even if you have unpluged the Arduino. The byte is send but there is no ack from the other end so you don’t know what happened to it.

You could set things up so that the led blinks if the program is running correctly (see blink without delay). But as the serial com is two unidirectional channels that about the best you can do.

Mark

TX!
I got it to work with blink. Thats better than nothing :slight_smile:

What if you have a arduino uno R3 make edition, can you do the same with that?.