Arduino and time detection (ms scale)


I'm new to Arduino, and for a project I have, I'm not sure the Arduino platform is a good choice.

My goal is to make a measurement of the time elapsed between two events. the precision needs to be at least 1 millisecond or so. The maximum time needed to be measured would be around 1 second, roughly. Also, the user could let know Arduino when the measurement is to be done (if necessary to prevent Arduino to constantly look for the event), the time for looking for the event could then be around 10sec, 1mn, or simply while the user press a button.

The events are taken from physical world via transducers, whose signals are then conditionned to be used on 2 analog inputs of an Arduino.

then Arduino would check if thoses analog inputs are going above a certain threshold. If yes, the millis() or micros() method would be used to catch the time of the events. A simple substraction between the time of event 1 and 2 would then give the time elapsed between the two events. Number that could be displayed then.

My concern is the following:

How much often Arduino do look to it's analog input for sure? If it's not often enough, I could either miss an event, or capture it with an error of measure too big.

Supposing the measurement takes place when the user press a button (so when a digital pin input is 1), I would have a loop like that (pseudocode and very simplified, not taking into account for instance which event happens first, variables declarations, etc...)

While(userWantsMeasurement) {
   if (analogPin1 > threshold1) {
       time1 = micros();
   if (analogPin2 > threshold2) {
       time2 = micros();
       display(time2 - time1);

How much often the analog pins value will be checked? sufficiently enough for my application? Is it "hardwired", or does it depends on the code placed in the while loop?

Thanks a lot.

Reading an analog pin takes about 110us using the standard Arduino setup. So you can achieve the 1ms resolution you are looking for, provided that the event you are looking for on the analog pin lasts long enough to be noticed, say 200us.

If your Arduino has a ceramic resonator, then the clock accuracy is around 0.5%. Therefore, although you may achieve 1ms resolution, you won’t achieve 1ms absolute accuracy when the interval is as high as 1 second.

Thanks a lot for your answer! it covers all my needs...

BTW, which Arduino's have or don't have a ceramic resonator? or otherwise, which Arduinos have the most precise clock? I don't need it for this project, just curious.

The Arduino Uno has a ceramic resonator. I don’t know about the others, but I think most of them have crystals, which provide better accuracy. For serious timekeeping, you can connect a real-time clock to the Arduino.

Thanks again!

faster analogread with less precission but maybe good enough see-,56396.0.html -

Reading an analog pin takes about 110us ... provided that the event you are looking for on the analog pin lasts long enough to be noticed, say 200us.

Probably best to stick with Nyquist's advice: 110 us * 2 = 220 us.