How can I program a timer with Arduino?

Hi, a friend and I have to build something for a school project. We've decided on a shooting range, and we're given 60 seconds in total. The whole thing is supposed to be shown on an LCD display, so it's supposed to count down from 60. We're using an Arduino Uno and the Arduino program. I'd be grateful for any help, because we're really desperate. It would also be okay if you just gave us a tip, like what to do, e.g., a for loop or if. If you have any questions, I'd be happy to answer them as best I can.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Elumania
1 year ago

That’s how you can start. This is where the timer counts from 60.

https://www.tinkercad.com/things/dL5f8iZq4Y3-gf-timer-60sek-auflcd-display

RareDevil
1 year ago

I always like to be a friend of using the “millis()”.

You can find an example under “Blink without delay”… Of course, you could also use delay, but no further function is possible during the break. If you go through the millis() function, you can react to any further function, key pressure, etc. This makes the whole thing very flexible…

apophis
1 year ago

If the Arduino is to do nothing but the timer, you can simply use the Sleep command.

set a variable to 60,
let the program sleep for a second,
reduce the variable by 1,
display the variable,
stop as soon as the variable 0 reaches.

If the Arduino should have more functions (you write something from a shooting range), this solution does not work.
In this case, you can work with the millis function and the deltatime.
This is generally also the more precise and more elegant solution.

The millis function shows you how much time has passed since the start of the Arduino.
You can regularly query and check the time for a second. And then update according to the timer.

The whole then works via if-enquiries and can therefore easily be used together with other program sequences.