Is there a substitute for delay()


I am working on programming the IR remote, and I use delays all the time. For example, to make it go for half a second, I would do something like this:`;;

But the delay() command uses 100% of the processor, so it is oblivious to IR commands during the time the delay is activated. If I did a command and then decided to cancel it, I could not do that because it is unresponsive. Is there any way I can make it wait without using the delay() command so it will still respond during the command?


Hi Niall,

Yes there is. Check out This tutorial about how to use the millis() function instead.

Have fun, Stefan


Agreed. The delay() method is a blocking call. You’ll need to use the millis() call and a static variable to track whether or not to start/stop executing your code.


I tried that, and it only works for values greater that 500 milliseconds. Here is my code, is there a problem?

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > 500) {
previousMillis = currentMillis;;;