Need to get a signal from led but only when constantly on

I have a piece of equipment that illuminates an LED when it is on, I want to use the LED being on as an input to the Arduino as its the only way I can pickup a signal from the equipment.

but I have a problem:

When the equipment is in normal operation the LED is illuminated constantly but if a fault develops the LED flashes on/off every 500mS.

I do not want the Arduino to do anything if the LED is flashing Only when the LED is on steadily should the Arduino run.

I am very new to coding so don't know where to start with this so any help very much appreciated

So, if the LED is illuminated for a period of, say 1 second, that is enough for you. Try something like this (untested)

unsigned long ledDetectedMs = 0;
int ledPin = 5 ;  // your choice
boolean lastLedStatus = LOW ;

setup() {
    pinMode( ledPin , INPUT ) ;
}

loop() {

   if ( ledPin == HIGH &&  lastLedStatus == LOW) {
      ledDetectedMs = millis() ;
   }
   else if ( ledPin == LOW ) {
      ledDetectedMs = 0 ;
   } 
   if ( ledPin == HIGH  &&  millis() - ledDetectedMs > 1000UL  && ledDetectedMs != 0 ) {
       // equipment ON
   }
   else {
      // equipment OFF
   }
   lastLedStatus = ledPin ;
}

Are you physically going to connect the LED to the Arduino? You first of all need to know how it is wired in the device. Have you figured that out?

Next you need to figure out which voltage levels you will receive. Anything above 5V blow up the Arduino. There is also a chance that the voltage level difference is not high enough for the Arduino to determine if the LED is on or if the Led is off.

Maybe it might be better to use a LDR or photo transistor to detect the light

Once you have the hardware side sorted, you can use millis() to do time measurements.

Using an average (over a certain time period) might be a good way to go as well. I second the photo sensor as something to consider.

Photo sensor is not viable for this but thanks for the suggestions, as said I need to do a bit more investigation on available voltage level etc be fore going any further.

I am however thinking that I should use the led to activate a transistor switch and have that give me my required input.

But the flashing under fault conditions still gives me an issue.

Will try the code example above when I get home

If you have access to the equipment you're trying to monitor (with the flashing LED) you could easily wire in an opto-coupled LED (in parallel with the existing LED I would think) so you are then safe inasmuch that your Arduino cannot be overloaded and the equipment you're monitoring only needs an extra few mA to drive the optoCoupler.

If you can do this then the actual Arduino side of things is really quite simple... (he said, not knowing the first thing about what your intentions are to do with the data!).

Anyway, just suggestin' :cold_sweat:

I do not want the Arduino to do anything if the LED is flashing Only when the LED is on steadily should the Arduino run.

What do you mean by let it run?

The Arduino is always running so all you can do is to decide what functions it calls or not. You can only make this decision every 1 second or so because you have to wait at least the time of one flash to know if it is flashing or on steady. Therefore the transition between fault and normal can not be closely coupled.

The use of interrupt pins could be good here?

One pin starts the code (via a boolean flag) when the LED is on. One pin stops the code (via a boolean flag) when the LED is off.

PSEUDO:

attatchinterupt 1 looking for HIGH -> sets boolean flag high.
attatch interupt 2 looking for LOW -> sets booleanflag low.

main( do while flag is high){ delay(600) };

while(flag HIGH){ Run functions }

You can use while(flag HIGH) before code blocks to catch the occurrence of the LED going off ASAP.

Other option is the reset pin?

Its been a while but I finally have got the signal level.

With the LED on I have 4.88v dc to use as a signal and is constant under normal running conditions, in fault condition it goes between 100mV and 4.88V every 300mS so how do I go about utilising it so that the Arduino only sees the input if not in fault condition.

Thanks

You read the signal and if it indicates off you capture the time from the millis() timer. Only when the current value of the millis() timer when you subtract the stored value from it exceeds a second ( or what ever the period of the flash is ) do you consider it is not in a fault condition.

I think I would start the project by sensing the LED and then controlling/mimic my own as an exact duplicate. copy the ON , the OFF, the flash.

in that way, your sketch would see the original and output to one on your device. capturing the signal is the easy part setting up de-bounce with a 500mS timer is also very easy.

setting up de-bounce with a 500mS timer is also very easy.

I would have thought that a debounce was exactly the opposite of what you want. You could do a read then delay but you don't see anything during the delay.

Grumpy_Mike: I would have thought that a debounce was exactly the opposite of what you want. You could do a read then delay but you don't see anything during the delay.

debounce shows you how to ignore anything less than the time value.

the OP wants to ignore any blink from the LED and only show when it is on a steady state.

of course you have to turn off any time the LED in the machine goes off.

as an example of millis() that part of debounce is about as close as you can get to what he wants.

of course you have to turn off any time the LED in the machine goes off.

Which would not happen with a debounce time in the order of a second.

as an example of millis() that part of debounce is about as close as you can get to what he wants.

No reply #9 is what the OP wants. It will stop at the instant the LED turns off and it will not start again until the LED turns on and stays on for longer than the blink period.