A dining car has been transformed into a train diagnostic vehicle for quality control of the catenary on an H0 model train network (scale 1/87)
Devices and components
10 connecting wires 150 mm male
Arduino-Nano ESP32
Materials and tools
Digital multimeter
Soldering iron, ESD
Software and tools
Cloud Editor
IoT Dashboard
Arduino IDE
Arduino creation platform
Project description
A dining car has been transformed into a railway diagnostic vehicle for catenary quality control
conclusion
model train diagnostic trainer
this is the script that runs the Arduino Nano ESP
1// Code for the diagnostic coach for model trains and catenary
2// runs on gauge H0 (scale 1/87)
3// Arduino Nano ESP 32 and Arduino Cloud
4
5#include "arduino_secrets.h"
6#include <WiFiManager.h>
7#include <strings_en.h>
8#include <wm_consts_en.h>
9#include <wm_strings_en.h>
10#include <wm_strings_es.h>
11#include <movingAvg.h>
12/*
13 Sketch generated by the Arduino IoT Cloud Thing "Untitled"
14 https://create.arduino.cc/cloud/things/........
15 Arduino IoT Cloud Variables description
16 The following variables are automatically generated and updated when changes are made to the Thing
17
18 float rawVoltage;
19 float VsAC;
20 bool green;
21 bool red;
22
23 Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
24 which are called when their values are changed from the Dashboard.
25 These functions are generated with the Thing and added at the end of this sketch.
26*/
27
28#include "thingProperties.h"
29
30const int sensorPin = A3;
31const float baseLineVs = 16.8; // threshold VsAC Voltage
32const int RunningAverageCount = 57;
33float RunningAverageBuffer[RunningAverageCount];
34
35int NextRunningAverage;
36int buzzer = 8; // setting controls the digital IO foot buzzer
37void setup() {
38
39
40 // Initialize serial and wait for port to open:
41 Serial.begin(9600);
42 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
43 delay(1500);
44
45 // set the LED pins as outputs
46 // the for() loop saves some extra coding
47 for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
48 pinMode(pinNumber, OUTPUT);
49 digitalWrite(pinNumber, LOW);
50 }
51
52 // Defined in thingProperties.h
53 initProperties();
54
55 // Connect to Arduino IoT Cloud
56 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
57
58 /*
59 The following function allows you to obtain more information
60 related to the state of network and IoT Cloud connection and errors
61 the higher number the more granular information you’ll get.
62 The default is 0 (only errors).
63 Maximum is 4
64 */
65 setDebugMessageLevel(2);
66 ArduinoCloud.printDebugInfo();
67}
68
69void loop() {
70 ArduinoCloud.update();
71
72 // Your code here
73 pinMode(buzzer, OUTPUT); // set the digital IO pin mode, OUTPUT out of Wen }
74 rawVoltage = analogRead(sensorPin);
75
76 RunningAverageBuffer[NextRunningAverage++] = rawVoltage;
77 if (NextRunningAverage >= RunningAverageCount) {
78 NextRunningAverage = 0;
79 }
80 float RunningAverageVoltage = 0;
81 for (int i = 0; i < RunningAverageCount; ++i) {
82 RunningAverageVoltage += RunningAverageBuffer[i];
83 }
84 RunningAverageVoltage /= RunningAverageCount;
85 // convert the DC voltage to AC voltage for display
86 // the diode bridge sensor changes from V0= 0 -3.3 V DC, if the AC Voltage changes from Vs= 0 -24 V
87 // the diode bridge says there's a 1.4 V offset
88 // ((voltage + 1.4 V) times 4.8; V0 = Vs * R2/(R1+R2)); voltage divider with resitors
89 VsAC = (RunningAverageVoltage - 60) / 4096.0 * 28.2;
90 Serial.println(", average Voltage VsAC : ");
91 // Serial.println();
92 Serial.print("\t");
93 Serial.print(VsAC);
94 Serial.print("\t");
95 Serial.print(19);
96 Serial.print("\t");
97 Serial.println(16.8);
98
99 // if the voltage Vs is lower than the baseline turn on red LED
100 int pitch = map(VsAC, 0.0, 23.9, 50, 4000);
101 if (VsAC < baseLineVs) {
102 digitalWrite(2, LOW); // GREEN
103 green = false;
104 digitalWrite(3, LOW); // YELLOW
105 digitalWrite(4, HIGH); // RED
106 red = true;
107 tone(8, pitch, 20);
108 delay(25);
109 } // if the voltage rises between 18.1 - 18.6, turn green LED on
110 else if (VsAC >= baseLineVs && VsAC < baseLineVs + 2.6) {
111 digitalWrite(2, HIGH); // GREEN
112 green = true;
113 digitalWrite(3, LOW); // YELLOW
114 digitalWrite(4, LOW); // RED
115 red = false;
116 } // if the voltage rises between 18 Vac and 20 Vac, turn a second LED on yellow
117 else if (VsAC >= baseLineVs + 2.6 && VsAC < baseLineVs + 3.8) {
118 digitalWrite(2, HIGH); // GREEN
119 green = true;
120 digitalWrite(3, HIGH); // YELLOW
121 digitalWrite(4, LOW); // RED
122 red = false;
123 } // if the voltage rises over, turn yellow and red LEDs on
124 else if (VsAC >= baseLineVs + 3.8) {
125 digitalWrite(2, LOW); // GREEN
126 green = false;
127 digitalWrite(3, HIGH); // YELLOW
128 digitalWrite(4, HIGH); // RED
129 red = true;
130 }
131}
Downloadable files
Arduino Nano ESP32 and IoT electronic circuit
Arduino Nano ESP32 circuit for diagnostic coach
I0T Arduino Nano ESP32 circuit.jpeg
Manual for Model Train Diagnostic Coach with Arduino Nano and IoT
This is the full description of the project.
Manual Model Train Diagnostic Coach with Arduino Nano and IoT.pdf
Documentation
Arduino Nano ESP32 monitors catenary quality on model train network
https://vimeo.com/1056795117/b015a61f36
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.