How can make Arduino Timer code instead of delay function

3 Responses

  1. admin says:

    Do you mean using a timer (like millis() function or similar) instead of a delay in between the output LED digitalwrite() function (HIGH and LOW). Could you please explain more?

    • Carmine says:

      Hello yes millisecond , i need to put another switch with other output wich trigger other relay with a different time ( in milliseconds).
      That is why i need to put a millis instead of delay.
      I tryed with same functions used in ( blink without delay) but it stay always on after i push switch button…
      Thank you….

      • admin says:

        Try this, the below code checks whether the time equal to delay is passed since the output is switched ON, if the time in millis() after switch ON is greater than set delay then it will switch OFF the output.

         long time_millis = 0;//Intialize as long
         delay_time = 100; //In seconds
        if (buttonState == HIGH && prestate == 0) {
         // turn LED on
         digitalWrite(ledPin, HIGH);
         time_millis = millis();
         prestate = 1;
        } else if (buttonState == LOW) {
         prestate = 0;
        // turn LED off
        if ((millis() time_millis) > (delay_time * 1000)) {
         digitalWrite(ledPin, LOW);

Leave a Reply

Your email address will not be published. Required fields are marked *