Skip to content

A two-terminus track with a station midway, controlled with Arduino: auto-reverse employing IR proximity sensors.

Notifications You must be signed in to change notification settings

buzcarter/arduino-train-terminal-controller-2.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();
    }
}
  • my final build uses a ease-in stop at the middle station rather than merely cutting the power, but I wanted to leave this "pure" and of a piece with Jimmy's original example.
  • any guage/scale layout: O, HO, N -- code should be scale agnostic
  • the motor driver used here can control TWO DC tracks... makes ya think, don't it?

Key Electronics

  • 3 IR proximity sensors, detect when train "arrives" at a station
  • potentiometer, control train speed
  • Motor Driver, applying current allows us to electrify either track (forward & reverse), as well as set the speed (using potentiometer's value)
  • Arduino Uno & breadboard (this probably fits easily on smaller mini, but I had an Uno handy)

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

  • solder parts, no jumpers
  • mount IR sensors beneath the flextrack, drill small holes in ties for LED & reciever

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

About

A two-terminus track with a station midway, controlled with Arduino: auto-reverse employing IR proximity sensors.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published