# Mobile Train SpeedoMeter



## wvgca (Jan 21, 2013)

Suggested by another member, slightly different than the stationary speedometer ..
Anyways, Arduino Nano with a non latching Hall Effect sensor triggered by a wheelset mounted 2mm x 1mm rare earth magnet [or super magnet] ..
I used the OH360U sensor , active low .with a single trigger magnet ..
The code [as current] displays both mph and kph, and is coded for a 33" wheel, readily changes to a 36" if end user requires..and is not scale dependant ..except for physical room to mount the electronics...
The display shows speed [including tenths] below 10 mph / kph, and whole numbers above that ..
Currently the display being used [and coded for], is a standard 1602 /I2C, but will be replaced with a two digit seven segment when they come in ..just for easier viewing at longer distances ..
Results show to both display and Aruino IDE serial monitor as currently coded..
Hard parts are the nano, I2c display, sensor, one magnet & one resistor ...
For installation in a boxcar or similar .. other parts would be power pickup trucks, a small capacitor fr possible power interruptions, a bridge, and a voltage regulator ..ideally for DCC or AC / DC voltages consistently over 10V ..
I'm waiting for the larger displays before I build myself one..
If anyone wants the code, I can post it..


----------



## jlc41 (Feb 16, 2016)

Thanks for the information. I will at some time get to it. My grand son is always asking me how fast the trains are running.


----------



## wvgca (Jan 21, 2013)

A few images of this project, and the code, currently for 1602 lcd with I2C iterface

























View attachment train_speedo_Mobile_I2C_1602_LCD.ino.txt


----------



## RT_Coker (Dec 6, 2012)

Great Idea! Here is another way the approach to the design for anybody that might be interested.

The Bluno Beetle board could be used with just a battery, on/off switch and tachometer sensor. The display would be a hand-held Adriano-thing with a slightly modified “Bluno Basic Demo” App.
Bob


----------



## wvgca (Jan 21, 2013)

RT_Coker said:


> Great Idea! Here is another way the approach to the design for anybody that might be interested.
> 
> The Bluno Beetle board could be used with just a battery, on/off switch and tachometer sensor. The display would be a hand-held Adriano-thing with a slightly modified “Bluno Basic Demo” App.
> Bob


Yes, a good alternative, especially for those wanting a remote display,


----------



## crusader27529 (Apr 3, 2016)

Here are some photos of my current project....it's in pre-production stage, but alkmost ready.....

It still needs tweaking of the packaging, and the obvious size issues are because my home-made PCBs are single sided, and to put all this together, I need access from the 'wrong' side of the PCBs to make the solder connections.....that causes the connectors to be significantly LONGER than those that will be used eventually.

The display shows MPH & KPH, and on the second line shows average speed and odometer in scale miles:





































You can plainly see the magnets around the wheel and the hall effect sensor mounted on the power pickup truck.


----------



## Lemonhawk (Sep 24, 2013)

You're computer mouse tracks motion, so why not use something like a laser mouse to determine speed and distance, no special connections and would work in no/low light.


----------



## gunrunnerjohn (Nov 10, 2010)

I'm guessing any mouse mechanism would have a real problem with the irregular surface of the roadbed between the rails.

I do have a question, do you really need that many magnets? Wouldn't one or two give you sufficient accuracy?

BTW, have you looked at OSH Park for prototype PCB? It's my "go to" place for small quantities of PC boards.


----------



## wvgca (Jan 21, 2013)

I went a slightly different approach on mine, just the sensor on the truck, no pcb, three wires up .. and no pcb for the nano ..three wires to sensor , and four to the current I2C display ..
I still prefer 7segment displays for visibility, but am currently trying double height numbers using both lines for the digits .. 
I assume that you are running averaging on the speed, if the magnets are even 10 thou out of the correct angle, it will change the speed reading constantly..

The blue display does have nicer contrast than the yellow ones that I have


----------



## crusader27529 (Apr 3, 2016)

gunrunnerjohn said:


> I'm guessing any mouse mechanism would have a real problem with the irregular surface of the roadbed between the rails.
> 
> I do have a question, do you really need that many magnets? Wouldn't one or two give you sufficient accuracy?
> 
> BTW, have you looked at OSH Park for prototype PCB? It's my "go to" place for small quantities of PC boards.


I'm retired and 'poor', plus sort of cheap.....final prototypes and probably initial 'production' will have the boards made professionally. For now, homemade is fine, and I'm quite good at it. I use laser transfer to copper clad PCB, and I can make a PCB in an hour, depending on how many holes I need to drill. The only real problem I have with the homemade stuff is that the copper is nowhere near as robust as a professionally made part....I can lift the traces much too easily, but that's a tradeoff I can live with for now.

The code averages the timings of all the magnet detections primarily because motion start and stop are not accurate at all.

The code also does NOT use a simple detection of the magnet to trigger each part of the timing.....the initial detection presets the logic, and when the magnet detection goes away, that action is the trigger.

All that really requires more than one magnet, and actually, the more magnets yield better accuracy...I use 5, which yields 4 timings.

I agree on your assesment of the mouse HW for movement detection, as the focus distance is critical, PLUS the HW would need to decode what the mouse HW was sending...it send a pulse train which isn't simplistic.


----------



## crusader27529 (Apr 3, 2016)

wvgca said:


> I went a slightly different approach on mine, just the sensor on the truck, no pcb, three wires up .. and no pcb for the nano ..three wires to sensor , and four to the current I2C display ..
> I still prefer 7segment displays for visibility, but am currently trying double height numbers using both lines for the digits ..
> I assume that you are running averaging on the speed, if the magnets are even 10 thou out of the correct angle, it will change the speed reading constantly..
> 
> The blue display does have nicer contrast than the yellow ones that I have


I'm trying to make something for sale, so PCBs are a necessity. Unfortunately, the most expensive part is the power pickup truck. Almost all the other parts are Asia purchases.

I originally started to use 7 segment displays, and I have about 300 of them laying around from other jobs that I did, but they are power hogs, requiring 20ma per segment, so worst case was almost 400ma for the whole setup. I started to use a LM317 regulator, but dropping 11volts at 400ma was just too much heat to dissapate(4+ watts), so I went to a DC-DC converter and the LCD display. Even when I add the 433mhz radio(running at minimal power output), the current load will be less than 100ma or so. With +90% efficiency of the buck converter, the thermal load is acceptable for mounting inside an HO scale or larger car. I've decided that N-scale isn't practical, as the radio or display is just too large......


----------



## wvgca (Jan 21, 2013)

crusader27529 said:


> Unfortunately, the most expensive part is the power pickup truck.


I honestly have no idea of what 'store bought' power pickup trucks are worth, 
I just use metal wheels and a piece of bronze wire, as shown below


----------



## Bwells (Mar 30, 2014)

crusader27529 said:


> Unfortunately, the most expensive part is the power pickup truck.
> Yes, it is. Here is a link to an Athearn caboose truck with all wheel pickup but they are pricey. You can see the generator on the one truck and they do have wires attached to them but they aren't very long.
> http://www.athearn.com/Products/Default.aspx?ProdID=ATHG4593


----------



## crusader27529 (Apr 3, 2016)

The ones I found aren't anywhere that pricey.....like $4-5 each.

I'd still need a PCB to mount the Hall Effect sensor stuff.


----------



## wvgca (Jan 21, 2013)

I finally received my seven segment displays, and no matter how I try to mount them for good visibility, they still look horrible ...and using LCD display makes to hard to see at longer distances, plus half the time it's upside down anyways
So I ordered some WiFi modules, and will try to send speedometer data to PC or phone..

Might also try mounting them on the sides of a boxcar, for some reason never thought of that until now.. always tried top mounting for some reason?


----------



## crusader27529 (Apr 3, 2016)

wvgca said:


> I finally received my seven segment displays, and no matter how I try to mount them for good visibility, they still look horrible ...and using LCD display makes to hard to see at longer distances, plus half the time it's upside down anyways
> So I ordered some WiFi modules, and will try to send speedometer data to PC or phone..
> 
> Might also try mounting them on the sides of a boxcar, for some reason never thought of that until now.. always tried top mounting for some reason?


I'm using HC-12 radios, althouigh I haven't actually tested the link yet.....I have the same issues trying to read a moving display.

I've decided to make my speedometer cars do dual duty......they can send(and display) data or act as a receiver to display the data. I expect the receiving car to sit in a powered siding while the other car gets dragged around the layout.


----------



## gunrunnerjohn (Nov 10, 2010)

The remote display sounds like the cool way to do it.


----------



## wvgca (Jan 21, 2013)

gunrunnerjohn said:


> The remote display sounds like the cool way to do it.


That's probably the way it may wind up in the end, I should have some of the ESP WiFi modules, but couldn't find them ..

But I did find some four digit seven segment modules, a little bit smaller, look like the 0.59 height .. left overs from an old project, and still have a half dozen left .. easy hookup, only four wires, and I think they were fairly low power draw.. old project was run on a 9V battery..maybe just paint over the first digit , maybe second as well, don't really need the extra decimal readout ..no real need for it to read a hundred miles per hour .. dunno?

In the photo they are at full brightness, have to lower it somewhat, 

They should fit into the small two bay hopper that I put the sensor into ..Minor snag right now, I was hoping to use the AtTiny85, found a couple of those still in the anti static pouches, but it looks like it has an issue with the TM1637 display library ..sigh .. 

I might have to go with the Nano, but I was saving those for project builds that actually generate income..a grain bin temperature reader .. have to look around some more , there should some pro mini's someplace ...


----------



## crusader27529 (Apr 3, 2016)

I don't know how much control you have over those 7-segment displays, but if you had complete control, you could alternately display the data upside down periodically, so it could be read from either direction.....I did something like that on a project decades ago, and it worked well, and was easy to do, as long as I had complete control of the decode for the display.


----------



## Lemonhawk (Sep 24, 2013)

If you have enough display control you could have speed on the minutes part upside down and the hours rightside up. Hm, might be just as confusing. I think billboard style on the side of the boxcar is the best. What else could you display on the other 2 digits that would have meaning and not be confusing. Acceleration, Lateral g's ( for those tight turns you take at high speed? I'm wondering if maybe you should just get some really large display digits for the wall?


----------



## wvgca (Jan 21, 2013)

Had some free time this evening ... pretty much done ..


----------



## jlc41 (Feb 16, 2016)

wvgca, nice project. Just what my grandson wants. He is always asking how fast are the trains going. Maybe with your help I could build or buy one from you.


----------



## wvgca (Jan 21, 2013)

Sure, I can make a schematic and a bill of materials, and upload it later on ..


----------



## gunrunnerjohn (Nov 10, 2010)

I want to see an O-gauge model.


----------



## wvgca (Jan 21, 2013)

gunrunnerjohn said:


> I want to see an O-gauge model.


Sure, I will upload a photo twice as wide and twice as tall, lol

Seriously though, the code is scale transparent, it treats the wheel as being actually a 33" diameter, so it doesn't matter what scale it's working with, as long as there is physical room for the components ..


----------



## gunrunnerjohn (Nov 10, 2010)

You do realize I was kidding.


----------



## jlc41 (Feb 16, 2016)

wvgca, thank sir.


----------



## Lemonhawk (Sep 24, 2013)

John, the display and the Nano computer will look a little smaller on the O scale version. I keep a Nano next to the computer I use most of the time, just to try out things like servo control, GRBL (CNC firmware) and whatever project triggers something. Takes me back to the days of the Intel 8080, but with a lot less hassle!


----------



## gunrunnerjohn (Nov 10, 2010)

The I8080, a blast from the past! 

I worked on the first large scale use of the I8080 processor, the Univac BC/7 Computer. At that time, in quantity 100, the I8080 chips were $310/ea! My, how times have changed.


----------



## wvgca (Jan 21, 2013)

Here's a basic schematic, and bill of materials









View attachment train.speedo.mobile.7segment.BOM.txt


----------



## gunrunnerjohn (Nov 10, 2010)

I'm guessing the code running on the Arduino is also going to be required. 

A source for the displays would be nice as well.


----------



## wvgca (Jan 21, 2013)

gunrunnerjohn said:


> I'm guessing the code running on the Arduino is also going to be required.
> 
> A source for the displays would be nice as well.


I just need to clean up the code first .. I'm a messy coder 

Code attached
View attachment Hall_Mobile_Speedo_7segment_Final.ino.txt


I bought these displays from .. 
http://www.ebay.ca/itm/161939143063?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

They were 0.99 each, good value


----------



## crusader27529 (Apr 3, 2016)

On this line:

attachInterrupt(0, rpm_fun, FALLING);

Shouldn't it be pin 2 instead of pin 0???

I've never used interrupts on an Arduino, so I could be wrong......


----------



## wvgca (Jan 21, 2013)

crusader27529 said:


> On this line:
> 
> attachInterrupt(0, rpm_fun, FALLING);
> 
> ...


Well, kinda yes and kinda no ...
from the arduino.cc description ..

"The processor at the heart of any Arduino has two different kinds of interrupts: “external”, and “pin change”. There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove), INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges, or on low level. The triggers are interpreted by hardware, and the interrupt is very fast.", 

so actually either way will work, just a personal preference.. I'm a messy coder...


----------



## crusader27529 (Apr 3, 2016)

wvgca said:


> Well, kinda yes and kinda no ...
> from the arduino.cc description ..
> 
> "The processor at the heart of any Arduino has two different kinds of interrupts: “external”, and “pin change”. There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove), INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges, or on low level. The triggers are interpreted by hardware, and the interrupt is very fast.",
> ...


OK, I didn't understand the limitations of the arduino interrupts....int0 is indeed tied to the correct pin 2 as on the schematic. I thought that the 0 was the pin number, not the choice of which interrupt.

Sorry for the misunderstanding on how the interrupts were defined in the code.

BTW, your code is fine, and quite minimal......my code for my speedometer is about 1200 lines, but that includes lots of documentation and explanations of how thing are supposed to operate. I also have about 10 different compile time switches to control lots of options, which also increases the number of lines.


----------



## wvgca (Jan 21, 2013)

crusader27529 ..
I think I saw a screen pic of yours, much more involved, seems like you have average speed, and mileage accumulators .. fancier end result
This one here turned out okay with the seven segment display ... if i get some free time may tie in a ESP8266 for remote viewing ... maybe


----------



## jlc41 (Feb 16, 2016)

wvgca, thanks again for the information.


----------

