/* Single Shot Timer Code Alternative to ElapsedMillis (c)2015 Forward Computing and Control Pty. Ltd. This code may be freely used for both private and commerical use. Provide this copyright is maintained. */ int led = 13; unsigned long timer; // the timer boolean timedOut = false; // set to true when timer fired unsigned long INTERVAL = 5000; // the timeout interval void setup() { pinMode(led, OUTPUT); // initialize LED output timedOut = false; // allow timer to fire timer = millis(); // start timer } void loop() { // this will toggle the led ONCE only after 5sec (timeOut) if ((!timedOut) && ((millis() - timer) > INTERVAL)) { // timed out timedOut = true; // don't do this again // you can reset the single shot timer by setting // timedOut = false; // timer = millis(); // toggle led if (digitalRead(led)) { digitalWrite(led, LOW); // turn the LED off by making the voltage LOW } else { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) } } }