Model Railroad signaling device problem

I have signaling devices that I thought turned a red, yellow or green led on or off by suppling 12v to the led lights. Wrote a program for Arduino to do this based on a train being on certain parts of the track. Worked fine on the breadboard, but not with the equipment. Turns out, the Chinese who built the signal device did not wire it with 3 positives to the led's and a common ground, but a single positive to all three leds and you need to make or break the ground to turn the light on or off. Tried setting the pin signal from the led to low, hoping that would couple the led to ground, but did not work. Now making a transistor circuit to act as a switch for each light, where the high signal from the digital pins bias the transistor base and the transistor turns the leds on or off. Any better thoughts?

That sounds right. Post a schematic and code for this failed attempt. You doing something wrong probably, or I don't understand, also very probable.

a7

1 Like

Sounds like the right approach. Make sure each LED has a series resistor to limit current.

1 Like

If only all us "experts" could just agree on anything! :expressionless:

a7

I'll set it up again and try it. If it works, I'll post it here, if not, I'll post code and schematic. Thanks.

Could not do it last night, other things got in the way. Also, not sure how to upload drawings or code here, but I think it easy enough to try to just explain. For example, using pins 10 and 13 as output pins, there should be 5v on them when high.

If pin 10 is high and 5v comes out of pin 10 and goes to the resistor, then to the anode of the led, to the cathode of the led and then to pin 13 which is also high, there should be 5v on both sides of the led and it will see no voltage drop and will not be lit.

If pin 13 on the cathode side goes to low with pin 10 still high, 5v will flow from pin 10 through the resistor and led and go to ground via pin 13, thus turning the led on.

Is this correct?

Reads plausible.

Does it not work? Be sure to use a resisitor that does limit the current. 1K is totally safe and will give good light out of modern LEDs short of blinding.

Fun: put another LED and resistor between the same two pins, only swap the anode and cathode. You can then light on or the other or neither.

You may deduce that only one resistor would serve for the LEDs wired back-to-back, so to speak. Only one can be on no matter what

You work out how. :slight_smile:

a7

Not sure if it works yet, as I did not have time to wire it last night. After work today, plan to wire it on a breadboard and use my power supply to simulate the Uno and test it. If it does work, all I need to do is replace the resistors in the signal devices with 330 ohm resistors so the leds work on 5 volts instead of the way they are wired now with 1k resistors for 12 volts.

This link Below is very useful to start with. There it is explained how to load code, pictures, etc. Worth to read it.

On the circuit schematic, you can draw it per hand, take a picture with your phone and upload the picture. To upload the pic just click on the up arrow here oben and follows the instructions.

Also, the reason it did not work before may be the resistor, if my limited understanding of all this is correct. I measured the resistor the signal leds are using and it is a 1k resistor. When I do the math, 12v minus the Vf of the led of 2v gives 10 volts. 10 volts / 1000 ohms gives .010 amps, or 10 mA, which is what the led needs to turn on. When using the Arduino, the 5 volts from the Arduino minus the 2 volts for the led gives 3 volts divided by the 1k resistor only gives 3 mA for the led, which will not be enough to turn it on. Concept may have been working, but the components may have not. Fortunately, although I don't have access to the leds to re-wire their polarity, I do have access to the resistor and can change it to a 330 ohm resistor to run the led on 5 volts, assuming my math and understanding of this is correct.

No, it will turn on fine at 3mA. It won't be as bright as with 10mA. There is no minimum current for a led. Even 0.01mA may light it enough to see in a completely dark room.

if the common is tied to 12V, changing the output pin from 0 to 5V isn't going to turn it off.

but if it needs 12V, you want the common to be at 12V so that the LED can be simply pulled to ground with an open collector, the base of a NPN transistor connected to the arduino output pin thru a resistor (try 10k), the emitter grounded and the LED connected to the collector.

set the output pin HIGH to turn on the transistor so that it provides a path to ground for the LED connected to 12V

a uln2803a has 8 transistor circuit and a common ground. see ebay

Not really. Modern LEDs have wildly different efficiencies, and many will be just too bright when driven with their full rated current. Oh, didn't see reply #12...

But to be more specific, try running on 5V. Then you can direct drive from the pins, no extra components needed.

Do you have access to the 1.0k resistors? Can you change them at all?

2 Likes

i've been working on an MR signaling system. RR signals can be either common anode or common cathode. the code is table driven and there is a field identifying the on state as either HIGH/LOW

@anon57585045 made a good suggestion about changing the resistor values a driving them directly from the processor. but bear in mind that processors, even I/O expanders to have a total current limit that is often not the sum of the current limit on each pin.

the max current of the MCP23017 is 150ma, the max current per pin is 20ma. there are 16 pins.

I did some calculations for the STM32F108 running 12 PWM'ed LEDs. At least with the resistor choice I used, the LEDs were plenty bright and MCU current was well within spec.

@rbryce1
I have been working on a railroad crossing simulator with LEDs in Common Anode.

  • real-time or fast-time (debug) can be commented-out at the top of the sketch
  • crude, uses blocking,
  • unfinished parts
    • move from blocking to millis()
    • wigwag red strobes (need millis())
    • LCD arrival announcement
// https://forum.arduino.cc/t/model-railroad-signaling-device-problem/1147370
// https://wokwi.com/projects/370078430529203201

/*
  RRX light pattern:
    1. Default green
    2. When CALL TRAIN button is pressed
      a. RRX begin flashing
      b. Traffic lights cycle
        (1) green 5 seconds
        (2) yellow 3 seconds
        (3) red for 10 seconds
      c. Gates lower
    3. After red timeout
      a. RRX off
      b. Traffic lights green
      c. Gates raise
*/

int millisDelay = 1000; // live time
// int millisDelay = 100; // 10x time for debug

#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27
#define LCD_COLUMNS 16
#define LCD_LINES   2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);

byte rail[] = {
  0b00100,
  0b01000,
  0b11111,
  0b00000,
  0b11111,
  0b00010,
  0b00100,
  0b00000,
};

#include <Servo.h>
Servo servo0;  // create servo object to control servo
Servo servo1;
int pos = 0;    // variable to store the servo position

int rLED[] = {4, 12}; // red LED pins
int yLED[] = {3, 11}; // yellow LED pins
int gLED[] = {2, 10}; // green LED pins
int* LED[]  = {rLED, yLED, gLED }; // array of LED arrays / multidim array

int redDelay = 10; // LED ON time
int yelDelay = 3; // LED ON time
int grnDelay = 5; // LED ON time

bool callTrain = false;
#define buttonPin 13
#define ON LOW   // traffic LEDs ON  - common anode
#define OFF HIGH // traffic LEDs OFF - common anode

void setup() {
  Serial.begin(115200);

  servo0.attach(5);  // attach servo on pin 5 to a servo object/instance
  servo1.attach(8);  // attach servo on pin 8 to a servo object/instance

  lcd.init();
  lcd.backlight();
  lcd.createChar(0, rail);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.write(0);
  lcd.print(" NationalRail ");
  lcd.write(0);
  lcd.setCursor(3, 1);
  lcd.print("Twickenham");

  for (int i = 0; i < 3; i++)  //
    for (int j = 0; j < 2; j++) {
      pinMode(LED[i][j], OUTPUT); // set all LEDs as OUTPUT
      digitalWrite(LED[i][j], HIGH); // set all LEDs OFF
    }
  pinMode(buttonPin, INPUT_PULLUP);
  welcome();
  grnLEDs(ON);
}

void loop() {
  readButton();
  if (callTrain)
    rrxSequence();
}

void sequenceTrafficLight() {
}

void readButton() {
  if (!digitalRead(buttonPin)) {
    delay(150); // debounce button
    callTrain = true;
    Serial.print("Train approaching (GREEN ");
    Serial.print(grnDelay);
    Serial.println(" seconds delay).");
  }
}

void rrxSequence() {
  callTrain = false;
  // wigwag neopixels red
  delay(grnDelay * millisDelay);
  grnLEDs(OFF);
  yelLEDs(ON);
  delay(yelDelay * millisDelay);
  yelLEDs(OFF);
  lowerGates();
  redLEDs(ON);
  delay(redDelay * millisDelay);
  redLEDs(OFF);
  raiseGates();
  yelLEDs(ON);
  delay(yelDelay * millisDelay);
  yelLEDs(OFF);
  grnLEDs(ON);
}

void wigwag () {
  // neoPixel wigwag awaiting non-blocking code (remove delay()s)
}

void redLEDs(byte val) {
  for (int i = 0; i < 2; i++) {
    digitalWrite(rLED[i], val);
  }
  if (!val) { // if ON
    Serial.print("Automobile traffic stopped (RED ");
    Serial.print(redDelay);
    Serial.println(" seconds delay)");
  }
}

void yelLEDs(byte val) {
  for (int i = 0; i < 2; i++) {
    digitalWrite(yLED[i], val);
  }
  if (!val) { // if ON
    Serial.print("Automobile traffic warned (YELLOW ");
    Serial.print(yelDelay);
    Serial.println(" seconds delay)");
  }
}

void grnLEDs(byte val) {
  for (int i = 0; i < 2; i++) {
    digitalWrite(gLED[i], val);
  }
  if (!val) { // if ON
    Serial.println("Automobile traffic passing (GREEN indefinite).");
    Serial.println("Press CALL TRAIN for RRX sequence.");
  }
}

void lowerGates() {
  servo0.write(180);
  servo1.write(0);
}

void raiseGates () {
  servo0.write(90);
  servo1.write(90);
}

void welcome() {
}

@xfpd Nice.

The amber before green is not usual where I live.

Looking forward to what you put on the neopixel strip…

a7

Thank you. Working on the wigwag (red strobe neopixels).

I just changed it to "no amber before green" - a hold over from the "take your mark (red); set (yel/red); GO! (green)" traffic lights of the 1980s.

I can't wait to drive my SIM CAR through the RRX... (also needs to remove blocking code and insert event timing).

signal should be STOP (red) when the next block is occupied, APPROACH (yellow) when the next next block is occupied, otherwise CLEAR (green)

abs-signal-diagram-single_m_med-2

haha... the ready/steady/go (quote) is how automobile traffic lights acted on a normal city street... it was a wild, wild west of gas/brake back then (and probably wilder not too long before that). My sim signals are for automobile traffic.

BUt... I see your drawing... that is train to train... I like it. I do not know the rules of the rail... I only liked riding (and spotting) them for a few decades. The train-to-train lights will be later. Very cool, though.