A two-terminus track with a station midway, controlled with Arduino: auto-reverse employing IR proximity sensors.
Not a DCC controller.
This is a fork of DIY Jimmy's (find him at DIY and Digital Railroad) "Three Station Railroad Arduino Demo", however, that project is setup as ArduinoIDE and I prefer vanilla C/C++ or JavaScript with Microsoft VSCode etc. Plus, that code can be refactored for me, a n00b to Arduinios and very rusty with C++. That said, this compiles fine using Arduino IDE 2.x (Arduino Automated Railroad.ino
becomes src/main.cpp
).
Original GitHub Source and his incredibly helpful YouTube tutorial.
Pseudo-code of how I want my main loop to read:
void loop() {
updateSpeed(); // get potentiometer setting and send that to motor controller
reportStatus(); // echo state of the train, direction and speed
if (isAtTerminus()) {
// applies to any terminating station: end of the line
reverseDirection();
} else (isAtMiddleStation()) {
// any station "in the middle" we'll just pause momentarily before
// continuing in same direction of travel
pauseAndResume();
}
}
Direction of travel -- "Left" or "Right", "Forward" or "Reverse" -- are completely arbitrary, so pick and move on.
(check the "docs/fritzing" directory for the Wiring Diagram and additional part definition (found on very helpful Fritzing forums)
I'll be using an n-scale Bachmann Trolley (trolleys can be found for as little as $35-$60)
Everything is free except Copilot, which is optional, but helpful (even explains pin-outs)