I am playing with control systems in a DCC++ system. The sensors are inexpensive ambient light detectors, which I modified to have the photo-resistor on a short cable instead of on the circuit board; powered by a small 3.3 power supply. The sensor output is a 1 (3.3v) or a zero (0v). The sensor output goes to an Arduino mega 2560 digital input pin. Since I am not using the Arduino 3.3 supply, I assume I have to tie the external power supply ground to the Arduino ground pin to establish the correct reference for signal detection. Correct? Every block has a sensor at each end. This tells me where a train is, but not which train. I am pretty sure I can keep track of which train is where knowing the initial location of the train. I am intending to write my own code in a Raspberry pi which communicates with the Arduino. I know I could do simple control with JMRI and will be playing with it also. I just like to write code! comments / advice appreciated.