Difference in timestamps is inconsistent

Hello everyone!

I hope you´re doing fine. I´ve been developing an app to measure the reaction time to an audio. The idea is simple: when an audio is played, a timestamp is saved in a variable, and once a significant response is detected, another timestamp is saved in a different variable. The, the reaction time is the difference between the two. Now here is the problem.

One of the subtleties of this program is that it won't detect a reaction until 2 seconds have passed - this as a way of avoiding a false input caused by the player having their phone in a weird position. I control this through a timer: when an audio is played, the timer is enabled (for 1.6 seconds) and after these have passed, the accelerometer is enabled. This means that the minimum time possible for a response would have to be 1.6 seconds right? Well, in my phone (S9+) it gives me around 2 seconds, with a difference of about 10 milliseconds, wich I find appropiate. But, when I try this app in other phones, it gives around 1.6 seconds. How can I make sure that the time measurement will be similar in different phones?

Here are the relevant blocks to the program

This is the block that plays the audio and proceeds to enable the aforementioned timer and save the timestamp. I include only a part of it because it's kinda large, but the idea is the same.


Here's the timer event in question.

And here's the block that proceeds to save the other timestamp and calculates the difference. Again, I only include a small part because it's quite large, and the idea is the same.

Any sugegstions or ideas are welcomed.

EDIT: I forgot to mention that the testing was done using the companion app.

Best Regards


Hello Manacho

  1. Partially answered your own question - it's not reasonable to expect optimum results from the Companion.

  2. The Timers do not have sufficient system priority for the accurate timing you require. Fortunately, my colleague Anke is creating an extension that does deliver accurate timing:
    Upcoming extension: countdown / up timer - date / time format - in real time

1 Like

Hello ChrisWard!

Thanks for your answer. I understand that using the companion app may have influenced the results. Do you think that if I do the testing using a full buid my results will be more consistent? The thing that really troubles me is the difference between the "theoretical" 1.6 I should be getting and the 2 I actually got. Would there be a way to estimate for an error and then modify the calculations according to that?

About the timer by Anke, I had actually read something about it. However, I didn't really find a way to import it as an extension to my app. I know it's still in development, but I only need de timer.now method to do my calculations. Do you know a way to import it as an extension?

Thanks for your help and time

you might want to test again using the apk file together with your different test devices...
let us know , what you find out...
the more things are running in the background of your device, the larger might be the difference...

also you might want to simplify your blocks... remove the redundancy...
for example these blocks are identical... no need for these duplicates...


1 Like

Hey Taifun

Thanks for taking the time to help with this. I see your point, however, this redundancy is kind of necessary. The idea is that enabling the timers and playing the sound should happen at the same time. Because of that, I tried to put as little code between the audio play and the sensor setters as possible. However, I understand that it won't ever be simultaneous.

My process of thinking was that trying to get as little code as possible between these instruction and making them as close as possible (so that the processor won't have to jump to another adress to get the instruction) it would be as simultaneous as it could. However, I may lack some info on how App Inventor works or some insights in its compiling. Any more info on this would be appreciated.

Thanks for everything, I'll do some more testing and get back to this with the results.


redundancy is never necessary! a little bit reduced:
also why are you using several sound components? use only one and set the source of the sound before playing it, you even could set the sound to play dynamically according to the id...
more reduced:

and why are you using 3 clock compponents? reduce your components and blocks!



Post a little test aia so we can check it, including what the time difference causes (Clock, AccelerometerSensor ...).

(It is not yet clear to me what exactly should happen and how in your app.)

Test this app (which uses a simplified version of my (unpublished) timer extension):


question about your blocks

Btw, what does this mean:

Dears @Anke and @Taifun,

I profusely apologize for my lack of any answer. I got stuck up in some other work that was more urgent in the last few weeks. If it stills interests you,

@Anke: I tested your .apk, it works wonderfully! However, from the pictures of the blocks you sent, I can't seem to figure out how it is so accurate. Is there a way you could tell me? Regarding your other question, the block you pointed is supposed to get the difference between the two timestamps, the one which got captured after the audio was played, and the one captured after a movement was detected (timeIni and timeFin respectively). In any case, I sent you a DM.

@Taifun: Ok! I see it now, thanks for pointing it out to me. I'll fix it and leave it pretty when I have more time :sweat_smile:

Again guys, thanks a lot for all the help you always give, and I apologize again for my unresponsiveness.

Best Regards


If I can find this version of my modified extension again, I'll send you it via PM.

and post the result of "Do it".
I think you won't get what you probably expect.

If you could I'd be very gratefull!

Regarding the block you mentioned, it does what it's supposed to do, roughly. The variabe timeIni is declared in another block, so if I execute only the aforementioned block it won't work. However, as a group, the only problem I have is that it's not as accurate as it should.

I sent you the app in your DMs

Best regards

use Do it to debug your blocks, see also tip 4 here https://puravidaapps.com/learn.php
see also Live Development, Testing, and Debugging Tools

Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

1 Like