I'm sorry, but you don't seem to have a clue what flush() does. You haven't sent any data on Serial1. There is no reason to block until nothing has been shifted out.
Why? Why not an hour or two?
You have no decoupling anywhere - not difficult to see why you don't need the IR receiver to pick up any light ifits comparator catches glitches from the supply rail - decouple all chips, especially comparators (they are extremelysensitive). You may have to add a little capacitance on the comparator inputs to prevent false triggering too.
in that case could you please look at the code I had placed in reply# 7 and tell me if what I have done is theoretically and logically correct..because I have the issue with that code too.
You'd need to make it clearer what the connections were when you ran that code, because you're describing several arrangements in that post.The behaviour you described originally matched up with what I would expect given that code and the hardware you described, assuming the IR link worked.
If you check the comments on the delay statements on these two links, you will see what I meant.
That delay is in there to give the ADC time to discharge between readings. It has NOTHING to do with reading Serial data, sending Serial data, or anything NOT involving the ADC. And, even then, it's use is questionable.
Just so that everyone can see what I am talking about, I am attaching another image here where I had connected the LED driver with Tx1 and the comparator output to Rx3. Now I put light on one of my sensors using a cellphone flashlight and you can see the LED glowing in the picture. Can anyone give me a sane explanation for this? There is no program running on the board obviously, since it is not powered. It has to do something with the internal circuitry, does anyone here have any idea about this?
You've created a very expensive piece of wire using the MEGA's input protection diodes, but that's not exactly useful is it?