void loop()
{
// display information about the counter
Serial.print("Awake for ");
Serial.print(count);
Serial.println("sec");
count++;
delay(1000); // waits for a second
// compute the serial input
if (Serial.available()) {
int val = Serial.read();
if (val == 'S') {
You want to do ModBus communication and use the same serial interface to send commands like "go to sleep* or print debugging messages. Do you really think this can work? How should the SCADA system distinguish between ModBus traffic and your other serial stuff?