I have put together several proto-boards incorporatingarduino nanos. Each board controls one 3 aspect model railway signal on my uncle's layout. The arduino basically reads values from light sensors when a train passes over to control the signal aspect and also reads the position of the nearest turnout (point) to ascertain whether a red light should be on. This then runs a bit of code that fades down the green led and fades up the red. This is simply a switch built into the turnout control motor that connects a digi pin on the arduino to ground in order to trigger the action. This pin uses the arduino's internal pull-up resistor.
All works perfectly as expected on the bench before installation. I connect the relevent pin to ground and the red led is lit. Releasing the connection turns off red led and back to green. No problems there, then.
The issue I have is when I fit the board to the underside of the layout and run 2-3 foot wires from the ground and trigger pins to reach the nearest point motor switch. Before connecting, touching these wires together (sending earth to my trigger pin) triggers my red LED reliably and stays there, but when I release them my green led lights up as expected but then behaves like my trigger pin is floating, so it's flicking sporadically between red and green. Connecting these wires together again results in a solid red.
Back at home on the bench, I tried connected a long-ish wire to the same pins, thinking it may be that, or the need for a stronger pull-up, but the board works as expected.
My work around is to use the SPDT switches on the point motors to send 5v to the pin or earth to the pin, rather than earth or nothing (or earth and pull-up). This workaround, although working fine, uses more switch contacts that need to be used for other things later on.
My only idea about what may be causing my problem is electromagnetic interference from the railway's DCC power bus lines that run round under the layout. I know the system causes audio interference if listening to MW radio or if you place speakers near the wiring, but I would have thought it'd be difficult for it to interfere with a simple 5v-gnd connection?? All other functions including the photoresistors seem to work fine.
Any ideas on how to overcome this would be much appreciated!