Hello, I need to start and stop a timer based on the blinking state of an LED for a project. The timer should start when the LED is on and stop when the LED is off. I'm looking for help on how to achieve this.
Please use English in the main forum category.
First you need to figure out how you will detect that the led is flashing. Can you use a light sensor such as an LDR or Phototransistor? Can you connect wires directly to the led?
Your topic has been moved to a more suitable location on the forum.
I'm not using a light sensor; instead, I've set the LED as an INPUT, and I provide the status to the Arduino when it's on. I want to achieve this using the millis() function if possible
Hello kayubaba
Post your current sketch in code tags to see how we can help.
if (digitalRead(LED_PIN)) // read the state of the LED pin
startTimer(); // if HIGH, start the timer
esle
stopTimer(); // if LOW, stop the timer
This only sees HIGH or LOW... for blinking, you will want to see if H/L/H/L exists.
@kayubaba are you trying to measure how much time a signal is HIGH compared to how much total time has elapsed?
Like the timer runs while the signal is high, pauses when low and resumes accumulation or the time measured when the signal is again high.
Or do you want the timing to run continuously as long as the light is blinking, in which case how do you define blinking?
What range of frequencies and what range of duty cycle fit within your definition of blinking?
a7
My goal is to start the timer when the signal is HIGH, and since I know the total signal duration, I want to subtract the timer duration from the total signal duration until the signal goes LOW, i.e., to calculate how much time is left for the process to end.
Tell us the entire story of your project.
It's not clear what you want to do.
Do you want to time how long the led is off for each individual blink?
Do you want time from the first blink to the last blink? (The difficulty with that is not knowing if another blink will come, but that can be solved.)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.