This approach uses (at least) 3 LDR's between the rails and all are used for detection purposes. The ambient light they see does not need to be constant but should affect them all more or less ...
Code for this is attached in the same repo with name "code.ino". It was run on Arduino IDE Diving into learning various sensors, I came across LDR sensor. It is basically a variable resistor which ...