กลับไปหน้ารวมไฟล์
automatic-train-control-17bc11-en.md

This very simple scheme allows you to quickly get the train on your schedule. You can adjust the movement time and the train stop time. Train acceleration and braking are also configurable. By changing the schedule parameters in the sketch, you can create any type of automatic movement. Just turn on the power and your train leaves to way.

Following the Interlocking project, the Automatic Train Control (ATC) system focuses on the trains themselves rather than just collision avoidance. This project acts as the "Conductor," automating the acceleration and deceleration ramps for realistic station stops on an HO or N-scale layout.

Pulse Width DDC (Digital Command Control)

Model trains receive their power directly from the metal rails.

  1. The Circuit: The Arduino uses a heavy-duty Motor Shield (L298P or similar) directly connected to the track rails to output 12V PWM.
  2. The Ramp Algorithm: A real 100-ton locomotive doesn't stop instantly. The Arduino code uses a for loop to slowly increment and decrement the PWM signal: for(speed=255; speed>50; speed--) { analogWrite(trackPin, speed); delay(20); }. This creates incredibly smooth, realistic momentum.

Station Stopping Logic

To automate scheduling, the Arduino must know exactly where the train is.

  • You place an IR Sensor (TCRT5000) or a Reed Switch under the track at the beginning of the station platform.
  • When the train passes the sensor, the Arduino executes the deceleration loop.
  • The train comes to a perfectly smooth stop right at the tiny station platform.
  • The Arduino runs a delay(10000) to let the imaginary passengers off, then executes a slow acceleration loop to depart!

Changing the time parameters in the sketch:

// 1  | 0 > Time < 5 sec
if (counterScheduler <= 5) {
......
// 2  | 10 sec > Time < 15 sec
if ((counterScheduler >= 10) && (counterScheduler <= 15)) {
......
// 3  | Change direction
if (counterScheduler == 16) {
.... etc.

creates a timetable.

Variables:

int brakingDelta = 5;
int accelerateDelta = 6;

define the parameters of movement the train

The direction of the train is determined by the state of the pins D6 and D7:

// Set default direction to FORWARD
digitalWrite(L298_IN1, HIGH);
digitalWrite(L298_IN2, LOW);

Required Assembly

  • Arduino Uno/Mega.
  • Motor Control Shield: Capable of outputting continuous 1-2 Amps at 12V.
  • IR Obstacle Sensors or Reed Switches + Magnets.
  • Analog HO or N scale train setup.

You can endlessly change this sketch to get new options for automatic train movement.

Welcome aboard!

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
author: "Steve_Massikker"
category: "Home & Automation"
components:
  - "1x Arduino UNO"
  - "1x Dual H-Bridge motor drivers L298"
  - "1x Jumper wires (generic)"
description: "Model railroading upgraded! Build an autonomous train dispatching system that manages speed, station stopping, and track switching reliably."
difficulty: "Advanced"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX1+9Pzq5YUjBb+U225WaWG1YEjjRkvsPMs0huzLm/ydlHO8rcNHIXR4YwfF6K6WQf4Cs+xukt9tXTVkMw+O/buT7wzI8pQtUAXc="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/automatic-train-control-17bc11_cover.jpg"
lang: "en"
likes: 20
passwordHash: "5b0f061843599a0c126ff15d65bc65e3ea263af7d71dacc9ec8520e2e9f45420"
price: 1120
seoDescription: "Automate your model railway with Arduino. Create custom schedules and ensure your trains run on time using any Arduino boards."
tags:
  - "control"
  - "home automation"
  - "train"
title: "Automatic Train Control"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/3m3fIjzGKho"
views: 30255