I'm rather new to Arduino coding and was having a bit of trouble getting my code to have an LED trigger after having an IR Transceiver receive constant input for 10 seconds. The LED will trigger and stay on, but will also flash if the IR received an input, then 10 seconds has passed and it received another input. i have attached my code for any possible help.
You should initialize currentMillis to millis() in setup so it has a known value.
You should reset currentMillis to millis() when IR_SENSOR is HIGH (I assume LOW is triggered). This way the LED will only come on if the sensor has been triggered for more than 10 seconds and will stay on until it is not triggered anymore.
Thank you all very much for your help, not only was I able to get it to work because of your help. I also have a little better understanding of how to apply some of the commands
blh64:
Global variables are required to be initialized to 0 by the C/C++ standard so currentMillis is guaranteed to be 0 without explicitly setting it.
OTOH, doing so doesn't hurt anything and makes the intention clearer to the reader.
Good point blh64 and I knew that. Since I do the millis() timer thing quite often I always initialize it to millis() in setup(). I should have stated more precisely that currentMillis should be initialized to, in fact, the current millis() value. I appreciate you pointing that out so that the OP doesn't think it would be some random value.