Led fading out question

So i have my model railroad crossing completed... Good to go... Except for the led at the end of the crossing arm goes dim after about a minute. It eventually dies out. I have tried replacing the Led but the same thing happens.

The other flashing LEDs work perfect and stay bright.

Any reason you could think of to cause this?

I am using an uno....

Thanks in advance for any help.

Please post your electronic schema (a drawing is OK)
How is the LED connected the LED?

1 Like

Is there a series resistance unique to that LED?

1 Like

Welcome to the forum

Please post your full sketch, using code tags when you do

If there's no series resistor for the LED, that's the cause. Excess current won't be tolerated forever; be glad the LED is failing, not the Arduino output (though, it might be easier to switch to another pin when you add the resistor than replace the LED on the crossing arm).

I will upload a drawing of the way I uave it set up when I get home. I do have the LED connected to the positive side with a 220 olm resistor... But come to think of it, it may be soldered on the side of the resistor where the wire connects to the uno, instead of past the resistor.

Thank you for your help.

Hello everyone,

Earlier today I posted a question about my led going dim and then fading out completely. I am working on my model railroad crossing and everything works perfect, except for the led going dim and fading out on the end of the crossing gate arm.

All the other leds work perfectly, the one giving me the issue is the only one that stays solid.

Could anyone help me to find the cause and the corrected action I need to take to fix the issue? All the leds are the same on the gate arm. two flash and one stays solid.

Here is the code for the sketch I am using.

Again, thanks in advance for your help.


// Example Level Crossing Control Driving Common Cathode LEDs
// Version 1.4 Geoff Bunza 2018
//
#include <Servo.h>
Servo gate1servo; // create servo object to control crossing gate 1
//ASSUMPTION Gate is down at position 30 and up at position 120
Servo gate2servo; // create servo object to control crossing gate 2
//ASSUMPTION Gate is down at position 30 and up at position 120
int sensor1 = 5; // IR sensor pin Assumption== Pin goes LOW when train detected
int sensor2 = 6; // IR sensor pin Assumption== Pin goes LOW when train detected
int led1 = 10; // Led 1 pin first alternating flasher
int led2 = 11; // Led 2 pin first alternating flasher
int led3 = 12; // Led 3 pin second alternating flasher
int led4 = 13; // Led 4 pin second alternating flasher
int led5 = 9; // LED 5 should be the solid light on the end of the gate when the lights are flashing.
int led6 = 8; // Pin for the steady LED
int gatelow = 5; // variable to store the servo low gate stop position
int gatehigh = 120; // variable to store the servo high gate stop position
int gateposition = 120; // variable to store the servo gateposition
int entering_sensor = 5; //this will tell which sensor was triggered first
int leaving_sensor = 6; // this will tell which sensor shows train leaving
int gates_started = 0; // this says if the crossing is active
int flash_state = 0;
long flash_time = 1;
long flash_interval = 800; // time in milliseconds between alternating flashes
int sensor_count = 0;
void setup()
{
gate1servo.attach(3); // attaches the servo on pin 3 to the servo object
gate2servo.attach(4); // attaches the servo on pin 4 to the servo object
gate1servo.write(gateposition); //start assuming no train
gate2servo.write(gateposition); //start assuming no train
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
digitalWrite(led1, LOW); // Start with all flashers off
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
flash_time = millis();
}
void loop()
{
if ((digitalRead (sensor1)==LOW)&& (gates_started==0)) {
gates_started = 1;
leaving_sensor = sensor2;
starting_sequence();
}
if ((digitalRead (sensor2)==LOW)&& (gates_started==0)) {
gates_started = 1;
leaving_sensor = sensor1;
starting_sequence();
}
if (gates_started) flash_leds(); //gates are down continue flashing
if ((digitalRead(leaving_sensor)==LOW)&&(gates_started==1)) { //train is starting to leave

//as long as the leaving sensor is active the train is still in the crossing
while (gates_started==1) { //now check if train is REALLY gone
sensor_count = 0;
for (int i=1; i< 40; i++) {
if (digitalRead(leaving_sensor)==LOW) sensor_count++;
delay (30);
flash_leds();
}
if (sensor_count==0) gates_started=0;
flash_leds();
}
// we only get here if the train has really left the crossing
ending_sequence();
}
}
void starting_sequence() {
long wait_time;
flash_time = millis();
wait_time = millis()+3000;
while (wait_time> millis()) flash_leds(); //flash before dropping gates
for(gateposition = gatehigh; gateposition> gatelow; gateposition-=1) // goes from gatehigh degrees to gatelow degrees
{
gate1servo.write(gateposition); // tell servo to go to gateposition in variable 'gateposition'
gate2servo.write(gateposition); // tell servo to go to gateposition in variable 'gateposition'
flash_leds(); // keep flashing leds
delay(40); // waits 40ms to slow servo
}
}
void ending_sequence() {
for(gateposition = gatelow; gateposition< gatehigh; gateposition++) // goes from gatelow degrees to gatehigh degrees
{
gate1servo.write(gateposition); // tell servo to go to gateposition in variable 'gateposition'
gate2servo.write(gateposition); // tell servo to go to gateposition in variable 'gateposition'
flash_leds(); // keep flashing leds
delay(40); // waits 40ms to slow servo
}
digitalWrite(led1, LOW); // flashers completely off
digitalWrite(led3, LOW);
digitalWrite(led2, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
delay(30000); // 30 second delay to account for the train passing the starting entry sensor
}
void flash_leds() {
if (flash_time> millis()) return;
flash_state = ~flash_state;
digitalWrite(led1, flash_state); // Alternate flashers
digitalWrite(led3, flash_state);
digitalWrite(led2, ~flash_state);
digitalWrite(led4, ~flash_state);
digitalWrite(led5,1);
flash_time = millis()+flash_interval;
}

```Use code tags to format code for the forum

Could you please edit your post and wrap the code in [CODE] tags as per the hint. It gets formatted properly which it so much easier for everyone to read.

Also, for reference, maybe post a diagram of how you have everything wired .

It would also help if we knew the variable name/number of the LED that you are having problems with or at least the pin that it is attached to?

Thanks.

1 Like

You've been asked for a schematic before...

2 Likes

What about the resistor I asked about?

This looks like one LED will stay on:

  digitalWrite(led4, ~flash_state);
  digitalWrite(led5,1);

I don't think Bunza made a mistake, so perhaps you changed it or it is meant to not flash.

a7

Mr. Bunza was correct in the sketch... I added the solid light at the end of the crossing gate arm because in real life that light stays lit while the others flash. He did an excellent job on the code... I do not think the sketch was designed to have the other light on at the end of the crossing gate, as most HO scale crossing gates do not have any lights on the gate at all.

The one I am making is in G scale, which is a lot larger than HO. I thought I could try to make a prototypical gate.

I solved the problem, as the resistor was wired wrong on this led. Issue resolved now. Thank you to all for the suggestions and the help.

There's not that many ways you can connect a resistor. How was it wired wrong?

1 Like

He misunderstood the schematic, along with the code tags request.

It was our fault the resistor was across the LED.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.