Which arduino do I use?
Moderators: AmyCowen, kgudger, bfinio, MadelineB, Moderators
-
Misobower1
- Posts: 1
- Joined: Sun Aug 31, 2025 12:58 pm
- Occupation: Student
Which arduino do I use?
I am doing the ultrasonic haptic feedback project and am wondering if an arduino uno r3 will work instead of an r4
-
Snehaarun
- Student Expert
- Posts: 26
- Joined: Fri Oct 04, 2024 11:30 pm
- Occupation: Student
Re: Which arduino do I use?
Hi!
Could you please provide the link of the project you are working on so I can get more details about the specifications of the project?
It seems as if the only differences between the R4 and R3 versions of the Arduino are the ports, but you can still use similar libraries for the R3 and R4. However, I would need the exact project to help you find out whether you can actually use the R4.
Thanks!
Could you please provide the link of the project you are working on so I can get more details about the specifications of the project?
It seems as if the only differences between the R4 and R3 versions of the Arduino are the ports, but you can still use similar libraries for the R3 and R4. However, I would need the exact project to help you find out whether you can actually use the R4.
Thanks!
-
MadelineB
- Moderator
- Posts: 973
- Joined: Fri Jun 20, 2014 4:42 pm
- Occupation: Biostatistician/Data Scientist
- Project Question: Interested in volunteering as an expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Here's a science buddies project that uses ultrasonic haptic feedback:
https://www.sciencebuddies.org/science- ... c-feedback
https://www.sciencebuddies.org/science- ... c-feedback
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Hi - while a lot of Arduino code is compatible between the R3 and the R4, that isn't actually the case here when generating the 40kHz ultrasonic signal, so you have to be careful. The Arduino has a function called tone that you can use to generate a square wave of a certain frequency on a certain pin:
https://docs.arduino.cc/language-refere ... d-io/tone/
That seems simple enough, however, the function is not accurate at high frequencies. I tested it on an R4, and trying to generate a 40,000 Hz signal actually resulted in a 41,670 Hz signal on an R4. That is why the code posted for the project uses delays and digitalWrite to manually turn the pin on and off to generate an approximately 40,000 Hz signal - I had to experiment with the right delay time to get the signal I wanted.
So if you are using an R3, you have two options:
1) Keep the code but experiment with changing the delay time (the R3 and R4 processors run at different speeds) until you get the best response out of your ultrasonic transducer
2) Change the code to use the tone() function instead of digitalWrite to generate a 40,000 Hz signal, because by coincidence/luck, you DO get a fairly exact 40,000 Hz signal on an R3 (but it is slightly off at other frequencies).
Hope that helps.
https://docs.arduino.cc/language-refere ... d-io/tone/
That seems simple enough, however, the function is not accurate at high frequencies. I tested it on an R4, and trying to generate a 40,000 Hz signal actually resulted in a 41,670 Hz signal on an R4. That is why the code posted for the project uses delays and digitalWrite to manually turn the pin on and off to generate an approximately 40,000 Hz signal - I had to experiment with the right delay time to get the signal I wanted.
So if you are using an R3, you have two options:
1) Keep the code but experiment with changing the delay time (the R3 and R4 processors run at different speeds) until you get the best response out of your ultrasonic transducer
2) Change the code to use the tone() function instead of digitalWrite to generate a 40,000 Hz signal, because by coincidence/luck, you DO get a fairly exact 40,000 Hz signal on an R3 (but it is slightly off at other frequencies).
Hope that helps.
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
hi i am back again with another question, i am trying to use the provided formula to find the frequency.
periodMS = 4*numPulses*(Delaytime+digitalwritetime)
Frequency(Hz) = 1/periodS
i am using the formula but it is giving me an unrealistic frequency, when i use the variables given in the video the resulting frequency is 208hz. Can you please tell me what i am doing wrong. I created a python script to do it automaticallly maybe i messed that up.
Code:
delayTime = 10
numPulses = 5
digitalWriteTime = 2
offTime = 2*(digitalWriteTime+delayTime)*numPulses
periodMS = 4*numPulses*(delayTime+digitalWriteTime)
periodS = periodMS/1000000
frequency = 1/periodS
print(frequency)
periodMS = 4*numPulses*(Delaytime+digitalwritetime)
Frequency(Hz) = 1/periodS
i am using the formula but it is giving me an unrealistic frequency, when i use the variables given in the video the resulting frequency is 208hz. Can you please tell me what i am doing wrong. I created a python script to do it automaticallly maybe i messed that up.
Code:
delayTime = 10
numPulses = 5
digitalWriteTime = 2
offTime = 2*(digitalWriteTime+delayTime)*numPulses
periodMS = 4*numPulses*(delayTime+digitalWriteTime)
periodS = periodMS/1000000
frequency = 1/periodS
print(frequency)
-
amyCC
- Site Admin
- Posts: 398
- Joined: Wed Apr 01, 2020 4:02 pm
- Occupation: Moderator
- Project Question: *
- Project Due Date: *
- Project Status: Not applicable
Re: Which arduino do I use?
I notice you've posted another thread with this question. I am adding the link here so that experts see that there is another thread. It's always best to keep all questions in one thread.
viewtopic.php?t=25021
viewtopic.php?t=25021
-
amyCC
- Site Admin
- Posts: 398
- Joined: Wed Apr 01, 2020 4:02 pm
- Occupation: Moderator
- Project Question: *
- Project Due Date: *
- Project Status: Not applicable
Re: Which arduino do I use?
Your Python script looks okay for the equations given in the project.
Keep in mind that you are calculating the modulation frequency, not the Hz of the ultrasonic signal itself.
As noted in the project introduction, we can’t feel a continuous 40 kHz sound, so the signal must be pulsed on and off at a lower rate that we can detect with our finger.
The equations in the directions are for finding that lower rate (the "modulation frequency").
Does that help?
Amy
Science Buddies
Keep in mind that you are calculating the modulation frequency, not the Hz of the ultrasonic signal itself.
As noted in the project introduction, we can’t feel a continuous 40 kHz sound, so the signal must be pulsed on and off at a lower rate that we can detect with our finger.
The equations in the directions are for finding that lower rate (the "modulation frequency").
Does that help?
Amy
Science Buddies
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
oh ok thank you so much that helps alot
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
Is there anyway to calculate the highest ultrasonic frequency it will operate at and is the offtime calculation in microsecond?
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Hi - do you mean that you want to drive the ultrasonic transmitter at a frequency higher than 40kHz? (the actual underlying ultrasonic frequency, not the lower modulation frequency that Amy discussed).
If so, there is no easy way to calculate that in advance. If you watch the full video for the project, in the middle there is an explanation of the transmitter's resonant frequency and frequency response: https://youtu.be/xXqoGwIPiK8?si=AWkjfmPQdAzvTDuV. In short, the transmitters are designed to vibrate the most at a certain frequency. If the frequency is too low, they won't vibrate enough and won't produce any ultrasonic sound. The same is true if the frequency goes too high. You can determine the resonant frequency of your ultrasonic transmitter experimentally by varying the frequency and seeing where you get the loudest response on a receiver, but doing this generally requires an oscilloscope. You can also experiment by "feel" with both the underlying ultrasonic frequency and the modulation frequency to see what gives you the strongest response. Hope that helps, but let me know if I misunderstood your question.
If so, there is no easy way to calculate that in advance. If you watch the full video for the project, in the middle there is an explanation of the transmitter's resonant frequency and frequency response: https://youtu.be/xXqoGwIPiK8?si=AWkjfmPQdAzvTDuV. In short, the transmitters are designed to vibrate the most at a certain frequency. If the frequency is too low, they won't vibrate enough and won't produce any ultrasonic sound. The same is true if the frequency goes too high. You can determine the resonant frequency of your ultrasonic transmitter experimentally by varying the frequency and seeing where you get the loudest response on a receiver, but doing this generally requires an oscilloscope. You can also experiment by "feel" with both the underlying ultrasonic frequency and the modulation frequency to see what gives you the strongest response. Hope that helps, but let me know if I misunderstood your question.
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
hi yes that does sort of help. to clarify there is no way to calculate exaclty the ultrasonic frequency it will operate at like you can for the modulation frequency.
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
An add on to my previous question. Does the resonant frequency change if I change the number of pulses variable. If so how do I calculate that if not what is the resonant frequency. Thank you
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Ok, it's important to make sure we aren't mixing up a few different things here. Let's use a swing as an analogy. A swing has a resonant frequency, also called its natural frequency. The natural frequency depends on the length of the ropes holding the swing. When pushing the swing, it will go highest if you push it at the natural frequency. You don't HAVE to push the swing at its natural frequency, however. You can try to push it faster or slower, but if you do that, it won't go as high.
The ultrasonic transmitter is similar. It has a natural frequency that depends on its physical properties (its size, shape, and what materials it is made of). You can't change that. If you want to get the biggest response (the loudest ultrasonic sound) out of the transmitter, you need to push it at its natural frequency. You don't HAVE to do that though - you can push it at another frequency, but the ultrasonic sound wont' be as powerful. The frequency at which you push the ultrasonic transmitter is called the "drive" frequency.
You can calculate the drive frequency using the equation
frequency = 1/period
So to find the frequency, you need to find the period. One period of an ultrasonic pulse comes from this part of the code:
digitalWrite(ultrasonicPin,HIGH); // set pin high
delayMicroseconds(delayTime); // wait
digitalWrite(ultrasonicPin,LOW); // set pin low
delayMicroseconds(delayTime); // wait
So, the period would be
period = 2*(digitalWriteTime + delayTime)
on an Uno R4, I measured digitalWriteTime to be about 2 microseconds. This value is slightly different on an R3 but I don't have the measurement handy.
Another way to do this is to use an oscilloscope, if you have access to one, to measure the frequency of the actual output signal on the Arduino pin, which will account for any delays in the code.
I hope that helps.
The ultrasonic transmitter is similar. It has a natural frequency that depends on its physical properties (its size, shape, and what materials it is made of). You can't change that. If you want to get the biggest response (the loudest ultrasonic sound) out of the transmitter, you need to push it at its natural frequency. You don't HAVE to do that though - you can push it at another frequency, but the ultrasonic sound wont' be as powerful. The frequency at which you push the ultrasonic transmitter is called the "drive" frequency.
You can calculate the drive frequency using the equation
frequency = 1/period
So to find the frequency, you need to find the period. One period of an ultrasonic pulse comes from this part of the code:
digitalWrite(ultrasonicPin,HIGH); // set pin high
delayMicroseconds(delayTime); // wait
digitalWrite(ultrasonicPin,LOW); // set pin low
delayMicroseconds(delayTime); // wait
So, the period would be
period = 2*(digitalWriteTime + delayTime)
on an Uno R4, I measured digitalWriteTime to be about 2 microseconds. This value is slightly different on an R3 but I don't have the measurement handy.
Another way to do this is to use an oscilloscope, if you have access to one, to measure the frequency of the actual output signal on the Arduino pin, which will account for any delays in the code.
I hope that helps.
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
Hello my name is Michael; I'm in 8th and I'm doing a project on ultrasonic haptic feedback from Science Buddies (I have been asking questions on the ask an expert forum under the username misobower1 (or misobower123)). My teacher recommended to literally "ask an expert" so I am asking you.
Is it ok if I ask you a couple question.
Is there any way to calculate the ultrasonic frequency not the resonant frequency.
This part.
I will be testing if I change the variable (numPulses) how will it affect the frequency and how the sensation will be different for different people of different ages. Do you know how age will affect the sensation. Another question when I am refering to the numPulses variables, would I say 100pulses/microsecond?
I also coded a program to do the calculations for me. Is there anything you think I could add or should change.
Code (python) :
delaytime = 10
numpulses = 300
dwt = 2
offtime = 2*(dwt+delaytime)*numpulses
#calculations
periodμs = 4*numpulses*(delaytime+dwt)
period_sec = periodμs/1e6
frequency_modulation = 1/period_sec
#arrondissement
rounded_frequency = round(frequency_modulation, 2)
#frequence avec unité
frequency_word = f'{rounded_frequency}Hz'
print
#frequence avec unité et un meesage
frequency_hz_meesage = f'La fréquence de modulation est {frequency_word}'
if rounded_frequency <=1000:
print(frequency_hz_meesage)
else:
print('erreur'.title())
#offtime
offtime_word = f'{offtime}μs'
#frequency in kHz; not likely to use
frequency_kHz = rounded_frequency/1000
frequency_kHz_rounded = round(frequency_kHz, 2)
frequency_kHz_rounded_word = f'{frequency_kHz_rounded}kHz'
frequency_kHz_message = f'La fréquence de modulation est {frequency_kHz_rounded_word}'
Would it be ok to have your credentials as I would need to list them for my bibliography.
Thank you,
Michael
[Administrator note: post edited to remove personally identifying information.]
Is it ok if I ask you a couple question.
Is there any way to calculate the ultrasonic frequency not the resonant frequency.
This part.
I will be testing if I change the variable (numPulses) how will it affect the frequency and how the sensation will be different for different people of different ages. Do you know how age will affect the sensation. Another question when I am refering to the numPulses variables, would I say 100pulses/microsecond?
I also coded a program to do the calculations for me. Is there anything you think I could add or should change.
Code (python) :
delaytime = 10
numpulses = 300
dwt = 2
offtime = 2*(dwt+delaytime)*numpulses
#calculations
periodμs = 4*numpulses*(delaytime+dwt)
period_sec = periodμs/1e6
frequency_modulation = 1/period_sec
#arrondissement
rounded_frequency = round(frequency_modulation, 2)
#frequence avec unité
frequency_word = f'{rounded_frequency}Hz'
#frequence avec unité et un meesage
frequency_hz_meesage = f'La fréquence de modulation est {frequency_word}'
if rounded_frequency <=1000:
print(frequency_hz_meesage)
else:
print('erreur'.title())
#offtime
offtime_word = f'{offtime}μs'
#frequency in kHz; not likely to use
frequency_kHz = rounded_frequency/1000
frequency_kHz_rounded = round(frequency_kHz, 2)
frequency_kHz_rounded_word = f'{frequency_kHz_rounded}kHz'
frequency_kHz_message = f'La fréquence de modulation est {frequency_kHz_rounded_word}'
Would it be ok to have your credentials as I would need to list them for my bibliography.
Thank you,
Michael
[Administrator note: post edited to remove personally identifying information.]
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
Hello back with another question. I really do appreciate all your help.
I'm building the circuit and how do you connect the 12v DC cable extension with some wires?.
Thanks,
Michael
I'm building the circuit and how do you connect the 12v DC cable extension with some wires?.
Thanks,
Michael
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Hi,
1. If you haven't already, see my previous reply above about calculating the ultrasonic pulse frequency as opposed to the modulation frequency.
2. Did you buy the materials linked in the project? There is a plug adapter that you can use to connect your power supply to two jumper wires with the screw terminals. You can then plug the jumper wires into the breadboard. This assumes your power supply has a "5.5mm x 2.1mm" plug which is a common size (and matches the 18V supply we link in the materials list). If you bought a different size plug you will need a different adapter: https://www.amazon.com/QLXHBOT-Connecto ... ebuddie-20
3. My full name and job title are Ben Finio, PhD, Lead Staff Scientist at Science Buddies
1. If you haven't already, see my previous reply above about calculating the ultrasonic pulse frequency as opposed to the modulation frequency.
2. Did you buy the materials linked in the project? There is a plug adapter that you can use to connect your power supply to two jumper wires with the screw terminals. You can then plug the jumper wires into the breadboard. This assumes your power supply has a "5.5mm x 2.1mm" plug which is a common size (and matches the 18V supply we link in the materials list). If you bought a different size plug you will need a different adapter: https://www.amazon.com/QLXHBOT-Connecto ... ebuddie-20
3. My full name and job title are Ben Finio, PhD, Lead Staff Scientist at Science Buddies
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
Thank you so much I greatly appreciate it. You have such a great help.\
I did buy all the materials linked in the project so i just take my jumper wires and stick them into the cable extension?
I did buy all the materials linked in the project so i just take my jumper wires and stick them into the cable extension?
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Do you mean the barrel jack adapter? If so, you don't just stick the wires directly in, it has what are called "screw terminals." You need to use a small screwdriver to loosen the screws, stick the wires in, then tighten the screws again so they hold the wires in place. You should be able to gently tug on the wires without them coming out.
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
I didn't see the screw
Thank you
Thank you
-
misobower123
- Posts: 14
- Joined: Mon Oct 06, 2025 2:40 pm
- Occupation: Student
Re: Which arduino do I use?
Hello, I have built the circuit following the diagram given on the page and downloaded the code then used that code in Arduino IDE yet I am not feeling any vibration. The arduino is getting power and my other power source is working. Could you please tell me common problems and how to trouble shoot them.
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Hi,
1. Can you clarify whether you purchased the Science Buddies kit (Arduino UNO R4) or if you have your own UNO R3?
2. Can you post clear, well-lit, in-focus pictures of your circuit, using the "attachments" feature below? That will help us check your wiring - otherwise it's hard for us to tell what might be wrong without seeing your circuit. Many times problems like this are due to a single misplaced jumper wire on the breadboard somewhere.
Thanks,
Ben
1. Can you clarify whether you purchased the Science Buddies kit (Arduino UNO R4) or if you have your own UNO R3?
2. Can you post clear, well-lit, in-focus pictures of your circuit, using the "attachments" feature below? That will help us check your wiring - otherwise it's hard for us to tell what might be wrong without seeing your circuit. Many times problems like this are due to a single misplaced jumper wire on the breadboard somewhere.
Thanks,
Ben
-
bfinio
- Expert
- Posts: 964
- Joined: Mon Aug 12, 2013 2:41 pm
- Occupation: Lead Staff Scientist, Science Buddies
- Project Question: Expert
- Project Due Date: n/a
- Project Status: Not applicable
Re: Which arduino do I use?
Conversation continued in this thread: viewtopic.php?t=25104

