# Train SpeedoMeter



## wvgca (Jan 21, 2013)

Wound up with some left over Vishay IR emitter / sensor modules , so I figured that I would make a little speed readout for my layout, just to see what speed I normally run my loco's at ..

Something that I can set down and check speeds., not built in or car mounted .....

Need some kind of fixture to hold the sensors, plus probably a small Arduino and a LCD two line display ..and [in my case], power pickup from the track [DCC] ..easier than batteries I think ..


----------



## highvoltage (Apr 6, 2014)

Actual speed or scale speed?


----------



## wvgca (Jan 21, 2013)

highvoltage said:


> Actual speed or scale speed?



Calculation will first be actual ...then one line of code for scale conversion, two line display can show both mph and kph ..


----------



## thedoc (Oct 15, 2015)

Many years ago there was an article in one of the magazines on how to build a speedometer for a scale model engine. It was based on the EMF produced by the motor as the engine was running. The speedometer needed to be calibrated for each engine, but it was directly proportional to how fast the motor was turning.


----------



## Lemonhawk (Sep 24, 2013)

You could add the code to your DCC Booster that's only displaying current. You could probably add another 2 line display to the Nano by changing the I2C address on the display.


----------



## wvgca (Jan 21, 2013)

thedoc said:


> Many years ago there was an article in one of the magazines on how to build a speedometer for a scale model engine. It was based on the EMF produced by the motor as the engine was running. The speedometer needed to be calibrated for each engine, but it was directly proportional to how fast the motor was turning.



This one is a bit simpler, just two sensors mounted on a stand.. calculates real world speed based on time between sensor trips.. and then displays in scale, any scale of users choice ..[but just one at a time] ..


----------



## Lemonhawk (Sep 24, 2013)

A few years ago I was thinking messing with electronics was dead, how wrong I was, the Arduino in particular has opened up a whole new world of electronics!


----------



## daschnoz (Dec 12, 2016)

VERY COOL.

Would you be willing to share your hookup diagrams, code, parts list, etc. with the rest of us???


----------



## Cycleops (Dec 6, 2014)

I've seen people use cycle computers for this but I don't have any info on how to set this up.


----------



## wvgca (Jan 21, 2013)

Cycleops said:


> I've seen people use cycle computers for this but I don't have any info on how to set this up.


Sure, a bicycle speedometer would work, but with only one sensor you would have run in a known size loop, and put the pickup magnet onto the loco or a piece of rolling stock, and divide the loop size by the scale .. 
It's an excellent idea for a very low cost speedo ..
and probably cheaper than the one I'm doing ..


----------



## wvgca (Jan 21, 2013)

daschnoz said:


> VERY COOL.
> 
> Would you be willing to share your hookup diagrams, code, parts list, etc. with the rest of us???


Sure, there is no diagram, just two sensors in pull up mode ..80 ohm to IR led to keep load under 60ma, and I think around 10k on the transistor emitter side ..that's all there is for non arduino hard parts

Once I get code finished the pinouts I used are readily determined there , as well as sensor spacing and scale choices ..

At this point the code works, but not ideally, the loco needs to move in the same direction right now, have to figure out bi-directional trip sense yet


----------



## Lemonhawk (Sep 24, 2013)

I have some ultrasonic sensors, I might try using them to detect the speed.


----------



## gunrunnerjohn (Nov 10, 2010)

wvgca said:


> At this point the code works, but not ideally, the loco needs to move in the same direction right now, have to figure out bi-directional trip sense yet


Couldn't you make an assumption about how long it takes to transition the sensors? If it takes more than, let's say 5 seconds, the time interval is reset and the first sensor tripped determines the direction and starts the timing.


----------



## wvgca (Jan 21, 2013)

Lemonhawk said:


> I have some ultrasonic sensors, I might try using them to detect the speed.


I'm just using the ones that are no longer needed for spares for PLC control systems [end user upgraded modules] .. so either they find a purpose or maybe get tossed ..
Just threw away about 30lbs of old style pots and pot kits


----------



## wvgca (Jan 21, 2013)

gunrunnerjohn said:


> Couldn't you make an assumption about how long it takes to transition the sensors? If it takes more than, let's say 5 seconds, the time interval is reset and the first sensor tripped determines the direction and starts the timing.


lol ...
I just found time to work on the part where the second sensor is tripped first ..
It's not even 24 hours into this yet ... project 38 1/2


----------



## gunrunnerjohn (Nov 10, 2010)

GMTA.


----------



## jlc41 (Feb 16, 2016)

I would like to see how this ends up. My grandson is always asking me how fast are the trains going on the layout and how fast in real train speed.


----------



## thedoc (Oct 15, 2015)

Using a pair of sensors will only give the speed for one section of the layout, and if you speed up or slow down after you pass the sensors, you don't know how fast you are going again. If you are running on a small loop at a steady speed, perhaps this would be sufficient, but for a larger layout with a longer main line run, you should be able to know the speed of the train at all points on the main line.


----------



## wvgca (Jan 21, 2013)

thedoc said:


> Using a pair of sensors will only give the speed for one section of the layout, and if you speed up or slow down after you pass the sensors, you don't know how fast you are going again. If you are running on a small loop at a steady speed, perhaps this would be sufficient, but for a larger layout with a longer main line run, you should be able to know the speed of the train at all points on the main line.



yes, exactly.. measure speed at ONE point ...

besides which, measuring speed at all points would require an 'on board' readout, with a HUGE number of sensor trips .. 

even if it was a two part system, speed detector with remote display, the sensors would have to be other than standard IR type, probably hall effect off the rolling stock wheel sets ..

I think I did see one two part with wiFi enabled, but it was around $200 I think ..


----------



## Shdwdrgn (Dec 23, 2014)

I've been planning on rigging up a tach sensor on my computerized locos, would love to build something like this to calibrate the tach speed to a real speed of each loco.


----------



## wvgca (Jan 21, 2013)

Shdwdrgn said:


> I've been planning on rigging up a tach sensor on my computerized locos, would love to build something like this to calibrate the tach speed to a real speed of each loco.


Sure, would work...

Need only one sensor, and the same type of light / dark bar tape that GunrunnerJohn uses ...on the motor .. 
or hall effect on rolling stock ..

and then calibrate with any gear reduction and wheel size ..
pretty much what thedoc was talking about...and run two I2C displays back to back for viewing, or a remote display using WiFi or similar

For my use I just want to see what speed they run past one point.. I have an old era layout, and want to match speed to the 28 step that I use... ie: step 18 would be 18 scale mph


----------



## Shdwdrgn (Dec 23, 2014)

I was actually thinking that one of the gears has some exposed area, I thought I could drill a small hole through it and use IR leds to detect the hole, then just count the milliseconds between each step... but I'll have to take a closer look at that when I get around to actually setting it up.


----------



## Lemonhawk (Sep 24, 2013)

GRJ looks like he painted a flywheel white and then put a black band across it that an optical sensor could see. It was for syncing the chug on a steam loco, but it would do as as an RPM sensor also.


----------



## wvgca (Jan 21, 2013)

Got the rest of the code done, works either way now, setup for I2C display, reports in both Kph and Mph .. sensors need to be 25mm or less from loco ..
Kph is on top, 'cause I'm from Canada 

Arduino .ino attached .. enjoy 

View attachment Train_Speedo_FINAL.ino.txt


----------



## thedoc (Oct 15, 2015)

wvgca said:


> pretty much what thedoc was talking about...and run two I2C displays back to back for viewing, or a remote display using WiFi or similar


No, I was referring to a system that used the EMF of the motor to calculate the speed of the engine, it didn't involve sensors at all.


----------



## wvgca (Jan 21, 2013)

thedoc said:


> No, I was referring to a system that used the EMF of the motor to calculate the speed of the engine, it didn't involve sensors at all.


I mis-understood...
Do you have one working in this fashion, or a link to an operating one??
I'm curious as to how they shut down the decoder, and use the generated EMF to calculate and then display scale speed?? 
Is the electronics in a seperate trailing car, or??


----------



## Shdwdrgn (Dec 23, 2014)

I was thinking about how this EMF system might work, and it occurred to me that Hall sensors are commonly used to read the speed of motors. I have a bag of some with a real short range, could be interesting to see if they work from the outside of the loco motor's case. And since it would give a much faster speed than reading one of the gears, I could flip the counter to something like steps per 100ms.

@wvgca -- thanks for posting your code, it should make an interesting read!


----------



## wvgca (Jan 21, 2013)

Shdwdrgn said:


> I was thinking about how this EMF system might work, and it occurred to me that Hall sensors are commonly used to read the speed of motors. I have a bag of some with a real short range, could be interesting to see if they work from the outside of the loco motor's case. And since it would give a much faster speed than reading one of the gears, I could flip the counter to something like steps per 100ms.
> 
> @wvgca -- thanks for posting your code, it should make an interesting read!



I thought about using BEMF last night .. and not sure if it would be a viable option ... first of all a decoder that supports BEMF so as to turn off the driver current, and then read the driven or generated voltage coming off the motor itself.. and somehow you would have to discriminate between the square / sawtooth drive waveform, and the sine wave generated waveform with an external reader .. 

by the way, the code is horribly messy, but it does work


----------



## gunrunnerjohn (Nov 10, 2010)

Lemonhawk said:


> GRJ looks like he painted a flywheel white and then put a black band across it that an optical sensor could see. It was for syncing the chug on a steam loco, but it would do as as an RPM sensor also.


It's actually a printed tape on gummed label paper. It's used for my Chuff-Generator to generate the chuff pulses.


thedoc said:


> No, I was referring to a system that used the EMF of the motor to calculate the speed of the engine, it didn't involve sensors at all.


I suspect back EMF wouldn't give you accurate readings of speed as there are too many variables in play. You need to actually lock the sensing to the wheel rotation to calculate speed accurately IMO.


----------



## thedoc (Oct 15, 2015)

wvgca said:


> I mis-understood...
> Do you have one working in this fashion, or a link to an operating one??
> I'm curious as to how they shut down the decoder, and use the generated EMF to calculate and then display scale speed??
> Is the electronics in a seperate trailing car, or??


The article was in a much older magazine that predated DCC or was when DCC was not very common, so there was no decoder involved, and I have been unable to locate the article. Also since the EMF is directly proportional to the motor speed the reading would be very accurate once calibrated. The speed display was to be built into a hand held controller, there was no electronics in the engine, that I remember.


----------



## wvgca (Jan 21, 2013)

thedoc said:


> The article was in a much older magazine that predated DCC or was when DCC was not very common, so there was no decoder involved, and I have been unable to locate the article. Also since the EMF is directly proportional to the motor speed the reading would be very accurate once calibrated. The speed display was to be built into a hand held controller, there was no electronics in the engine, that I remember.


Okay .. they must have had some circuitry to shut down the drive signal to be able to read the generated voltage .. it's seems a bit cumbersome to deal with internal gear ratios to calculate scale speed.. 

With further consideration, a possible version may be something mounted in a boxcar, with rail power pickup, either for DC or DCC, a loco needs close to 5V in DC to move, so that's enough ..simplest may be a sensor that times wheel revolution, with a 33" wheel, the code wouldn't care about scale, it would calculate in 1:1 speed, and the 33" is very common to most rolling stock that would have room for a couple of displays .. just using a small 2mmx1mm magnet inside the wheel and a hall effect sensor is pretty simple, and low cost. ...

wonder if I have parts to try??


----------



## Shdwdrgn (Dec 23, 2014)

@wvgca -- I think one of us is confused here. My understanding is that EMF is basically the radio noise that is put out by any motor, while you seem to be referring to reading the generated voltage from a motor as it coasts to a stop (which would be nearly zero if you have a worm drive). Reading the radio noise is a passive function which requires the motor to continue running.


----------



## wvgca (Jan 21, 2013)

Shdwdrgn said:


> @wvgca -- I think one of us is confused here. My understanding is that EMF is basically the radio noise that is put out by any motor, while you seem to be referring to reading the generated voltage from a motor as it coasts to a stop (which would be nearly zero if you have a worm drive). Reading the radio noise is a passive function which requires the motor to continue running.



back EMF is just the voltage generated by an electric motor while it's spinning with no power applied, just being a generator ..
You may be thinking of EMI or RFI, which are basically radiated 'noise' ..

DCC decoders with BEMF shut down drive power momentarily and check generated voltage to adjust 'constant speed' drive voltage to the motor while going up or down grades and similar .

It's great fun to watch two loco's in a consist when both have BEMF adjusting turned on ..easy to tell if there's a real metal Kadee coupler in between them or a plastic one


----------



## Shdwdrgn (Dec 23, 2014)

OK but he mentioned that this article was pre-DCC, which just further makes me think they were simply monitoring the radio noise, which should be pretty consistent for any given motor.


----------



## gunrunnerjohn (Nov 10, 2010)

thedoc said:


> Also since the EMF is directly proportional to the motor speed the reading would be very accurate once calibrated. The speed display was to be built into a hand held controller, there was no electronics in the engine, that I remember.


I'd like to see that article. In discussions with folks that are well versed with back-EMF control at ERR, I believe it was mentioned that trying to generate chuffs from the information wouldn't be exact enough. If you can't keep the timing well enough to generate a chuff, it's hard to believe you'd actually have accurate speed information. It may have been done, but that doesn't say it was accurate. You also have to continually integrate the changes on the fly, and as the motor speed changes, I'm guessing errors would creep in as well.

Doing it with a tach pulse is easy, you count.


----------



## crusader27529 (Apr 3, 2016)

wvgca said:


> Okay .. they must have had some circuitry to shut down the drive signal to be able to read the generated voltage .. it's seems a bit cumbersome to deal with internal gear ratios to calculate scale speed..
> 
> With further consideration, a possible version may be something mounted in a boxcar, with rail power pickup, either for DC or DCC, a loco needs close to 5V in DC to move, so that's enough ..simplest may be a sensor that times wheel revolution, with a 33" wheel, the code wouldn't care about scale, it would calculate in 1:1 speed, and the 33" is very common to most rolling stock that would have room for a couple of displays .. just using a small 2mmx1mm magnet inside the wheel and a hall effect sensor is pretty simple, and low cost. ...
> 
> wonder if I have parts to try??


I'm designing a similar speedometer system to sell so my local club can generate some money to move to a larger location (and a new layout, since the old one will have to be demolished), using 5 mounted 2mm magnets mounted on the inside of a 36" scale wheel.

The neatest part of the design(as you noted) is that it will work on any scale as long as the same sized scale wheel is used, with no code changes. The current design uses the same type LCD display you have, is powered by the rails, and has keep alive caps to prevent resets of the Arduino NANO when going over dead spots.

I plan on offering a kit (with various versions based on what you want to do yourself) and a complete car. The minimal kit will include a power pickup truck, the programmed Arduino NANO and a PCB to mount it all on. The power parts also will fit on the same PCB. There are no sophisticated or hard-to-get parts in the design. The design allows for 2 power pickip trucks if you wish, battery power instead of power trucks (the one supplied truck is required, because that's where the Hall Effect sensor is mounted), or a full design with the keep alive super capacitors. The power regulation part is a DC-DC buck converter from China, fed from a simple diode bridge, fed from the tracks.

There already is a design to use a wireless remote readout instead of the onboard LCD. I'm trying to make it small enough for N-scale, but that won't happen until I design a completely custom PCB to minimize size......I'm using as many purchased modules as I can for cost, from China. I doubt that I can make a custom PCB and populate it as required for less than what it costs to purchase completed modules from China.


----------



## wvgca (Jan 21, 2013)

crusader27529 said:


> I'm designing a similar speedometer system to sell so my local club can generate some money to move to a larger location (and a new layout, since the old one will have to be demolished), using 5 mounted 2mm magnets mounted on the inside of a 36" scale wheel.
> .


I have done basically the same last week, 1 2mmx1mm magnet, OH360U non latch hall sensor, and an arduino .. both trucks for power pickup, and a single large 5.5V supercap on input .. As soon as the OLED 2 digit display comes in I will use that instead of a 1602 for better visibility Choice of Kms or Mph in code, and using the extra 10ths digit below 10mph/ kph ..just two digits whole above that, basic four sample averaging, and return to zero display on two second absence of falling trigger level ..nothing fancy ...I use just a simple pinout extender board for the Nano ..
boxcar mobile based on thedoc's suggestion .. 

Good luck with your fund raiser


----------

