I have just completed and tested a controller system of my design to automate trips between two stations and a yard siding on my model (HO scale) trolley line.

I have used a PIC 16F722 to take advantage of the generous quantity of I/O pins. When tested on the workbench everything functions superbly. When I connect it to the model table it is a different story.

My current design has 3 reed switches in the track between the rails attached to 3 pins on the PIC with pullup resistors in parallel. These detect the trolley as it passes overhead (with a magnet attached below it.) The reed switch closes and pulls the pin voltage low and the trolley stops at the station, etc. This design works flawlessly on the bench with relatively short leads to the PIC.

On the model table when everything is connected and tested, the location sensors(reed switches) are triggering falsely. The trolley doesn’t get anywhere near the reed switches and while it is running, the PIC jumps to the next event in the program. I remedy this by disconnecting the switches/wires thus taking them out of the test. I then run the system by shorting the corresponding PIC pins to GND wherein the system works correctly again.

I anticipated this problem and to prevent noise on the wires false triggering the PIC, I used a twisted pair to each switch. I view the track as a long antenna which runs roughly parallel to the sensor wires. In addition, the trolley motor is likely a significant source of stray EMF. I have been reading up on Signal to Noise Ratio but the subject is a bit intimidating for one without a scope and test equipment. Since I am self-taught my approach is largely trial and error.

My next plan is to test using a sensor wire consisting of a twisted pair with metallic sheath and ground it on both ends.

For those of you who have your feet grounded in the real world of control system design, I would gratefully appreciate some practical advice if not too technically challenging.

Thanks.