I am trying to put together an Arduino-based detection of 1/8 scale train cars (6 foot long, 4.5" wheels) in an insulated block of aluminum rails (7.5" apart) which is about 20 feet long. I already have a working crossing signal that the detection circuit will control. My thought is to connect the 5V Arduino pin to one insulated section of rail and an analog pin connected to the opposing rail. The idea is that once the steel wheel and axle enter the insulated block, voltage will flow and can be measured. I can then use a loop to turn on the signals when voltage measures over a certain level. I have seen similar questions asked about model railroad block detection where trains are powered through the track. This is not the case here. The only power would be that which I will use to detect trains. I am assuming I would need some sort of capacitor smooth out the voltage flow as it is likely to be erratic due to wheel movement, dirt, and imperfect contact between track and wheels, etc. Any advice?
It’s likely that as the wheels are rotating the motor will create noise or back emf which could cause problems .
It would be simpler to use an optical or inductive sensor to detec the engine.
I am a fan of track current based occupancy detection, but for a crossing I agree that a prox sensor (as mentioned above) can work.
However, track current detection does not depend on powered trains. A bias voltage is usually superimposed on the track power feed, so that a train that is not moving can still be detected. For what it's worth, consider real world train signals. They work on the track current principle. Your train is probably not very different than a real one. A real train has electrical continuity through the axles so the wheels on both sides are electrically connected. That is really easy to detect on two rails.
The best crossing detectors have 3 occupancy detectors. One on the crossing, and two on the approach to the crossing from both directions. That's so the gates come down early, and go up as soon as the train clears the crossing.
Best to protect the Arduino analog pin with a 10k resistor in series, then stray random voltages getting onto
the track are less likely to damage the Arduino (think nearby thunderstorm).
The idea is that once the steel wheel and axle enter the insulated block, voltage will flow and can be measured
Voltages don't flow, current flows, voltages are differences in potential between 2 parts of a circuit,
the analogy of voltage with pressure and current with water flow is a useful one.
I assume that you have already tested this in a static configuration. So, if you can detect the "closure" of the circuit through the wheels, then just use a long debounce method and treat it like a dirty switch.