check if data is being transferred on the serial port

I am trying to achieve the following:

check if there is no data on the serial port, start the timer for 30 mins. If during this time, there is no data that is transferred to/from the serial port, turn off all the gpio pins on arduino. If the data is transferred then restart the timer and wait for another 30 mins.

I am stuck on how to check if there is data being transferred on the serial port. Is there a way to do this?

I am stuck on how to check if there is data being transferred on the serial port. Is there a way to do this?

If your program is sending the data then you will know because you sent it. If your program is receiving the data then the Serial.available() function will return a non zero value.

Record the value of millis() in an unsigned long variable every time you receive/send data.

In loop() subtract that value from the current value of millis(). If greater than 30*60*1000, go to sleep.

KeithRB: If greater than 30*60*1000, go to sleep.

30L*60*1000

Ahh, of course.

Or 30UL*60*1000

You were understood, but there is a lot of cut and paste mentality here.