phyphox Forums

Full Version: Double acoustic stopwatch and speed of sound
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I always had a trouble to find a partner with a phyphoxed smartphone to reproduce the speed of sound experiment ( https://phyphox.org/experiment/speed-of-sound/ ). And even if you have it you should register the time measured by two smartphones and calculate all... So it would be nice to control the experiment by one smartphone and calculate the seed of sound automatically. I saw the recent forum thread "Device for experimental physics teachers" ( https://phyphox.org/forums/showthread.php?tid=1026 ) using the Arduino nano sense 33 BLE which has a microphone (unlike the SensorTag of Texas Instruments). Perfect to realize the project! Just ask for this particular Christmas gift Angel .

Instead of a second smartphone the Arduino board can be used. Just to adopt the acoustic stopwatch to it and transmit the measurements by Bluetooth to my smartphone which will do the rest. I have modified correspondingly the phyphox stopwatch in the smartphone. Here are the results. Maybe the programs are not yet perfect but they works. One may remove control communication of the Arduino via serial port to make it completely autonomous. Also a version with 3 claps is possible to realize bidirectional measurements reducing difference of these 2 stopwatches. Arduino sound threshold may be defined by the smartphone as well...

Happy New Year 2021!
Mikhail

The programs for the smartphone and the Arduino nano sense 33 BLE... The extension ".txt" of the latter should be changed to ".ino".
Hello Mikhail!

Great to see our project inspired you! I was working on the same Speed of sound experiment 2 weeks ago but I didn't finish before going on vacation. It seems like you did it for me! I am going to test your experiment in the next days and probably try to make the Nano board autonomous.

Best regards,
Gautier
Hello Gautier.

My last version for you. I had a problem to send the threshold value to Arduino from smartphone, but it works now. I do not understand "PhyphoxBLE::configHandler=&receivedData;" and I add to the reinitialization simply "receivedData();"  (timer_dec30d.ino).

Now the experiment works so: 2 claps (1 over the Arduino, one over the smartphone, or vice versa) to measure the sound speed; 30 seconds the Arduino builtin led blinks and then remains in on state (the time you enjoy the results); 2 claps to return both watches to the initial state (the builtin led is off). No need to touch neither the Arduino nor the smartphone.

I think that it would be nice to control the Arduino (nano 33 ble sense) by light of different colors (https://phyphox.org/forums/showthread.php?tid=1254) ..

I would be happy to see your version of the sound speed experiment.

with Brest regards
Mikhail
Hello Mikhail,

To be honest, I don't really understand the "PhyphoxBLE::configHandler=&receivedData;" part but it has always worked fine for me so I keep using it.
My version of this experiment was not finished and I believe I am not going to finish it since yours is doing a good job! I did not read your code in details but I think mine worked in a quite similar way.
I tried your program and it worked well, however I have a few remarks:
- the Arduino threshold is originally set to 4444, but I had to lower it to around 100 to make sure my claps were detected. Did it work for you with such a high threshold?
- in my opinion, resetting the experiment with 2 other claps and after 30 seconds is not very practical, especially when the experiment did not work. For instance, the phone heard the claps but the board missed one and you now have to wait 30 seconds until you can reset it. In addition, I did not manage to reset the experiment with the "bin" button of Phyphox, so I had to leave the experiment and open it again every time.
- I am probably going to try to modify your program at the end of the week, so it does not need to be connected to a computer to work. I believe this would be better in a classroom where it is not always practical to have computers everywhere.
- to avoid having to connect your phone to the board twice at the beginning of the experiment, you can follow these instructions: https://phyphox.org/wiki/index.php/Bluet...e_matching

Anyway, congratulations for your work! I am going to check your other topic about controlling with colors.

Best regards,
Gautier
Hey everyone,

very cool projects! Just want to give a short explanation to the "configHandler" topic.

In your experiment the user can set a treshold with the edit field and send it to the arduino. The way you designed the .phyphox file, the treshold is transfered every analysis cycle. To actually use the last transfered treshold in your arduino sketch you have 2 options:

A) call: PhyphoxBLE:read(myFloat) to update the float variable myFloat with the newest treshold. The problem with this method is, that you dont have a strict time relation between new data has been transfered and is actually used in your sketch. You also have to call this function as often as possible to get the transfered data as soon as possible.

B) Instead of calling the read function many times you can write a function which is executed every time a new value is transfered to the arduino. Let say you want to blink your onboard led everytime you get data and update your float variable:

Code:
void example_function(){
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
[size=small] digitalWrite(LED_BUILTIN, LOW);[/size]
[size=small] [color=#000000][size=small][font=Tahoma, Verdana, Arial, sans-serif]PhyphoxBLE[/font][/size][/color][color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]:read(myFloat);[/font][/size][/color][/size]
}

This function will do the variable update & blink job. Next step is to pass this function to the phyphox library so it gets executed after new data received.

Code:
  PhyphoxBLE::configHandler=&example_function; (this should be done in the setup block)

With this method you dont have to call the read-function as often as possible. This is especially useful if you receive new data very rarely. Hope this helps a bit.

Cheers
Dominik
Hi Dominik,

thank you for the explanations. Somehow "PhyphoxBLE::configHandler = &receivedData;" did not work correctly with the double stopwatch and I added direct reading.. In order to test the communication I have prepared a simplified example attached here. I have included to the communication function led blinking and printing of the transferred parameter. The function is called all the time (and led is blinking without interruptions) even if the value to be transferred is not changing in phyphox. Instead it is transferred every phyphox cycle...

For the stopwatch using of the configHandler may introduce some distortions of the Arduino part... And probably it did.. So probably it would be better to read the value when the time count is finished.

Bonjour Gautier.

Some answers to your comments:
- original set to 4444.4 is historical, I wanted to see from where the parameter is coming. The good Arduino threshold value for me is about 200 when I can move from Arduino to the phone without noise.
- when the Arduino and the phone are desynchronized the phone can be put to the original state by the "RESET" button. At the same time I did not want to touch the Arduino, particularly the Arduino reset button which brakes the Bluetooth communication. Two claps is coming from my modification "Contactless acoustic stopwatch" (attached here) when I produced a video with the stopwatch and did not want to appear in it.
- thank you for the given info how to make the program better.

Cheers
Mikhail
Hello everyone.

Here is the last version taking into account the comments above and the best result Smile . In order to make the Arduino autonomous it is sufficient to eliminate the serial printing used now for control of the Arduino parameters.

With Brest wishes
Mikhail
Dear creators of PhyphoxBLE,

we have decided to use the double acoustic stopwatch for our presentation of waves during the Fête de la Science this year. So it has been modified a little: All indication was assembled to one page and Arduino was equipped with a screen to see directly its measurements and parameters. Also I attempted to add a second parameter to be sent from smartphone to Arduino (the minimum time delay), but it did not work...

So the actual problem is that only second parameter sent pass correctly, the firs one coming as zero (parameters are float). This does not depend on input parameters "offset" and "length" of Bluetooth output. Could you help? Huh

The double acoustic stopwatch is functioning so: At the initial state of Arduino its RGB led is green. On the first clap the smartphone and Arduino start measuring, the Arduino RGB led is blue. After second clap the time measurement are stopped and indicated, the time measured by Arduino is sent via Bluetooth to smartphone and the sound speed is calculated. The Arduino RGB led is becoming red at this moment. After red is switched off after some seconds both smartphone and Arduino can be returned to original state by two more claps and the Arduino parameters (threshold and time delay) are sent via Bluetooth from smartphone to Arduino on the second clap. If Arduino and smartphone are desynchronized the "RESET" button on smartphone can be used. Current indications via Serial connection will be removed in the working version. Cool

[attachment=423] [attachment=424]

With Brest regards.
Mikhail
AFAICT, “offset” is not implemented for the “output” block. The elders of phyphox (BLE) are on it…
So, actually it is not possible to send more than one value from smartphone to Arduino?
Pages: 1 2