0

I want to program arduino uno by using it's own timer , which instructions and codes should be used if i want timer to be set for 5 minuets and then warn me about an event , the problem is that , the timer could not be set for minutes but for milliseconds , so how to program it for minutes?

  • Investigate the BlinkWithoutDelay example, that comes with the Arduino IDE. Thats a good way to do such things – chrisl Apr 6 at 16:10
  • why is it a problem to time 5 minutes in milliseconds? ..... how would you time 5 hours if the timer only displayed minutes? – jsotola Apr 6 at 16:35
  • 2
    Hint: How many milliseconds are there in 5 minutes? – sempaiscuba Apr 6 at 20:14
0

I had it ready. Hope it helps.

unsigned long aika = 0;
unsigned long h    = 0;
unsigned long m    = 0;
unsigned long s    = 0;

void setup() {
   pinMode(13, OUTPUT);
   Serial.begin(9600);
   Serial.println(" Connection OK ");
   digitalWrite(13, HIGH);
   delay(1000);
   digitalWrite(13, LOW);
}

void loop() {
   aika = millis();
   h = aika / 3600000;
   m = ((aika / 60000) - (h * 60));
   s = ((aika / 1000) - (h * 3600 + m * 60));
   // milliseconds run over in about 50 days !!!

   Serial.print("  Time ");
   Serial.print(h);
   Serial.print(" h ");
   Serial.print(m);
   Serial.print(" m ");
   Serial.print(s);
   Serial.println(" s ");

   if(m > 4)
   { // if minute is greater than 4 write pin13 HIGH and lit up LED
      digitalWrite(13,HIGH); 
   }

   // note .. nothing turns off LED ... exept resetting 
   // or opening new serial console

   delay (1500); //wait 1.5 sec
}
  • Markus, the solution is in the blink-without-delay example. When using that, it does not matter if millis rolls over. Can you start a 5-minute timer with a button? That is easy with the blink-without-delay, but you have to start using the blink-without-delay: arduino.cc/en/Tutorial/BlinkWithoutDelay – Jot Apr 8 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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