Turn On LED When Serial Communication is Active

Good afternoon, I need an example of a code that when communication is active RX pin0 serial Arduino a LED illuminates on the pin7 stopped communicating the LED goes out.

thank you very much!

Not sure you can do that without rewriting the serial drivers.

Why not connect a LED to the serial pin via a resistor? Why do you need code?

If your sketch is actually reading data from the serial port, you can do this pretty easily by putting a "wrapper" around Serial.read():

getSerial:
   if (serial available) {
      light LED;
      set lastDataTime = now;
      return data;
   } else {
     if lastDataTIme is a_long_time_ago {
        turn off LED;
        wait, or return "no_data";
     }
   }

It looks too much like a homework assignment for me to provide actual code.