Measure LED flash duration and conditional serial print

Hi all,

Casual Arduino user with some programming experience here. I am trying to build a system to integrate with another board which switches relays based on serial data received.

I have a status LED that flashes in two states 20 ms or 200ms. I have an Arduino setup with an photo-transistor (TEMT6000) next to the LED (ambient light blocked out) and I need to print serial data (can be any serial data message) ONLY when the 200ms LED fires. At the moment the TEMT6000 is sampling at 10ms and I can see the data in serial monitor, and there is a clear distinction which LED has fired, but I need to measure it and conditionally print it.

I’ve searched around but can’t see even where to start with measuring duration of this sensor.

Any help much appreciated, Thanks!

The beginner's guide to millis() is a place to start. When the LED is sensed to come on, record the value of millis() in a variable. Every time through loop() check to see if it is still on and compare the current value of millis() with the recorded value. If the difference is more than 20ms, (or whatever duration) print.

Thanks! It looks like the millis command calls for a digital input, does that mean I should use a photodiode rather than an LDR? Or perhaps use a voltage divider to create a digital input?

It looks like the millis command calls for a digital input

I don't understand that. The millis() function takes no input. If your LDR is connected to an analog input, set a threshold for the light to be considered as "on".

If you post a schematic of your project and the code that you are using I could be of better help.

Great, thanks for the clarification.
At the moment, the only code I have is to read the value from the LDR and print it

int sensorPin = A0;   // select the input pin for ldr
int sensorValue = 0;  // variable to store the value coming from the sensor


void setup() {
  Serial.begin(9600); //sets serial port for communication
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  Serial.println(sensorValue); //prints the values coming from the sensor on the screen
  

  
  delay(10);                  
}

The schematic I have is attached below, hopefully that helps illustrate what I'm trying to achieve. And just to clarify, the serial output is not important, the secondary board monitors the RS232 traffic, and acts on any data that is received. Any help much appreciated!
Thanks

What value do you see from the analogRead(sensorPin) when the LED is on? What value when off?

EDIT-Sorry, I took a closer look at the sensor and it is actually TEMT6000 (a photo-transistor), if that makes any difference.

When on, average value is around 96, when off, value is usually 0, but a threshold of 5 would probably be safe enough.