Time code example

hello! how are you?

I started playing with Arduino recently and I wanted an example of how I would make a code that records the time, but preferably a simple code (I saw some of the timer and I was kind of lost).

can be using light sensor or button.

I don't know if it helps, but I was wondering how long it takes for an object to go and come back to the same place, in seconds.

Elapsed time using the Arduino crystal controlled oscillator are rather common in the "stopwatch" classification:

(arduino stopwatch sketch using millis - Google Search)

The internal clock is not really a good "real" clock unless a precision time keeping crystal is on the Arduino board (separate and less sensitive to temperature changes.) These Arduino boards will typically state they have RTC capability.
https://www.google.com/search?q=arduino+boards+with+RTC+capability

I was wondering how long it takes for an object to go and come back to the same place, in seconds.

The answer is, "unknown" or variable. The fastest the main loop will cycle is when the loop is "empty":

void loop() {
}

Adding function calls and statements in the loop construct will consume time, that is, will increase the overall loop time.

depends on what the "object" is.

A call to a few lines of code will take 0,000125 seconds

This is a waaaayyyyy tooo unprecise description of what you mean.

"recording" time in the sence of how many seconds have passed by but then since what?

"recording" in the sence of how much time has passed by since execution of ..... yeah what? has started

There are two commands that can be used to measure executiontime

millis() for measuring milliseconds
and
micros() for measuring microseconds.

See the arduino reference

As you just started learning programming
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.