Model Train Forum banner

Quesion if Arduino is a possible good solution for my wants

3.2K views 31 replies 7 participants last post by  johnfm3  
#1 ·
I am considering dipping my feet into the use of Arduino. There are mechanical solutions involving the use of Double Throw Double Pole and momentary switches, but I am looking for something a bit more with a single momentary switch. As I learn from my son's layout for when I build my layout (wife approving of course).

I have a DC track for my 4yr old son. I am keeping power very simple, even though its quite complex. What I have built so far is in prep for DCC in the years to come.

I have a train yard puzzle where the train has to zig zag off the inner loop to the end where the engine house is. This part is made up of 4 track power segments which are electronicly isolated on both rails.

Image



If I wanted to use 2 DPDT switches, 1 would be used to alternate which of the 2 left tracks are powered, the second would do the same with the right 2 tracks.

What I am interested in is the use of a Arduino (maybe mega or uno) to run 2 relays (I think) to alternate between 2 track legs. To simplify things, ideally using on 2 momentary switches. I have seen momentary switches which turn from green to red, which I can use to indicate which track has power.

My second Arduino project is more common. I am looking for a good turnout control for RailCrew switch machines. They use 2 wires like Kato. The problem I am want to over come is the 4 turnout limitation. Some form of stackable board method where I can control 13 turnouts.

The ideal solution would be where all of this could be done with 1 Arduino. If I apply some digital knowledge, 5 channels is good for 32 addressable results. So if I can use some of that logic and stackable boards, that would allow me to keep the physical of this simple. Just more program dev work.

Thanks,
John
 
#2 ·
So here is another question. On the Arduino web site, they sell the Mega 2560 Rev3 for about $50. I search for "Arduino Mega 2560 Rev3" on ebay and find what looks like compatible devices from other manufacturers. Ex ATMega, SunFounder, Elegoo.... Is there any opinions as to what one to buy, or should I stick with name brand? There was a add for 3 ATMega's for $50. When 1 of the real ones is the same price, I get skeptical. Then again, I am a noob in this topic.

John
 
#4 ·
don't understand what you want the arduino to do.

of course an arduino can control track power using relays, but won't you need some switches to tell it which tracks to power and wouldn't it be easier to just use those switches to directly power the tracks? (you only need an SPDT switch or even separate SPST switches to power one rail of each track)

The problem I am want to over come is the 4 turnout limitation. Some form of stackable board method where I can control 13 turnouts.
again not clear what the problem is and how an arduino possibly solves it.

again, panel switches will be needed to select a turnout position. looks like the railcrew machines are stall motors similar to Tortoise machines that are controlled by switching the polarity to the machine and a single DPDT panel switch can control the machine without the need for an arduino

if an arduino were used, while output pins would be needed for the turnout machines, inputs would be needed for the panel switches
 
#9 ·
don't understand what you want the arduino to do....

....if an arduino were used, while output pins would be needed for the turnout machines, inputs would be needed for the panel switches
As stated in my original post, there are mechanical solutions for what I want to do. This is about my dipping into learning how Arduino can replace mechanical solutions. The idea of having a single soft switch which can cycle thru the various turnout configurations is much easier than 2 toggle switches. As I wrote this, I had no clue as to the hardware options with Arduino.

With a 3 wire Snap Switch, you need 2 relays to run the switch. On the relay board I saw used by a YouTube creator, you use the Common and Normally Open so you can digitally create the momentary electrical connection when triggered with a momentary switch. Then I found a Youtuber who showed using a Arduino board for Kato style switches (which I then found out was a 2 wire switch where polarity is reversed). But it can only run 2 switch machines.

All of these add on boards add wires in the Arduino environment before even going to the train layout. By using shields (I am guessing that is what they are called), they sit on top of the Arduino in a stack and minimize the wiring mess of the Arduino env.

You start looking at 1 board running 2 turnouts, and that adds up to alot of additional wires and power. Where getting things stacked some may help cut down on that mess. I have 13 turnouts to deal with.

Regarding the track power of the ladder, in those 4 legs, I want no more than 2 connected legs to have power at any 1 time. Ideally I would like it be able to be turned off completely as this segment of the track is electrically isolated from the inner and outer loops. So if you look at the 4 legs starting with 1 on the left top, 2 on the Right top, 3 on the Left bottom, 4 on the Right bottom, I want the following....

All off
Track 1 & 2 On
Track 2 & 3 On
Track 3 & 4 On

2 DPDT switches can do this easily. I want to see about doing the same with Arduino. Unless there is a On Off On style relay, I can not see doing this with out 3 relays per leg. Again, this adds alot of extra. 2 Relays (Normally Closed / Normally Open) can do most what I want except turn left or right segment or everything off.

Are there more shield options for Uno? The reason the Mega is the increased number of channels. Unless I attempt to use the digital pins. That is basic binary, 8 pins could give me 256 different addressable states.
 
#6 ·
you are kinda vauge on what you want it to do .... of course it will, but there are other alternatives out there ....
using an arduino to throw a relay isn't much different that using a switch to throw the relay ...
by the way, i use mostly nanos for the size of them , on those get the rev3 if you can ..
 
#11 ·
To further explain the ladder situation.... Looking at he picture above, imagine the 2 passenger cars were missing and I wanted to park a train from the inner loop in there spot on leg 1. But I have 3 other legs with trains on them. In DCC this would not even be a problem. In DC, this becomes more of a issue. Alternating between track 1 & 3 or 2 & 4 is easy. But I need to be able to turn off track 2 & 4 altogether to avoid those 2 trains from moving.
 
#14 ·
I only suggested uno because it's a place to start, still popular and readily available. It's a soft suggestion. Really if you zero programming and no real hw experience.. I'm not sure this makes sense except with the idea you want to learn, not actually get to your solution. You might get to it. Then again, you might not.
 
#17 ·
As I didnt want to come off as erragant, and I have no reason too, I didnt specify my skill set. I am Sr System Administrator. Spent 15 yrs a MS and now at Warner Media. My software dev background includes Powershell tool design and dev around Server and Active Directory managment. I know Active Directory, Servers, and Enterprise network hardware, as well as remote management of such devices using powershell. Not IoT or Arduino.
 
#15 ·
still not clear. sounds like you're looking for a reason to use an Arduino.

as for relays, presumably your working with twin coil switch machines which require momentary power. a SPDT relay can route power to one of 2 coils and a common relay for all machines could momentarily provide power. SPDT panel switches can be monitored for changes to both drive the routing relay and pulse the power relay

Arduino UNO shields may be designed to stack on one another but, there must be separate connections to the relays and not many relays can be on a single stackable board. there are non-stackable relay boards.

not sure what your thinking about controlling track power with an Arduino. guessing you want to hit a momentary button that routes power using relays to tracks 1&2, 2&3 or 3&4. could be done with latching relays, momentary panel switches and diodes.

arduino based system using relays to drive 30 tortoise machines to align turnouts for specific routes thru an interlock by pressing a pair of buttons on either side of the interlock
Image
 
#16 ·
still not clear. sounds like you're looking for a reason to use an Arduino.
I suggested this in my original post. This is complete overkill, but why not take the opportunity to learn on a small layout before adding to a much larger one.

as for relays, presumably your working with twin coil switch machines which require momentary power. a SPDT relay can route power to one of 2 coils and a common relay for all machines could momentarily provide power. SPDT panel switches can be monitored for changes to both drive the routing relay and pulse the power relay
In my original post, I comment on using RailCrew switch machines. Which need a motor controller as they are similar to Kato switches where you have 2 wires and a momentary application of power where reversing the polarity will reverse the direction. These relays are not useful for that use-case. The track power is the harder issue to tackle.

For right now, I am digging into the track power question.

not sure what your thinking about controlling track power with an Arduino. guessing you want to hit a momentary button that routes power using relays to tracks 1&2, 2&3 or 3&4. could be done with latching relays, momentary panel switches and diodes.
Thats the point. For a 4yr old, this is a great start. He has used Atlas switches on my prior layout, but this puzzle will push him further. I can later add 1 switch per leg and add complexity to the problem solving. Single button momentary press and led indicators to show the results. Do you have any examples of what your speaking about regarding Latching relays and such?
 
#20 ·
Starting with the want of Track Power control on the 4 legs of the yard ladder, after some conversations with others more knowledgeable than I, I may have completely over estimated the number of relays per yard ladder leg. I may be able to get away with only 2 relays per pair of tracks. Where they share a common wire om 1 rail and the the first of two relays switches between the second rail of the 2 tracks. The first relay common terminal will get its power from the Normally open side of the second relay. So that when both relays have low signals coming in, 1 leg will be selected and all power will be off.

The intention is to use soft touch momentary switches to toggle thru the different configs on each side of the ladder. To clarify, use 2 switches. 1 per side.

All this said, I have pulled the trigger on a Uno Rev3 and a 4 relay shield to place on top of Uno. Well give this a shot. More to come whether I succeed or fail.

John
 
#21 ·
So after a rocky start, I seem to have a good path on my Journey of using Arduino in my layout.

I have questions regarding the use of resistors with LEDs.

When selecting resistance to use in a LED circuit, you take the voltage difference of the supply voltage to the forward voltage of the LED used (assuming 1 led). Ex for a 12v supply on a single LED with a 2.5v Forward Voltage, my delta would be 9.5V. That voltage divided by .020 amps (20mA) would be 475ohms. So I would add a resistor of 470 Ohm (rounded down 5ohms) to the cathode (I think ~ ground side) of the LED hooked up to a 12v source.

Yet, I bought a LED from a supplier who provided 2.2Kohms. When math is applied, I get 44v on the resistor at 20mA which means a supply voltage of 46.5v.

What gives? What is with the recommendation of resistor values? What general guideline is safe to use if Ohms Law is not proving what is being recommended by suppliers?
 
#22 ·
Since I know nothing ive tried to use calculators like this.


There's other calculators and explainers. There's also charts, rules of thumb and all that.

It helps to have the spec of what you bought. If on the hand you just have a pile of LEDs and know nothing about them, how about starting with a resistor that's surely way to big and then working down to a light level you like?
 
#23 ·
the voltage is constant, not the 20 ma thru the circuit.

using your example of 12V supply and 2.5 Vled, results in 4.3 ma

20 ma is typically the max. todays LEDs are more efficient and often too bright.

there's not direct mapping between light intensity and current, so the appropriate resistance for the desired intensity and supply voltages varies. it's usually safe to start with a 1k resistor and i've used across the track which is ~14V
 
#25 ·
Gregc, I bought 150 ohm, 330 ohm, 470 ohm, and 1K ohm. And I bought these bi color (Red/Green) LEDs...

...which have different forward voltage depending on color.

How do I determine a good starting resistance?


Severn, Thanks for those links. I will dig into them over lunch today. Hopefully they will provide some guidance for my questions here.
 
#26 ·
as i said, there's no common relationship between light intensity and current. you'll need to eyeball the intensities to match unless you have some sort of light meter that covers the different wavelengths

i recently bought a box of 3mm red, yellow and green LEDs. presumably all from the same manufacturer and of similar type. i found that two had about the same intensity with (lets say) 330 Ohm resistor but the green LED needed a 1.2k resistor. (i have boxes of different value resistors to choose from)

based on what i've read, different manufacturers may require different resistor values
 
#28 ·
To expand on the topic of resistors....

I have a question regarding the use of a resistor on the Ground side of a momentary switch where a trigger wire is connected and goes to a Analog pin.

There seems to be various opinions as to the size of that resistor between ground and the switch. From 330ohm to 1k.

What are the general guidelines to picking the appropriate value resistor for this use?
 
#31 ·
You could always make an LED tester with a variable resistor in the circuit to see what the LED looks looks like then measure the pot to see what resistor you need, you only need to be close. Remember that LED's are not like incandescent bulbs in that as you put more resistance (higher ohms) in the circuit the LED will not dim to zero, it won't even get dim it will just go out. Generally I use 1k or more on 12v circuits. You can make LED's dim from full bright to zero, but you do it with PWM which your Arduino is fully capable of doing. I also suggest you look into NEOPIXELS LED light strings. The Arduino is perfectly capable of driving long strings (likely with an external power supply on the Neopixels, but then you have full control of each individual LED on the string in terms of color and brightness. You will have a blast messing with them!
 
#32 ·
I also suggest you look into NEOPIXELS LED light strings. The Arduino is perfectly capable of driving long strings (likely with an external power supply on the Neopixels, but then you have full control of each individual LED on the string in terms of color and brightness. You will have a blast messing with them!
Ok, the Neopixels look like a cool option. Something I will have to consider for some of the automation goals I have.