The function delay is really useful in an Arduino program. It is used to stop a program during a given time to wait the next measure of a sensor for example or permits to user to read the value on the serial monitor.
The function delay can be also useful to blink a LED. That way the user has time to see the light turning on and off. Without a delay it would be too quick and the user won’t see the blinking.
We will different function to use a delay:
The delay function is used to stop the program with given time in milliseconds:
delay(millisecond);
The value we will enter is in millisecond, that mean if you want 1 second of break we write:
delay(1000); // One second of break
It is possible that sometimes in your program you need a more accurate break, in microseconds for example. We will see a function to do that :
The function delayMicrosecond can be used to do a break in a program in microsecond:
delayMicroseconds(us); // Value in microsecond
delayMicroseconds(1); // 1 microsecond