Building a train control board (Lego trains)

I'm building a large Lego train layout and want to make a custom control panel for it. I've looked at the code available for the Lego IR system and am pretty confident I can make the software side work. Here's what I want to have, so I can control 3 trains:

3 Large throttle levers (something similar to these boat throttles) but simpler - I just want a big handle w/ a pot, not anything w/ fancy expensive electronics that I can mount on a box
1 big E-Stop button
3 switches to select train direction between forward and reverse

This will be hooked to a arduino board to convert the inputs to the proper Lego IR signals and blasted out an IR LED.

Any idea where to get the throttle levers? I can't find anything cheap enough - everything I've found from googling has been actual throttle controls. I just want a handle w/ a pot that I can get a signal from.

Any problem using an e-stop button that's designed for big, high powered real equipment? I just want to have it be a simple on/off switch - when it's pulled out, things can run, but when pressed, the "stop" signal gets sent out to all three trains and then nothing else is transmitted till it's pulled out again.

You could make your own levers and fit them to pots.

All the large emergency buttons I've seen are just normal switches, so you can use them for anything you like.

The forward/reverse switches and just any old toggle switch because your Arduino actually does the F/R stuff via the protocol.


Rob

Graynomad:
You could make your own levers and fit them to pots.

Ah, I could, if I had any fabrication skills :slight_smile:

Yes you would need some skill in that area.

What about the large lever pots used on audio decks/mixers etc.


Rob

Sure, something like this (Professional Video Mixing Console, Transmission Control Full. Stock Photo, Picture And Royalty Free Image. Image 5386902.) would work too. Any idea where to get those? Maybe my google skills are just weak today, but I havne't found anything. Looks like these levers are more on video equipment than audio...

worst case I'll just go with something like 100mm slide pots, but bigger is better. I want to make this really kid-friendly and cool looking, so small knobs aren't good enough :slight_smile:

Couldn't you make them out of Lego?

I can't find much either. There's these

They look cheap eh :slight_smile:

And at the other end of the sprectrum there's this

Surely you could bend a strip of aluminum, drill a 1/4" hole and cut a slot. I'd use a large wire-wound pot, I think it would have a better feel. And support the shaft on the other end.

Ok here's another idea. Fix the shaft and rotate the pot. You can use the nuts that are usually used to fix the pot to a panel, your lever just becomes the panel. That way pretty much all you have to do is drill a hole in the aluminum strip. A couple of U-bolts would hold the shaft well enough.


Rob

I saw that specsensors one. Also found this: http://parts.digikey.com/1/parts/1691404-joystick-t-bar-fader-tbf-po.html Looks perfect, but it's $138 a piece. Not in the budget here.

Guess I'll keep looking and thinking. Sure, I could just bend some Al strip, but I'd prefer something nicer. Also might build a handle out of Lego... we'll see...

Still haven't found the levers I want, though I do have a possible lead thanks to many many pages of google results...

However, last night I tried wiring up some parts and writing some code - and it actually worked! I had just 1 IR LED (1.2V, 100ma) though - so range wasn't great w/ the LED pointed up at the white ceiling and the train on the table (with the receiver pointed up). I just used a normal pot to control the speed and everything worked great.

Now thinking towards expanding... thinking about upping the system to 9 IR LEDs to give better coverage. (3 strings of 3, w/ 15ohm resistors on each string, all run off the 5V rail from the arduino and a transistor to switch them)

  1. Any reason not to spread them out? It's a fixed table, so I could put the three sets of LEDs in different places (or even mount them on the ceiling pointed down to really boost efficiency). Would just running something like phone wire or ethernet wire from the control box work? If so, should I put the resistor w/ the LEDs or in the control box... heck, I might even put jacks on the box to be able to add however many strings of LEDs I want/need...

2. I'd like to add a visible LED in parallel, so I can see when signals are being sent. Can I just hook a second transistor up to the same pin on the arduino and then connect a green LED to that? I've used my camera to monitor the IR one blasting, but a visible indicator would be easier. Never mind, did something simpler after I got some sleep... just put a resistor and LED in series between the output pin and the transistor - so it blinks exactly the same as the IR does. Seems to work perfectly. Any flaw with going that route?

Latest update, and some new questions...

Decided to use a Saitek Throttle Quadrant as the hardware. Took it apart, got the wiring basically figured out, but there's not much room in there for putting in a new control board. Current plan is to replace the 6 buttons below the levers with 3 toggle switches (to select forward/reverse direction). That means I need 5v, ground, and 6 signal lines. Sounds to me like a great time to use some cat5 to connect the "throttle box" to an "electronics box" with an arduino in it. I'll mount rj45 jacks on both and then I can grab whatever length ethernet cable to connect them that I want. I can walk around with the controller that way. (and yes, I know I'm not doing anything actually "ethernet" here, just using it as a 8 conductor wire)

Next, I'm going to solder everything up on some perf board. Radioshack sells aMatching Printed Circuit Board that's laid out like a breadboard for easy transfer. I'll stick that inside a standard wiring box (like electrical outlets use) with a faceplate that has 2 rj45 jacks. One will be input from the throttles, and the other is output to the IR LEDs. I'm going to basically use the circuit from the Sparkfun Arduino breadboard kit to make my own board, since I don't need a lot of the stuff on the Duemilanove for this.

The LEDs... I think I want to put them on the ceiling pointing down, for better signal strength. Monoprice sells cool little wall mount boxes that already have an RJ45 jack in them. I'll put an LED in each one and use rj45 splitters to divide the signal around. Basically, I'll use pins 1-7 in the cat5 wiring as 7 separate voltage lines (each connected back to a separate transistor on the main circuit board) and pin 8 as a shared ground. Each LED box (I'll make 7 of them) will have a single IR LED connected to a different pin, so that each one has a dedicated power supply to it rather than being parallel or serial connected. And this way, I can run a single ethernet cable from the control box up to the ceiling, and then split it out there to put the LEDs wherever I need for best coverage. Or at a train show where there's no (reachable) ceiling to use, I could put up a couple poles with the LED boxes on them.

Now, my current prototype setup has 4 LEDs on a breadboard, with 4 transistors. That's all being run off the 5V rail from the arduino and a single pin controlling them. I forget offhand what resistor I've got on the LEDs, but it's giving them in theory 250ma each (LEDs are rated at 100ma continuous, 2A peak). I think the regulator on the Duemilanove can do 800ma, so I'm not getting full power, right?

Questions:

  1. Making my own board, would it be worth using a pair of 7805s to give 1 to just the arduino and 1 to the LEDs? My current power supply is 12v 1A, but I figure I'll replace that since it's old and awkward to use. I'll probably get something that's around 9V 2A to have plenty of power, and less strain on the 7805s than the 12v.

  2. Do I need to / should I add a cap to provide more power to the LEDs? I know nothing about that, so that's why I'm asking :slight_smile:

  3. Do you foresee any problems from running the LEDs out on cables like this?

  4. Should the series resistor for each LED go in the main circuit board, or out at each LED in the remote boxes? My gut says to put it with the LEDs, but I have no logic or experience to back that up...

  5. Do you see anything else stupid I'm doing?

  6. My IR LEDs are specced at 40 degree spread. Since I can't actually see the light they're throwing out, how much area do you think they're actually covering? In theory, with them 5 feet above the table, they'd be casting about a 3.5 foot diameter circle below. Not all that big... but I'm sure there's some "overspray" if you will, but the datasheet that I got on them doesn't really give any more detail. I'm just wondering if putting 7 up is gross overkill and 1 or 2 would do, but at this point I don't have the table set up to really test it. On the other hand, having the expandability would be nice too :slight_smile:

  1. You could get 1, 5v supply for the Leds and 1, 7+ volt supply for the Arduino. 7805 regulators would be nice to use if you think you might want to expand later or if you think you want to be flexible with supplied power. For instance maybe you would want to run the train from a car battery, the 7805s would make it easy to do so.

  2. I don't think you would have to have a cap for the LED's but, it might make the regulator more stable and keep the leds regulated as close as possible to the 5v desired.

  3. I think cat 5 wire is usually 22 gauge but, yours might be different. I would have to look up the amp rating of 22GA. but, I think you should be ok to run your leds with it.

  4. Put the resistor were it is convenient for you. In this situation it does not matter were you put it.

  5. There is a lot to read but, you seem to be doing a good job so far.

  6. I would test your IR system by shadowing areas and see if you lose communication with the train. Add leds as necessary. Or just take a wild guess and sprinkle them across your train platform.

I think cyclegadget pretty much covered it, you seem to be on the right track.

  1. You can help by using 4 wires for the signal and 4 for the return.
  2. Unless you want to run a separate cable to each LED they have to be at the LED end.

That controller is a real find, better than bending up some ali and drilling a few holes :slight_smile:


Rob

Few more updates...

Decided to get a teensy instead of wiring up a whole arduino from scratch. Should only need minor modifcations to the code (new IR library, change pin assignments) and save a lot of effort. It'll still be mounted to a board, but then my board only needs the teensy board and the transistors on it, because...

I found in my parts bin a nice power supply. It's designed for running computer components outside a case, so it's got a normal computer 4 pin molex connector, with 12V and 5V (2A) in it. I'll use that for everything and not need the voltage regulators anymore.

Looking at my current prototype and my post above, I think I stated things backwards (or did I, I'm starting to confuse myself here...)

I think my setup is actually a shared 5V rail to the LEDs and the transistor is on the - side of them. I'm using standard NPN 222 transistors. Here's what I'm doing:


LegoTrainRemoteTeensy by mostlytechnic, on Flickr

Is that right? Or should I wire the transistors differently? (the red LED is just an indicator so I could see if it's working. Might leave that out of the final design since I won't really need it)

Second, some browsing other people's circuits online suggests skipping the resistors on the IR LEDs altogether since the transistors only handle 600ma, which these LEDs should handle just fine. What'd happen then, since for a moment, they would be trying to pull 4.8A when the power supply only provides 2? Some weird splitting of the power between them based on the tiny differences transistor to transistor, and possibly resetting the teensy since they're drawing too much power? Would it be better to keep like I am with resistors restricting each LED to 200-250ma?

Sorry timrop those Fritzing diagrams are too much work to decipher. Can you do a real schematic?

A couple of things though.

I don't see any base resistors, they are required.

skipping the resistors on the IR LEDs

That sounds dodgy, you will be connecting a 5v (or whatever) power rail to GND via two components (LED and transistor) that have a total forward voltage of 2-3v. Something has to deal with the difference between the 2-3v and the power supply. Maybe the transistor will do this as you describe but is has to be a bodge and all transistors are different anyway.

trying to pull 4.8A when the power supply only provides 2?

The PSU will drop the voltage causing who knows what to happen to your circuit. Or maybe it will trip an internal fuse or whatever.

Would it be better to keep like I am with resistors restricting each LED to 200-250ma?

Yep. Not that I can see any resistors in that drawing.


Rob


LegoTrainRemoteTeensy_schem by mostlytechnic, on Flickr

Hope that helps - sorry it's so messy, not my strong suit :slight_smile: The J blocks (screw terminals in fritzing cause it's what's there; I'll use an RJ45 jack on the real device) on the left are the inputs from the throttle controller. No issues there I don't think (have 5v, gnd, 3 signal from the pots, and 3 signal from the switches). the J blocks onthe right are the outputs to the 7 IR LEDs. Again, it'll really be an RJ45. Each LED box then will connect to the 5V and just one of the other lines in it. I showed one LED /resistor pair, but there will be 7 altogether.

There's one PWM output pin - goes thru a red LED so I can see when it's transmitting, and then out to the bases of the 7 transistors (npn, 2n2222s.) Collectors of the transistors all go to ground, and the emitters are connected to the 7 pins of the RJ45 and therefore to the LEDs.

I currently have a breadboard set up with this (minus the RJ45s inbetween things) and it works. But thinking about it more, should I switch the wiring on those transistors - put the LEDs to the collectors and the emitters to ground? Seems like that's how circuits I see online are set up.

That arrangement on the transistor bases is a little unconventional but if it works it works I guess. Transistors aren't my strong point.

Normally you low-side switch with an NPN transistor, so your comment about swapping the emitters and collectors is right.

But the biggest question I have is, why are you using 7 transistors and not just a single large one or even a FET?


Rob

I'm using 7 to try to run all the LEDs as high as I can - and they're what I had on hand :slight_smile: I'm not knowledgeable about FETs or higher power transistors. Lemme go read up a little...

ok, I'm back. Basically a TO-220 packaged transistor or FET, with more power handling ability, would be better than a bunch of little ones? I whipped up a new schematic:


LegoTrainRemoteTeensy2_schem by mostlytechnic, on Flickr

Is that what you mean? Is there then any reason to keep the 7 lines for 7 LEDs? Or should I switch it to use 4 power and 4 to the FET to make things easier? I'm certainly open to things that'll make this easier to build :slight_smile:

Anything particular I should be looking for in the specs for this? I'm hoping to not make any more online orders, so I looked at what radioshack carries locally. There 1 FET - IRF510 - and a few bigger NPN transistors (TIP31, TIP120, TIP3055). All look like they'd handle the 5V 2A just fine. Is my speed (38khz for IR) an issue? When they say high or low or medium speed switching, I have no idea what those vague terms mean, since I don't really have any experience in this.

How much heat would you expect this to be generating? It'll be in a fist-sized enclosure with not much else - need a heat sink?

Thanks for all your help! I'm more of a software guy, so writing the code for this was easy. Now I'm learning stuff as I go on the hardware side.

That's the general idea.

As I said transistors aren't my field...

If you use a FET it has to be a "logic level" FET, meaning that it is fully turned on with a VGS(TH) of 5v or less.

In the data sheet for the IRF510 it states

These types can be operated directly from integrated circuits.

They don't used the magic words "logic level" but further down it says that VGS(TH) is 2-4 volts.

Looking further down at Figs 5 and 6 is appears to only be good for 1A with a VGS of 5v. In that case it may not be suitable.

So, in a nutshell, I don't know enough to recommend that FET but I have doubts.

Based on that I think the TIP120 might be a better option, that seems to be a no-brainer.

How much heat would you expect this to be generating?

With the correct FET, none, with the TIP120 and 2A (is that right?)

A x V = W where in this case V is the forward voltage of the transistor.

2 x .6 = 1.2 watts.

What that means in terms of heat I don't know because they don't give a C/W figure for the package, if that was constant I'd say you need a heatsink, but given that is will have a low duty cycle I think you are OK without one.

As I said though, transistors are not my bag so it would be nice for someone to confirm or deny the above.

Is there then any reason to keep the 7 lines for 7 LEDs?

No, but if you use a single wire it has to be thicker.

When they say high or low or medium speed switching, I have no idea what those vague terms mean,

Neither do I really, but 38kHz is pretty slow by electronics standards.


Rob

Ok, hopefully the final schematic here...

Using a TIP120 for the transistor. I've rearranged the RJ45 so that it's now using 4 wires for 5V and 4 wires to the transistor. Then the LEDs/resistor pairs in the external boxes just connect to any 2 of those, right? (obviously, making sure it's one of each set, and in the right polarity...)

Although, that's really overkill though, right? I mean, the current between the LEDs and TIP120 have to travel through a wire from the jack to the board, and then through the tiny trace on the board...


LegoTrainRemoteTeensy3_schem by mostlytechnic, on Flickr

Once I get it built, I'll test the heat production on the transistor by running a beyond-worst-case scenario on it (something like sending a signal 4x a second for 10 min or something) and see if anything heats up.

Oh, and I remembered why I originally used 7 separate transistors. I'd looked at the plans for the adafruit tv-b-gone (TV-B-Gone Kit [Universal v1.2] : ID 73 : $19.50 : Adafruit Industries, Unique & fun DIY electronics and kits) - they use 4 transistors to drive 4 LEDs, and even use a 5th to drive the 4 transistors :slight_smile: I guess the chip they're using just has really low output from the pin that's controlling the LEDs. It's also not using any series resistor with the LEDs, but it's only running from a pair of AA batteries.

and then through the tiny trace on the board...

In which case you don't use the tiny trace on the board. Run the LED 5v and the GND from the emitter directly to the power supply.

Then the LEDs/resistor pairs in the external boxes just connect to any 2 of those, right?

Right.


Rob