I am trying to build a set of four stars using an Arduino, potentiometer and a four channel relay to control how fast it speeds across the stars. My question is how can I delay the process, say for 20 or 30 seconds before it starts again?

3 Answers 3


Use Delay( ). Or this code

long previousMillis;

void setup(){
  previousMillis = millis();//in void setup
  bool lS=LOW;//in void setup

void loop(){
  long currentMillis= millis();//in void loop

     if (lS==LOW){
     previousMillis= millis();

While this does not serve your purpose, it shows you an how to switch on and off and LED after every 20 sec without keeping the Arduino idle for 20 sec.You could improve on it and make your own code.

  • Thanks FuaZe , for the edit.It looks a lot more easy to understand now , though the whole code is exactly the same to the Arduino. Apr 16, 2015 at 10:12

If you want to just provide a delay use this function

delay(ms) -> where the argument is an integer value that represents the time in milliseconds.

For example, 1s = 1000ms

If you wanna stop everything and wait 1s, just use like that:


Note that the atmega controller will stop everything it is doing and wait the amount of time. If you need to count or wait for something while other things are occurring, use timer interrupts. So the counting process is done in background and your main loop continues to do its jobs.



delay(20000); // wait for 20 seconds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.