# Panel lighting and tortoise switches



## hokie1525 (Jan 13, 2015)

So I'm trying to prepare myself to build a panel and wire it to tortoise switch machines.

I want some bi color panel lights to indicate active tracks. The first question is...should I get LEDs that are bi polar or that have a common cathode? Is there a reason for one or the other in this application?

The next question is...My track will require some LEDs to be wired through logic gates. Can someone point to a handy-dandy wiring diagram for how to wire this? I understand how the gates work, however they are designed to turn on and off current. In this application current needs to be on all the time, with the polarity switched to change the color from red to green. 

Unless I'm way off base....


----------



## DonR (Oct 18, 2012)

Since you'll be using Tortoise motors for your turnouts
you'll want to use DPDT switches for each on your
panel. One side will control the tortoise motor the
other side will control the color of a bicolor LED.

Will you be using DC for your Tortoise motors? If
so, only a resistor would be needed for the LED feed.

What is it you are doing on your layout that you
want logic gates? I have a 2 transistor logic circuit
to control a signal bridge that indicates that all turnouts are
set for a clear route on one of my mains. 

I have 4 turnouts in this main. I take a feed from each
on the panel thru a diode into the transitor circuit that controls a
bicolor LED. When any one of
these turnouts is set to divert the signal shows red. When
all are set to straight the signal shows green. 

I use the 3 wire bicolor (or tri color) LEDs.

Are you running DC or DCC on your layout? 


Don


----------



## hokie1525 (Jan 13, 2015)

My layout is DCC. The purpose of the logic circuits is to tell me which track in my yard will receive the train. Similar to a clear route system. Clear to track _x_ in the yard.

I would be powering the tortoises with DC power (12v). I would probably need separate power for the logic gates since they take 5V.

I guess I'm looking for some kind of wiring diagram, as I am a newbie at this and need a little hand holding.


----------



## johnfl68 (Feb 1, 2015)

How are you at basic programming?

For simple logic for LED's you might look at something like the Pro Trinket from Adafruit:

http://www.adafruit.com/products/2000

It has 18 GPIO (inputs or outputs) and is only $10. It will take up to 16V DC input on the +Batt pin, so 12V DC to power it should be fine. Then the GPIO outputs for LED's would be 5V and use resistor on LED's as normal for 5V (There are 5v and 3.3v versions, make sure you get the 5v version). If you want/need to power something more than a LED, you would need to add an additional circuit, as the outputs can only handle 20ma each.

Input could be from Push Button, or Switch (switch circuits in the Tortoise), as long as they are not shared with any other circuits that may interfere. 

It programs via USB with Arduino software (free), and should be easy to set up the logic that you want, looking at inputs, and the turning off and on LED's as needed. After programming, you can disconnect the USB cable, the program for the logic is written to the devices non volatile memory.

It would be a bit easier to change the logic with code and reload, then to build new logic circuits if you did something wrong, or wanted to make a change sometime in the future.

I have the baby brother of this (Trinket) running the Neopixel RGB LED's along my Warren Truss bridge, so I can change the bridge lighting to different color schemes throughout the year.

There are plenty of tutorials on the Adafruit site, here is a good starting point for what you are doing. It uses a larger Arduino, but works the same for the Trinkets:

https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs


Anyway, just a thought.

John


----------



## DonR (Oct 18, 2012)

hokie1525 said:


> My layout is DCC. The purpose of the logic circuits is to tell me which track in my yard will receive the train. Similar to a clear route system. Clear to track _x_ in the yard.
> 
> I would be powering the tortoises with DC power (12v). I would probably need separate power for the logic gates since they take 5V.
> 
> I guess I'm looking for some kind of wiring diagram, as I am a newbie at this and need a little hand holding.


The 12 Vdc would be fine for the LEDs also, use a 470 or so ohm
resistor for them.

Do the devices suggested by John do what you are wanting?

If not, then is it that you want an automated yard track selection
system? I have seen a large layout that had total automation of several
trains entering and departing a run through yard.

An incoming train would be sent to track 1, the next departing
train left from track 2, the following incoming train would go to track 2
and so on. Is that your thinking?

There are also devices to display track occupancy.

Don


----------



## hokie1525 (Jan 13, 2015)

johnfl68 said:


> How are you at basic programming?
> 
> For simple logic for LED's you might look at something like the Pro Trinket from Adafruit:
> 
> ...


I may have to look into this.

Not looking for automated track selection. I just want the LEDs to light up according to where the train would go given how the turnouts are switched. So if I set the switches so a train enters the yard and goes to track 2, then the LED for track 2 should be green and the others red.

Or I could avoid being "cute" and just wire the LEDs without logic and just remember that a train will enter the earliest track that is green.

Why should I need resistors? I thought the tortoise provides enough resistance. Or is it to bring the 12v down to 5v if I run off the same walwart?


----------



## johnfl68 (Feb 1, 2015)

hokie1525 said:


> Why should I need resistors? I thought the tortoise provides enough resistance. Or is it to bring the 12v down to 5v if I run off the same walwart?


You would use a resistor for each LED in part as a form of current protection. The same as if you install an LED in a locomotive for headlight, in most cases you need to use a resistor (some newer DCC Decoders are set up for LED, the resistor in is put on the decoder board for you).

Different LED's have different specifications, mainly Forward Voltage and Current.
Forward Voltage might be around 2.0 volts
Current might be around 15mA

You use ohms law to calculate resistance (Google LED Resistor Calculator - there are many).

In this case the answer is 200 ohms, rounding up to closest common resistor size of 220 ohms.

If you don't want glaring bright LED's, you can reduce the Current in the calculation, in this case using 10mA would be about 2/3 as bright using a 330 ohm resistor.

Some LED's (Blue for example) might have a higher current rating (20mA). The Trinket Pro has a max current per GPIO of 20mA - so if the LED requires more than 20mA, you want to reduce it to make sure it is 20mA or less, so you don't damage the Trinket Pro. Most LED's are fine with less current, they just don't light as bright.

Using a resistor is always a good idea, as it helps keep the magic smoke inside the LED, and LED magic smoke smells bad.

John


----------



## DonR (Oct 18, 2012)

Hokie

It sounds like you want the transistor circuit I used for my signal
light. A recap: The signal shows green when all four turnouts
are set to straight, if ANY one of them is set to divert the signal
will turn to red. 

I'll have to think a bit on how to do what you want. A simplified
version would simply use the existing switches on the Tortoise
motor to turn the LEDs from red to green when points are in
that position. It gets more complicated if you want a routing
system.

Lets say you have 4 tracks in your yard off of a ladder track.
You want the ladder track LED to show green when turnout
is set for it. Then you want track 3 LED to go from red to
green when it's turnout is set to divert. The same for each
of the other 3 yard tracks. Yes?

Don


----------



## hokie1525 (Jan 13, 2015)

DonR said:


> Hokie
> 
> Lets say you have 4 tracks in your yard off of a ladder track.
> You want the ladder track LED to show green when turnout
> ...


Well, almost. And I don't know what I'm doing so I may be way off base here. I don't necessarily want track 3 LED to go green when it's set to divert. I only want it to go green when it's set to divert and tracks 1 and 2 (not sure what you mean by ladder, I'm new to this) are not set to divert. I want the track set to green wherever the train will go.


----------



## DonR (Oct 18, 2012)

Hokie

What I described seems to be what you are saying...you want green
to show in THE track you intend to go on. That's what the wiring
I was describing does.

A LADDER track in a yard is the one from which the various spur tracks
divert. 

Here are various designs using it.

https://www.google.com/search?q=yar...VNaCJoylNoWhhKAJ&ved=0CCwQ7Ak&biw=853&bih=378

Doesn't have to be a yard, the system I use is not, but the main does
have various turnouts off of it. When I throw any of those turnouts two
LEDs react. The panel LED goes green for the destination track.
The signal bridge LED goes RED saying the main is not clear all the
way through.

Do we have a picture or drawing of your layout? That would be helpful
to suggest the easiest way to do what you want.

Don


----------



## hokie1525 (Jan 13, 2015)

The "ladder" in the center right is the area of concern.


----------



## DonR (Oct 18, 2012)

You have a classic small yard with 4 tracks leading off of it.

I know that you want to see a Green panel light and know that
is where your loco will go. All other LEDs would be Red.

There is not going to be a simple circuit to give you a
sure fire Green to any one track and be assured that
the other panel LEDs would all be Red.

It is going to need a transistorized logic circuit to do 
that.

I was going to suggest a diode matrix system for your
yard but realized you are using tortoise motors. The
matrix would likely be overloaded by the Tortoises.

I'm running into brick walls on this. I'll have to do some
more thinking. If anyone else has a thought on it
bring it on.

Don


----------



## johnfl68 (Feb 1, 2015)

I don't have a Trinket Pro available to test right now, so there may be some issues with this setup, but at least it will give you an idea of what the programming would look like. And there are some things that could be done to make the code more efficient, but for something simple as this, the amount of memory or speed of processing will not really matter. This is just intended to give you a ballpark idea. My "Logic" may be different than what you intended as well.

If you where to use something like the Trinket Pro, this would be a possible Code Example:


```
int ledAGreenPin = 3;
int ledBGreenPin = 4;
int ledCGreenPin = 5;
int ledDGreenPin = 6;
int ledARedPin = 7;
int ledBRedPin = 8;
int ledCRedPin = 9;
int ledDRedPin = 10;
int TortoiseApin = 14;
int TortoiseBpin = 15;
int TortoiseApin = 16;
int TortoiseBpin = 17;
 
byte leds = 0;
 
void setup() 
{
  pinMode(ledAGreenPin, OUTPUT);
  pinMode(ledBGreenPin, OUTPUT);
  pinMode(ledCGreenPin, OUTPUT);
  pinMode(ledDGreenPin, OUTPUT);
  pinMode(ledARedPin, OUTPUT);
  pinMode(ledBRedPin, OUTPUT);
  pinMode(ledCRedPin, OUTPUT);
  pinMode(ledDRedPin, OUTPUT);  
  pinMode(TortoiseApin, INPUT_PULLUP);  
  pinMode(TortoiseBpin, INPUT_PULLUP);  
  pinMode(TortoiseBpin, INPUT_PULLUP);
  pinMode(TortoiseBpin, INPUT_PULLUP);
}

//Tortoise inputs are PULLUP so triggered when LOW
//So when Tortoise internal switch is closed = LOW
// and when Tortoise internal switch is open = HIGH


void loop() 
{
  if (digitalRead(TortoiseApin) == LOW)
  {
        digitalWrite(ledAGreenPin, HIGH);
	digitalWrite(ledBGreenPin, LOW);
	digitalWrite(ledCGreenPin, LOW);
	digitalWrite(ledDGreenPin, LOW);
	digitalWrite(ledARedPin, LOW);
	digitalWrite(ledBRedPin, HIGH);
	digitalWrite(ledCRedPin, HIGH);
	digitalWrite(ledDRedPin, HIGH);
  }
  if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == LOW)
  {
        digitalWrite(ledAGreenPin, LOW);
	digitalWrite(ledBGreenPin, HIGH);
	digitalWrite(ledCGreenPin, LOW);
	digitalWrite(ledDGreenPin, LOW);
	digitalWrite(ledARedPin, HIGH);
	digitalWrite(ledBRedPin, LOW);
	digitalWrite(ledCRedPin, HIGH);
	digitalWrite(ledDRedPin, HIGH);
  }
  if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == HIGH
	&& digitalRead(TortoiseCpin) == LOW)
  {
        digitalWrite(ledAGreenPin, LOW);
	digitalWrite(ledBGreenPin, LOW);
	digitalWrite(ledCGreenPin, HIGH);
	digitalWrite(ledDGreenPin, LOW);
	digitalWrite(ledARedPin, HIGH);
	digitalWrite(ledBRedPin, HIGH);
	digitalWrite(ledCRedPin, LOW);
	digitalWrite(ledDRedPin, HIGH);
  }
  if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == HIGH
	&& digitalRead(TortoiseCpin) == HIGH
	&& digitalRead(TortoiseDpin) == LOW)
  {
        digitalWrite(ledAGreenPin, LOW);
	digitalWrite(ledBGreenPin, LOW);
	digitalWrite(ledCGreenPin, LOW);
	digitalWrite(ledDGreenPin, HIGH);
	digitalWrite(ledARedPin, HIGH);
	digitalWrite(ledBRedPin, HIGH);
	digitalWrite(ledCRedPin, HIGH);
	digitalWrite(ledDRedPin, LOW);
  }
}
```
LED A and Tortoise A are the first turnout, followed by B, C, and D.

You would take the common of one of the internal switches of each Tortoise internal switch (T pin 4) (they could be daisy chained) and connect to Ground on the Trinket Pro. And then take the pin of the internal switch (T pin 2 or 3 based on thrown orientation of Turnout) and connect each to Trinket Pro pins A0, A1, A2, and A3 (Digital pins 14, 15, 16, and 17).

LED's would have negative lead go to Ground as well, and then add appropriate resistor to the positive lead of each LED before connecting to Trinket Pro pins 3, 4, 5, and 6 for Green, and pins 7,8,9, and 10 for Red.

Once the script is uploaded, the Trinket Pro take about 2 seconds to "Boot" and "Setup" the pins. Then it will run the loop continuously to illuminate the LED's as needed.

John


----------



## DonR (Oct 18, 2012)

John

I used to program Pascal on MSDOS, but I sure can't follow
your program for this device. It is certainly cheap enough,
9.95 for the circuit board.

The layout owner wants his red/green LED panel lights in each of the tracks
of that yard to be RED except for the one he has set the
turnouts for and that one would show GREEN. That will require that
logic defeats green at any yard track except the ONE that
has clear access back to the main. 

Can this device be programmed to do the above?

Every concert I came up with left the probability of multi
greens showing in addition to the desired one.

Don


----------



## johnfl68 (Feb 1, 2015)

Formating has been simplified a bit since PASCAL, but the basics are still there.

OK to explain the code a bit.

The int's:

```
int ledAGreenPin = 3;
```
This give a name to each of the pins, so it is easier to follow in the code.
led A Green pin
led A Red pin
Tortoise A pin
etc.

The void setup:
This sets the pins as Inputs or Outputs
The LED's are outputs.

```
pinMode(ledAGreenPin, OUTPUT);
```
The input from the switch inside a Tortoise, and it is a pullup type input.

```
pinMode(TortoiseApin, INPUT_PULLUP);
```

The void loop:
This is the main part.

```
if (digitalRead(TortoiseApin) == LOW)
{
        digitalWrite(ledAGreenPin, HIGH);
	digitalWrite(ledBGreenPin, LOW);
```
If the Tortoise A pin is equal to LOW (the pin has been pulled low meaning the switch is closed and the turnout is thrown).
The "==" means "Equal To"

```
digitalWrite(ledAGreenPin, HIGH);
```
(then) turn led A Green Pin On
and the B, C, and D Green Pins are turned off
and the led A Red Pin is turned off
and the B, C, and D, Red pins are turned on

So Turnout A is thrown,
so A LED is Green and B, C, and D LED's are RED.


And then the next one:

```
if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == LOW)
```
If A is HIGH (Not thrown) and B is LOW (thrown)
The "&&" means "AND"
So Turnout A is not thrown, but Turnout B is thrown,
so A LED is Red, and B is Green, and C and D are Red.


And the next:

```
if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == HIGH
	&& digitalRead(TortoiseCpin) == LOW)
```
If A and B are HIGH (not thrown) and C is LOW (thrown)

So Turnout A and B are not thrown, but C is thrown,
so A and B LED's are Red, and C is Green, and D is Red.



And last:

```
if (digitalRead(TortoiseApin) == HIGH 
        && digitalRead(TortoiseBpin) == HIGH
	&& digitalRead(TortoiseCpin) == HIGH
	&& digitalRead(TortoiseDpin) == LOW)
```
If A and B and C are HIGH (not thrown) and D is LOW (thrown)

So Turnout A and B and C are not thrown, but D is thrown,
so A and B and C LED's are Red, and D is Green.

Hopefully that will help explain some.

That is the nice thing about using the Arduino Code (The Trinkets, or even full size Arduino's if you have more complexity and/or need more inputs and outputs), is that if you don't get the logic quite right the first time, you just change the code, and upload a new script. No rewiring, no having to order other transistors, or flip flops, chips, can't go to RadioShack because they went out of business, etc. You just change a few lines in the scripts, and try and test again.

As long as you can follow Operators and Boolean logic, all you need to do is look at the inputs, make your list of possible combinations, and output to the LED's to turn on and off to match what you want.

Everyone's possible situation is different, the way the Tortoise and Turnouts are installed might be different to give slightly different logic, etc. I can't try and program for free for all the possible situations. Like many I have my own projects I am working on in my spare time. I'm just offering a suggestion for an alternate way to do this. There are even some people using Arduino's connected to LocoNet or as DCC Decoders, but that is well above me.

There are plenty of places online for examples and Arduino basics. It's easier for me because I have worked with so many similar devices over the years. That being said, it's not that hard to learn, and at $10 a piece, get a few, if you happen to blow one or two up in the process of learning, so what, you learn from your mistakes like everything else in life.

These are great little tools to do some simple tasks like this.
Any other simple questions, I will try and explain some, but go read and learn some more for yourself if interested.

John


----------



## hokie1525 (Jan 13, 2015)

johnfl68 said:


> You would take the common of one of the internal switches of each Tortoise internal switch (T pin 4) (they could be daisy chained) and connect to Ground on the Trinket Pro. And then take the pin of the internal switch (T pin 2 or 3 based on thrown orientation of Turnout) and connect each to Trinket Pro pins A0, A1, A2, and A3 (Digital pins 14, 15, 16, and 17).
> 
> LED's would have negative lead go to Ground as well, and then add appropriate resistor to the positive lead of each LED before connecting to Trinket Pro pins 3, 4, 5, and 6 for Green, and pins 7,8,9, and 10 for Red.
> 
> ...


Thanks John. I don't have a problem with the programming logic. That's easy. For me it's the wiring. It seems these instructions are for separate red and green LEDs. How does the wiring work for two color LEDs? Does position go to the middle lead?


----------



## johnfl68 (Feb 1, 2015)

Depends on the LED that you use.

If you use a 2 pin bi-color led, you would connect the RED Pin Output (3) to a resistor, then to one pin of the LED, and then other pin of the LED to the GREEN Pin Output (7). Then if Red goes High and Green Low, Red will illuminate. If Green is High and Red is Low, Green will illuminate. You would not connect the LED to either Ground or +5V in this case.

If it is a 3 pin Common Cathode bi-color LED, then the common pin (usually center pin) would go to Ground on the Trinket, and Red to resistor then Red Pin Output, and Green to resistor then Green Pin Output.

If it is a 3 pin Common Anode bi-color LED, then the common pin (usually center pin) would go to +5V on the Trinket, and Red to resistor then Red Pin Output, and Green to resistor then Green Pin Output.

John


----------



## hokie1525 (Jan 13, 2015)

Thanks John. How many tortoises/LEDs can I wire with this thing? I have 13 tortoises to 10 switches, and maybe 15-20 lights depending on how much information I want to put on my control panel.

Also, do I need some kind of compiler to write this code, or is there some kind of developer's suite available with this hardware?

Thanks again for the knowledge.


----------



## johnfl68 (Feb 1, 2015)

The Trinket Pro would be about at it's limit of inputs/outputs for the example given.

You have a few options, if nothing needs to be directly interconnected, you could use several of the Trinket Pro's each doing a portion of the work.

If not, you could go up to one of the full Arduino's to give you more inputs/outputs.
For Example the Arduino MEGA 2560 which has 54 digital I/O's on board. 

Adafruit also caries the Mega 2560:
http://www.adafruit.com/products/191

There are special drivers for the Pro Trinket, you can find out more, and download the Adafruit IDE (Arduino with Adafruit Library included) which is already set up for the Pro Trinket here:
https://learn.adafruit.com/introducing-pro-trinket/setting-up-arduino-ide


Or you can get the Arduino software can be downloaded here if you are going with the Mega:
http://arduino.cc/en/Main/Software

You can also use the Arduino software with the Trinkets, you just need to add the appropriate drivers from Adafruit.

The Arduino/Adafruit software for these is free.


Also for others following along:
If you want/need to connect outputs to control Tortoise's or other items, you could add a relay board to interface the Arduino Outputs to trigger relays, the relays can handle the higher load of Tortoise's and other accessories:
http://www.amazon.com/JBtek-Channel-Relay-Arduino-Raspberry/dp/B00KTELP3I/

And it is possible to connect photo sensors, break beam sensors, etc. to these as well, just poke around the Adafruit site some, and other places online for more information. Lots of possibilities here.

And here is the Model Railroading with Arduino site, if you really want to get crazy mad scientist like (advanced electronics and programming skills a must):
http://mrrwa.org/

John


----------



## DonR (Oct 18, 2012)

John

Your code for dummies did activate some memories, but the
Hokie is reading you clear so I'll move out of the way.
Thanks for getting me out of a bind.

Don


----------



## johnfl68 (Feb 1, 2015)

No worries Don.

John


----------



## traction fan (Oct 5, 2014)

Hokie, 
I just read your posts and all the replies with plenty of personal interest, as I spent part of yesterday and all morning today trying to do the same thing! I finally gave up, as it was more work than it was worth to me. It can be done (with the two wire LED) in fact, a few years back I did it. On the six tracks serving a passenger station, I wired six two- legged LEDs and a LOT of diodes to show red until selected and green when selected. I'll have to look at that panel again as I'm too damn old to remember how I did it!
The LEDs with three wires don't change color by reversing polarity. The two wire LEDs do. That's the basic difference. The reason is that the three wire LED has a common "cathode" or negative wire (the center one on the LEDs that were frustrating me earlier.) This center wire has to stay negative all the time or the thing won't light up. The positive voltage is applied to one of the outer wires for green and the opposite one for red.
It's easier to think of this LED as two separate LEDs, one red, one green' with their negative wires connected. Electronically, that's exactly what it is. The two are just built into one shared package. 
With the two wire version, a polarity reversal on the two wires changes the color.
To accomplish the neat looking effect you want; you need to wire the contacts of each tortoise machine in the route for track one in series. The voltage will only get to track one's LED when all turnouts are set for that route. Easy enough if all that's desired is to light one simple LED from dark to lit. It gets several orders of magnitude more complicated when you want to change from lit red to lit green. for this reason I decided to live with just lighting a green LED from dark. 
However; If you have your heart set on changing from red to green; the easiest method I can think of would be to use that same series circuit to operate a relay, instead of an LED. Let the relay select which of those two outer legs gets the positive voltage,or weather the polarity is forward or reversed on the two leg LED.

Good Luck. I suspect you will need it!

Traction Fan


----------

