I am very new to Arduino. I have arduino UNO platform and Infrared Obstacle Avoidance Sensor. I found a code which prints that a movement was detected (see below). The thing I need is to get the time of detection. How could I get the time from my computer and see it in the serial monitor? Any suggestions please?
In order to get the time from your PC a program will need to send it to the Arduino. It would almost certainly be better to use a Real Time Clock (RTC) connected to the Arduino and forget about getting the time from the PC.
Incidentally, why are you using an interrupt ? Also, note that using Serial.print() in an ISR is not a good idea because it uses an interrupt and they are disabled when in an ISR. This may not be a problem with recent versions of the IDE but is still usually regarded as bad practice.
This may not be a problem with recent versions of the IDE but is still usually regarded as bad practice.
The delay() in the ISR is not only definitely a bad practice, it is stupid, since delay() relies on interrupts that are disabled while the ISR runs. Time does not pass in an ISR, so waiting for some amount of time to pass is not a useful thing to do.
OP: You REALLY need to understand what interrupts are for, and what you can, and can not, do in an interrupt service routine before you start trying to use interrupts.