buzcarter / arduino-train-terminal-controller-2.0

A two-terminus track with a station midway, controlled with Arduino: auto-reverse employing IR proximity sensors.
0 stars 0 forks source link
arduino arduino-uno-r3 hobby-project modelrailroad modeltrain

A Simple Reversing Arduino Train Controller

Overview

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.

Notes:

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();
    }
}

Key Electronics

Direction of travel -- "Left" or "Right", "Forward" or "Reverse" -- are completely arbitrary, so pick and move on.

Circuit Diagram

Circut Diagram/Schematic

(check the "docs/fritzing" directory for the Wiring Diagram and additional part definition (found on very helpful Fritzing forums)

Build

Resources

I'll be using an n-scale Bachmann Trolley (trolleys can be found for as little as $35-$60)

My Dev Setup

Everything is free except Copilot, which is optional, but helpful (even explains pin-outs)

Jimmy's Parts List