Speedometer Build Log


bigfoot13

Well-Known Member
@D&J RailRoad asked a question about automatic speed matching of locomotives which inspired this build. https://modelrailroadforums.com/for...speed-matching-locomotives.35010/#post-543957

I'm going to post this build on my website (https://www.modelrailroad.info/2022/10/dcc-speed-matching-assistant-scratch.html) and here.

Overview:​

  • Create a simple car that can be attached to any locomotive and used to obtain speed matching data.
  • Arduino based with no need for a computer attached but possibility to integrate with DCC possibly through I2C.
Speed = Distance / Time

Parts:​

Hopefully you will already have a lot of these parts.
  • 9" straight section of Bachman EZ Track or similar. + enough track to get the engine to the desired speed.
  • Arduino Uno/Nano
  • 1306 LCD Screen (128x32 pixels).
  • Train throttle (DC or DCC)
  • Train engine
  • Car:
    • Styrene sheet. I used a "For Sale" sign (Lowes) with a 0.015" thickness
    • 3/32" (2.4mm) round styrene tube Evergreen Scale Models #223
    • 1/8" (3.2mm) round styrene tube Evergreen Scale Models #224
    • 5/32" (4.0mm) round styrene tube Evergreen Scale Models #225
    • 3/16" 4.8mm) round styrene tube Evergreen Scale Models #226
    • 7/32" (5.5mm) round styrene tube Evergreen Scale Models #227
    • 1 Truck (Accurail) and wheels set (Walthers)
    • 1 coupler (Accurail) with draft box (Kadee)
    • 1 screw to hold on trucks. (Accurail)
    • Extra car weight (Amazon)

Arduino Program:​

Use an array of integers to hold readings sensor readings. This is averaged to prevent wild reading fluctuations.

Startup:​

Collect an average of readings a startup.
Set a threshold just below the average.
Display the average and threshold to the screen or serial connection.

Program Loop:​

  1. Read a sensor value the index value of the integer array.
  2. Get the average of all readings.
  3. If the average is below the threshold and the start time is zero then get the start time.
  4. If the average is above the threshold and the start time is not zero then get the stop time and calculate the speed using distance and time. Display the new speed and duration to the screen.
  5. Increment the index to the next sensor slot. Use modulus division to keep the counter within the size of the array.

Program Code:​

The program may be found at https://github.com/awoehler/DCC-Speedometer

Physical Arduino Setup:​

  1. Mount the trucks on the square with the piece that we just made below the truck. This will be the piece that is closest to the infrared detector. Foil tape can optionally be place on this to increase the reflectivity.
  2. Cut a hole between the ties just behind the nail hole. This is where the infrared detector/emitter will go. Hot glue to the bottom of the track.
  3. Connect the VCC on the sensor to 5V on the Arduino.
  4. Connect the GND on the sensor to GND on the Arduino.
  5. Connect the Digital out on the sensor to A0 on the Arduino.
  6. Connect the 1306 (128x32 pixels) screen to the Arduino. (Optionally you can use the Serial Output for reading your data.)
  7. Upload the sketch.
  8. Run trains.
  9. Adjust the pot on the sensor to match your lighting situation.


Car Directions:​

  1. Cut a 9' 6" square for the base of the car.
  2. Draw a lines from corner to corner to find the center.
  3. Cut a piece of Styrene tube long enough to hold the wheels off the truck and glue to the center of the square. The combination of rods used as standoff's for the trucks will vary depending on the trucks that you use.
  4. Use a 3/32 styrene rod to mount the Kadee draft box to the center edge of one of the edges of the square. Glue scraps of styrene sheet to the edge to keep the draft box from twisting.
  5. Cut a piece of styrene (?) wide and (?) long so that it fits between the wheels. This will be cut into 1 long piece of 33.1mm, and 2 at 20mm. Glue the 33.1mm pieces and 1 20mm piece together. Drill a hole large enough so that the screw head can pass through it. Drill a hole in the second 20mm piece so that only the threads pass through. Now glue it to the other 20mm piece so that it looks like this.



Notes:
When the sketch starts up it fills the array of will values from the current reading so you will not want anything over the sensor when it starts.
Initially I used the analog output but when when I changed lighting situations it was less dependable.
The timer will overflow or wrap around at about 50 days so I'm not sure what will happen if you leave this on for a long time.
As the train goes faster the readings become less accurate because the time becomes smaller and smaller, increasing the length of the car could help to resolve this. The length of the car can be adjusted at the top of the code.

DSC00019.web.jpg
DSC00021.web.jpg
 
Seems pretty involved for people who don't have a background in that kind of stuff. I could prolly bore you to death with processes of military Acquisition Logisitics and say, it's really simple when ya try it.
I think I'll just stick with the Accutrack speedometer.
 
@D&J RailRoad asked a question about automatic speed matching of locomotives which inspired this build. https://modelrailroadforums.com/for...speed-matching-locomotives.35010/#post-543957

I'm going to post this build on my website (https://www.modelrailroad.info/2022/10/dcc-speed-matching-assistant-scratch.html) and here.

Overview:​

  • Create a simple car that can be attached to any locomotive and used to obtain speed matching data.
  • Arduino based with no need for a computer attached but possibility to integrate with DCC possibly through I2C.
Speed = Distance / Time

Parts:​

Hopefully you will already have a lot of these parts.
  • 9" straight section of Bachman EZ Track or similar. + enough track to get the engine to the desired speed.
  • Arduino Uno/Nano
  • 1306 LCD Screen (128x32 pixels).
  • Train throttle (DC or DCC)
  • Train engine
  • Car:
    • Styrene sheet. I used a "For Sale" sign (Lowes) with a 0.015" thickness
    • 3/32" (2.4mm) round styrene tube Evergreen Scale Models #223
    • 1/8" (3.2mm) round styrene tube Evergreen Scale Models #224
    • 5/32" (4.0mm) round styrene tube Evergreen Scale Models #225
    • 3/16" 4.8mm) round styrene tube Evergreen Scale Models #226
    • 7/32" (5.5mm) round styrene tube Evergreen Scale Models #227
    • 1 Truck (Accurail) and wheels set (Walthers)
    • 1 coupler (Accurail) with draft box (Kadee)
    • 1 screw to hold on trucks. (Accurail)
    • Extra car weight (Amazon)

Arduino Program:​

Use an array of integers to hold readings sensor readings. This is averaged to prevent wild reading fluctuations.

Startup:​

Collect an average of readings a startup.
Set a threshold just below the average.
Display the average and threshold to the screen or serial connection.

Program Loop:​

  1. Read a sensor value the index value of the integer array.
  2. Get the average of all readings.
  3. If the average is below the threshold and the start time is zero then get the start time.
  4. If the average is above the threshold and the start time is not zero then get the stop time and calculate the speed using distance and time. Display the new speed and duration to the screen.
  5. Increment the index to the next sensor slot. Use modulus division to keep the counter within the size of the array.

Program Code:​

The program may be found at https://github.com/awoehler/DCC-Speedometer

Physical Arduino Setup:​

  1. Mount the trucks on the square with the piece that we just made below the truck. This will be the piece that is closest to the infrared detector. Foil tape can optionally be place on this to increase the reflectivity.
  2. Cut a hole between the ties just behind the nail hole. This is where the infrared detector/emitter will go. Hot glue to the bottom of the track.
  3. Connect the VCC on the sensor to 5V on the Arduino.
  4. Connect the GND on the sensor to GND on the Arduino.
  5. Connect the Digital out on the sensor to A0 on the Arduino.
  6. Connect the 1306 (128x32 pixels) screen to the Arduino. (Optionally you can use the Serial Output for reading your data.)
  7. Upload the sketch.
  8. Run trains.
  9. Adjust the pot on the sensor to match your lighting situation.


Car Directions:​

  1. Cut a 9' 6" square for the base of the car.
  2. Draw a lines from corner to corner to find the center.
  3. Cut a piece of Styrene tube long enough to hold the wheels off the truck and glue to the center of the square. The combination of rods used as standoff's for the trucks will vary depending on the trucks that you use.
  4. Use a 3/32 styrene rod to mount the Kadee draft box to the center edge of one of the edges of the square. Glue scraps of styrene sheet to the edge to keep the draft box from twisting.
  5. Cut a piece of styrene (?) wide and (?) long so that it fits between the wheels. This will be cut into 1 long piece of 33.1mm, and 2 at 20mm. Glue the 33.1mm pieces and 1 20mm piece together. Drill a hole large enough so that the screw head can pass through it. Drill a hole in the second 20mm piece so that only the threads pass through. Now glue it to the other 20mm piece so that it looks like this.



Notes:
When the sketch starts up it fills the array of will values from the current reading so you will not want anything over the sensor when it starts.
Initially I used the analog output but when when I changed lighting situations it was less dependable.
The timer will overflow or wrap around at about 50 days so I'm not sure what will happen if you leave this on for a long time.
As the train goes faster the readings become less accurate because the time becomes smaller and smaller, increasing the length of the car could help to resolve this. The length of the car can be adjusted at the top of the code.

View attachment 154360View attachment 154361
I liked this idea, so followed your link, but it's way beyond my understanding.
 
i did a couple a half dozen years back, both with arduinos ... one mobile that read speed only when moving, and the other was fixed, that read speed when a train moved past it ...
i used the mobile one much more, and put it into an old boxcar , with large displays on both sides for ease of viewing ..
if anybody's interested, the files are on modeltrainforum.com in the technical section, direct link is
 



Back
Top