want to turn on dc motor when train goes by and turn off motor when train goes by another sensor down the track. I am turning on a water wheel and motor only has to go forward. I can use a timer set up also , around 10 to 15 seconds. thx
Not sure what your question is, but here is a MOSFET motor driver. Pick a MOSFET that can handle the stall current of the motor.
Several things at a time, another millis() timing tutorial.
For the sensor(s) you could use a light gate. Google "light gate arduino" for more information.
Or attach magnet to the train and use Hall Effect sensors.
Adding to post #3
Reflective IR sensor
I would think the reflective IR sensor would be a good choice. You could put a small mirror ( < 1/4" sq) on the bottom of the engine or 2nd car. the sensor would peak through a hole inside the tracks.
If you find other lights are sensed by the receiver simply pulse the LED and verify the reflected signal is pulsing at the same frequency.
What scale? I'm assuming a model but in fact you didn't say... Size does influence the choice of solution somewhat.
make a basic design using a H-bridge and a sensor for current per rail track and test.
ho scale -
Part of the answer lies with what is visually acceptable
I would get an IR sensor and put it under the track have it look up
When a trane passes check results.
You could hide in shrubbery
You could hide in bridge overpass
Hide in sign posts.
Or in rocks