Led light sensor help...

Thank you for your reply and information.

The led will sense light with the same or shorter wavelength. So you need a red led.

I am familiar with this as I have a red led.

Your code is roughly okay. But the 40ms is a fixed time. The reverse charge could need 1ms(or less) ... 10000ms to be removed.

I don't quite understand what you mean here, do you mind expanding your explanation?

I you write a 'HIGH', and after that make it an input, this 'HIGH' sets the internal pull-up resistor. So you have to write a 'LOW' after you switched it to input.

I have also read a bit on the arduino pull-up resistor but I don't know why I need to disable the pull up resistor in this case. I will think about it today. Why is it that setting the pin to "HIGH" before making it an input sets the pull-up resistor? Why does "LOW" turn off the pull up resistor?

I will try to edit my code according to what you have stated while I await a reply. Thanks again.