Go Down

Topic: Timer (Read 306 times) previous topic - next topic


I am doing my first project and looking for the timer code to turn the output ON / OFF after certain time say 1 minute or 5 minutes.  Currently I am using millis() to achieve this, but I think there will be a better way to do this, any suggestions are welcome!!!

Currently I am using below sketch to turn OFF the output after 1 minute.

unsigned long time;
void setup() {
  pinMode(13, OUTPUT);
  pinMode(9, INPUT);

void loop() {
  if (digitalRead(9) == HIGH)
  digitalWrite(13, HIGH);
    time = millis();

if (millis() - time > 60000)
digitalWrite(13, LOW);



On the top of every single page is a link to the Playground. On the main playground page, there is a link, in the left column, to user contributed libraries. A number of them relate to timing.

Go Up