I could sure use some help here! I've been beating my head against the wall trying to figure out this problem. I have an Arduino Uno R3 hooked up to a Sainsmart 4-relay board. The relays switch 6V DC out to a model train track that's broken into 3 sections (stations). There are 3 reed switches spread out on the train track that are then hooked up to the Arduino inputs. These correspond to the 3 sections of train track. The relays are all energized at start-up, thus allowing the model train to run. My code waits for a reed switch to close, then turns off the associated relay, removing voltage from that part of the train track causing the train to stop at the station.
So now the problem. When there are no trains on the track, everything works fine. I can manually trigger each reed switch and the Arduino sees the switch closure and triggers the associated relay. However, as soon as I put a train on the track, the Arduino sees phantom random reed switch closures. I've checked the reed switches, and they aren't actually closing even though the Arduino thinks they are.
I have the reed switches hooked up to the Arduino as if they were push-buttons (using a resistor). I originally had them hooked up without the resistor using the Arduino's internal resistors, but I was having the same problem as described above, so I hooked them up as switches to see if that would help, and that's where they are now. See attached picture "switch.jpg" for how the reed switches are hooked up. I've also attached the source code.
I'll be really grateful for any help. If anything, you can have some free train controller software :-).
-tom

TrainController.ino (6.24 KB)