As a noobie with the model train system and because I haven't too much free space for test with big railways, I search for an automatic model train system, where it used IR module for define frake momment (stop position is not instant, as in rea case, if push brake pedal and car stop is after few meters).
First I found the video I Made an Automated Model Train With An Arduino! where it used direct control (DC voltage with normal or reversed polarity). I tested manually the functionality of the system with my adapted sketch as in video Automatic Model Train (test)
After that, I found article Back-and-forth train control by Arduino with IR sensor
with PWM control for speed, so I adapt the sketch (my sketch) and made a first test with push a carriage push by me, to see how system work, as in video Automatic Model Train (test 2)Finally, I added L298 H-bridge module as in schematic
and second (with an oscilloscope on railway power) is Arduino automatic model train (2)