Another great lesson. I liked this one as an introduction to your other ultrasonic sensor lesson. I will pass this on to my students when we start working with them. Thanks again for including the dimensional analysis Paul!
Another great lesson Mr. Mcwhorter, thank you. I had lots of fun with this because I've never done this experiment. I'm going to be sad when I run outta lessons lol.
You can also use the same sensor to calculate the distance within 3 cm. This would allow you to do everything automatically with no need to manually measure. The Formula is pingTime/58 to get cm. Then convert to inches (pingTime*0.3937) for the targetDistance variable. I know the video is 4+ years old but thanks for taking the time to do these. They are great!
never thought I'd get into writing or understanding codes at 30 old. You good sir have helped spark some major interest in things i never considered a couple months ago!
With my Swiss cheese brain due to the amount of pain meds that I've been on for 20 years, things don't come easy to me. You still manage to make it seem easy. Thank you, Paul! I hope this stays formatted correctly. Here's my homework. // Libraries:- // Defines:- // Pin allocations:- // Constants:- // Global variables:- int trigPin = 13; //Sensor TRIG pin to Ard 13 int echoPin = 11; //Sensor ECHO pin to Ard 11 float pingTime; //Time for ping to hit target and return float speedOfSound; //Calculate SOS float targetDistanceMin = 4; //Minimum istance to target - 600ms = 4" = 150ms/inch float targetDistanceMax = 8; //Maximum istance to target - 1200ms = 8" = 150ms/inch float targetDistance; // Class objects:- void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(trigPin, OUTPUT); //Set TrigPin as output pinMode(echoPin, INPUT); //Set EchoPin as input } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin, LOW); //Set TrigPin LOW delayMicroseconds(2000); //Pause to let sig settle digitalWrite(trigPin, HIGH); //Set trigPin HIGH delayMicroseconds(10); //Pause trigPin HIGH digitalWrite(trigPin, LOW); //Set TrigPin LOW pingTime = pulseIn(echoPin, HIGH); //Measure ping travel time in microseconds targetDistance=pingTime/150; //Target distance in inches is ping time / 150ms Serial.print(targetDistance); //Print target distance in inches Serial.print("\" is "); //So far, so good! if(targetDistancetargetDistanceMin){ Serial.println("within target range." ); }else{ Serial.println("out of target range!"); } delay(2000); }
I modified your code so the speed of sound were in meters per second, I got to changed TrigPin from Int to Float so I could use 0.20 meters as my target distance. Thank you very much Mr. Paul McWhorter !
Thanks for another enjoyable lesson, Hurricane Dorian had left me without internet in Nova Scotia for a few days so I had to revert to Elegoo's lessons on cd. It was kind of boring as I just inserted a file from the library and ultrasonic sensor worked with no explanation, just like magic. Your video certainly gives us many more possibilities for the sensor, even to measure golf club speed...
Another great lesson! When looking at the setup I see quite a few variables, eg. Angle of the post-it's, lead sheet is slightly separated, and where on the sensor you choose to begin measuring (front, back or center). All in all I'd say ~1% +/- is dead on.
Awesome, I got one of these sensors too so I can do this one. I thought these were speakers when I got it in the mail cuz I just ordered a bunch of parts about a year ago that my friend who is into Arduino said I might wanna play with and just barely started finally learning Arduino about a week ago. Thanks again for the cool lessons - peace.
I am a 63 year old airline pilot with a BS in Aero Eng. Technology. I am looking forward to applying this to my ham radio hobby. My question for Mr. McWhorter is; will the resulting speed of sound that is measured be affected by the density of the object the ping is striking? I will experiment with a pad of post-it-notes and then a piece of ceramic tile and find out.
Paul, according to data sheet of HC-SR05 "DETECTION DISTANCE: 2 cm to 450 cm". It is not inches. Because of it inches needs to transfer cm to get speed close enough to real. As 6 inch is 15.24 cm. It means it needs statement. Usually sound of speed is M (meter) per second (Second). Miles per hours are not practical and confusion as we talked about speed of sound
Little confused on the pulseIn function. As per the definition on their website "if value is HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing". We already gave the duration of pulse to be 10 microseconds so isnt it measuring this again instead of the time it takes between trigger and echo?
I have a great question for you, how would you calculate the speed of light with a LIDAR sensor? What would you make the targetDistance variable to be? Leaving all of your variables as is, while using 58924.8 as my targetDistance I get the 669,600,000 miles per hour output. It took a bit of guessing but I got it. I did change the variable name to speedOfLight and such. Incidentally I am doing this on an ESP8266 using the MakerFocus Lidar device. If I Serial.print the pingTime, I get 10. Your thoughts?
Do you measure the distance from the very base of the sensor board (the innermost part of it) or the outer tip of it (the physical outter part). There seems to be a few centimeters but maybe it matters. Thanks, you make this look simple and enjoyable.
Many thanks for your tutorials they are just awesome. I see on the video that you set the delay in microseconds. This made me think of something in general for other projects, as I wondered if you could change the unit of delay to seconds, minutes or hours? I know I could calculate everything in milliseconds, but if you want delays for hours you end up with massive numbers. For this it would be much better to be able to change the unit of delay to say minutes or hours. Is this possible?
Hi again Mr.McWhorter, I'm having a hard time with when it's proper to use a space before or after keywords, I see "int trigPin=13;" and "int trigPin= 13; So this spacing will not effect code operation, I just need a little guidance.
Hey Paul! that was a good lesson, I enjoyed it. say, can you help me out with a doubt i have? when you taught the colour sensor, you used unsigned int for the pulseIn command and now you are using float. do the two data types provide simmilar ranges? 0-102400 i think?? thanks!
So how do I hook up LED lights and two DC motors a fan motor and then hook it all together with the Bluetooth so I can run it on PlayStation controller
I need help i want t make it portable so have a battery and and led to it my idea was you start your stop watch when the led turns on then stop it when it turns off now i don't really know how its going to work please answer tomorrow this is due
Sir, I'm getting speed of sound as infinite in My serial monitor, I also tried calculating distance & time, both are coming zero, I thought time is very less so I converted it into nanoseconds still I'm getting zero.
can you please give more discription about pulseIn command. in previous lesson low pulse has messured colour strength which will be 0-102400 which will be converted to 0-255 i.e., backward 255-0 but here high pulse to get time in pulseIn we write HIGH or LOW is this for "forward and backword" or "high pulse pwm and low pulse pwm"
Pulsein HIGH . . . the signal is normally low, and you measure how long it goes high. Pulesin LOW . . . the signal is normally high, and you measure how long it goes low. Depends on how the sensor behaves which command you use.
thank you for the lessons, is there any chance of making lessons on microcontroller communication protocols like CAN, I2C, UART, SPI ..... i think they are intresting
Hello I have the accent same code and my serial monitor reads the speed is 'inf' could you please explain what this means because i tried but i can't figure it out on my own.
inf probably means you are dividing by zero. Before you do the calculation, print each variable that is in the calculation and make sure it has a reasonable value. Then if you have a variable that is 0 in the denominator, then find the mistake that led that variable to be zero. Use lots of print statements and figure it out.
Im using the metric system, so im measuring in cm per microsseconds, to convert it to km/h i multiplied the speedOfSound by 36000, but i get “inf” as a final result. Any might know what is wrong with what i did? Thnks
No, pulse width is TIME! How long does one pulse last. Frequency is pulses per second, which is the inverse of period. Pulsewidth is simply how long one pulse lasts.
inf means infinity which means you are probably dividing by zero. Print out each variable you use in your calculation equation in your program, and probably one is zero, then find out why it is zero.
Paul McWhorter thank you for your response, let me find that zero value in my variables. I'll get back to u for feedback soon. Asante sana (thank you very much)
im back, the person who does not like your face. well you educated me! i spent an enormous amount of time trying to figure out the library needed to make the sensor work. BUT YOU EXPLAINED HOW IT DID. so now i dont need the library and i understand what it does, and how it does it. DONT GET IN THE HELICOPTER! their dangerous. most people die in "twins," but helicopters are second cause of death at the airports.
im trying to make an led fed but i only turn it on in off thats the code i put in int trigPin=13; //sensor trig pin is connected to arduino13 int echoPin=11; //sensor echo pin is connected to arduino11 float pingTime; //time for ping to hit target and return float speedOfSound; //we will calculate the speed of sound float targetDistance=8; int LED=6; int writeValue void setup() { Serial.begin(9600); // turn on sserial port pinMode(trigPin,OUTPUT); //set trig pin as an output pinMode(echoPin,INPUT); // set echo pin as an input pinMode(LED,OUTPUT); } void loop() { digitalWrite(trigPin, LOW); // SET triger pin low delayMicroseconds(2000); // pause to let signal settle digitalWrite(trigPin,HIGH); // take trig pin high delayMicroseconds(10); // pause with triger pin High digitalWrite(trigPin,LOW); //finish trigger pulse by bringing it low digitalWrite(LED,speedOfSound); pingTime= pulseIn(echoPin,HIGH); //measure ping travel time in microsecond speedOfSound= 2*targetDistance/pingTime; // gives us speed in inches per microsecond speedOfSound= speedOfSound/63360*1000000*3600; // gives us speed of sound in miles per hours Serial.print("speed of sound is: "); Serial.print(speedOfSound); Serial.println(" miles per hour."); delay(3000); }
Paul McWhorter you dont have to answer this one i figure it out instead of this digitalWrite(LED,speedOfSound); i put this if(pingTime/2*targetDistance){ analogWrite(LED,speedOfSound); }
Things were great until now. I keep getting 0 as a return when it divides (targetDistance*2)/pingTime. I started a new sketch and used the text code verbatim. Still getting 0. It's doing integer math on floats. I even tried changing from UNO to Micro to Nano. Nothing works. Broke it down serial.print and debug line by line. ping =11000. (Distance*2)= 12. Divide them and return is zero zero zero zero zero zero zero. Add some decimals? no difference. Define as float in global? no difference. Typecast as float during the operation? nope. 0. 0. 0. 0. 0. 0. 0.
Created another variable of 1/ping and multiplied that by the other. No division = problem solved. Still don't know why that happened. But I learned that sound moves at 1cm in 29ms and one of my sensor was garbage(ping =11,000 @6")...
maybe you would have figured as of now, nevertheless if it helps, try putting decimal values to all your ints as floating variables still return int, in your case 0
Another great lesson. I liked this one as an introduction to your other ultrasonic sensor lesson. I will pass this on to my students when we start working with them. Thanks again for including the dimensional analysis Paul!
Another great lesson Mr. Mcwhorter, thank you. I had lots of fun with this because I've never done this experiment. I'm going to be sad when I run outta lessons lol.
You can also use the same sensor to calculate the distance within 3 cm. This would allow you to do everything automatically with no need to manually measure. The Formula is pingTime/58 to get cm. Then convert to inches (pingTime*0.3937) for the targetDistance variable. I know the video is 4+ years old but thanks for taking the time to do these. They are great!
never thought I'd get into writing or understanding codes at 30 old. You good sir have helped spark some major interest in things i never considered a couple months ago!
i rarely comment on video in youtube but Sir, you are an exception. Thank you so much for the detail and all. may god bless Sir.
Thank you and may God bless you
With my Swiss cheese brain due to the amount of pain meds that I've been on for 20 years, things don't come easy to me. You still manage to make it seem easy. Thank you, Paul!
I hope this stays formatted correctly. Here's my homework.
// Libraries:-
// Defines:-
// Pin allocations:-
// Constants:-
// Global variables:-
int trigPin = 13; //Sensor TRIG pin to Ard 13
int echoPin = 11; //Sensor ECHO pin to Ard 11
float pingTime; //Time for ping to hit target and return
float speedOfSound; //Calculate SOS
float targetDistanceMin = 4; //Minimum istance to target - 600ms = 4" = 150ms/inch
float targetDistanceMax = 8; //Maximum istance to target - 1200ms = 8" = 150ms/inch
float targetDistance;
// Class objects:-
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT); //Set TrigPin as output
pinMode(echoPin, INPUT); //Set EchoPin as input
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW); //Set TrigPin LOW
delayMicroseconds(2000); //Pause to let sig settle
digitalWrite(trigPin, HIGH); //Set trigPin HIGH
delayMicroseconds(10); //Pause trigPin HIGH
digitalWrite(trigPin, LOW); //Set TrigPin LOW
pingTime = pulseIn(echoPin, HIGH); //Measure ping travel time in microseconds
targetDistance=pingTime/150; //Target distance in inches is ping time / 150ms
Serial.print(targetDistance); //Print target distance in inches
Serial.print("\" is ");
//So far, so good!
if(targetDistancetargetDistanceMin){
Serial.println("within target range." );
}else{
Serial.println("out of target range!");
}
delay(2000);
}
I modified your code so the speed of sound were in meters per second, I got to changed TrigPin from Int to Float so I could use 0.20 meters as my target distance. Thank you very much Mr. Paul McWhorter !
You are a Great teacher. You lessons are organised nicely.
Thanx
Thanks for another enjoyable lesson, Hurricane Dorian had left me without internet in Nova Scotia for a few days so I had to revert to Elegoo's lessons on cd. It was kind of boring as I just inserted a file from the library and ultrasonic sensor worked with no explanation, just like magic. Your video certainly gives us many more possibilities for the sensor, even to measure golf club speed...
Another great lesson! When looking at the setup I see quite a few variables, eg. Angle of the post-it's, lead sheet is slightly separated, and where on the sensor you choose to begin measuring (front, back or center). All in all I'd say ~1% +/- is dead on.
Although I'm not a beginner I very much enjoy your lessons.
By the way, humidity also affect the speed of sound.
Awesome, I got one of these sensors too so I can do this one. I thought these were speakers when I got it in the mail cuz I just ordered a bunch of parts about a year ago that my friend who is into Arduino said I might wanna play with and just barely started finally learning Arduino about a week ago. Thanks again for the cool lessons - peace.
I am a 63 year old airline pilot with a BS in Aero Eng. Technology. I am looking forward to applying this to my ham radio hobby. My question for Mr. McWhorter is; will the resulting speed of sound that is measured be affected by the density of the object the ping is striking? I will experiment with a pad of post-it-notes and then a piece of ceramic tile and find out.
Please make a updated version of this
Thankyou
I have measured the speed of sound and got the speed of sound as 333.67 m/s (mks) on average with a 2.7% error, I am now very happy!
Hey paul!
thanks for this tutorial . I got 1201 Km per hour , not even close ! but very helpful video .
No, you're actually right! 1201 km/h is equal to 333.6m/s!!
you got to love the metric system
sir can u properly explain the function of pulsein
Paul, according to data sheet of HC-SR05 "DETECTION DISTANCE: 2 cm to 450 cm". It is not inches. Because of it inches needs to transfer cm to get speed close enough to real. As 6 inch is 15.24 cm. It means it needs statement. Usually sound of speed is M (meter) per second (Second). Miles per hours are not practical and confusion as we talked about speed of sound
Good video Paul it was good and also I don't know how to use an Ultrasonic senser but know I to thanks good video.
Little confused on the pulseIn function. As per the definition on their website "if value is HIGH, pulseIn() waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing". We already gave the duration of pulse to be 10 microseconds so isnt it measuring this again instead of the time it takes between trigger and echo?
You're the man Paul!
I have a great question for you, how would you calculate the speed of light with a LIDAR sensor? What would you make the targetDistance variable to be? Leaving all of your variables as is, while using 58924.8 as my targetDistance I get the 669,600,000 miles per hour output. It took a bit of guessing but I got it. I did change the variable name to speedOfLight and such. Incidentally I am doing this on an ESP8266 using the MakerFocus Lidar device. If I Serial.print the pingTime, I get 10. Your thoughts?
I wish you long long life. Thanks for sharing your knowledge.
Do you measure the distance from the very base of the sensor board (the innermost part of it) or the outer tip of it (the physical outter part). There seems to be a few centimeters but maybe it matters.
Thanks, you make this look simple and enjoyable.
I wonder if you had 2 of these if they could be used to pulse Morse code communications to each other.
thanks a lot sir! you are gentle man!
Hi, thanks for the tutorial;
Question: Is there a function of producing a pulse instead of creating it ourselves ?
Great stuff as always
Many thanks for your tutorials they are just awesome. I see on the video that you set the delay in microseconds. This made me think of something in general for other projects, as I wondered if you could change the unit of delay to seconds, minutes or hours? I know I could calculate everything in milliseconds, but if you want delays for hours you end up with massive numbers. For this it would be much better to be able to change the unit of delay to say minutes or hours. Is this possible?
+David Hall You could probably do that if you wrote a custom function to define those functions.
Sir give some video on stepper motor, LCD and menu button
Hi again Mr.McWhorter, I'm having a hard time with when it's proper to use a space before or after keywords,
I see "int trigPin=13;" and "int trigPin= 13; So this spacing will not effect code operation, I just need a little guidance.
A lot of the time it doesn't really matter, it's just up to which way you prefer to do it.
Sir,When you used pulseIn command for the color sensor you used LOW as an argument and here you are using HIGH. any reasons for it?
Hey Paul!
that was a good lesson, I enjoyed it.
say, can you help me out with a doubt i have?
when you taught the colour sensor, you used unsigned int for the pulseIn command and now you are using float. do the two data types provide simmilar ranges? 0-102400 i think??
thanks!
Floats can be very large numbers, but include the inbetween numbers. In math terms, floats are the "Real" numbers
very good - thank you
Hey guys I am just in fifth grade and I have done a lot of it and it is so simple.
Well it sounds like you are a very smart and dedicated young man. Maybe a future engineer!
good mr paul
Could you use that component with a modified sketch to measure speed of an object? (i.e. a speed detector?)
Welcome Doctor
How to create a metal detector, underground spaces and pharaonic tombs using arduino
You are just awesome...
So how do I hook up LED lights and two DC motors a fan motor and then hook it all together with the Bluetooth so I can run it on PlayStation controller
Is this compulsary that we set target distance in units of inches? Can I set distance in centimeters?
Do the trigpin & echopin always set to pin no. 13 & 11 respectively?or i can set to whichever pin no...
I need help i want t make it portable so have a battery and and led to it my idea was you start your stop watch when the led turns on then stop it when it turns off now i don't really know how its going to work please answer tomorrow this is due
How can you measure the speed of an object? I am new at this
Sir, I'm getting speed of sound as infinite in My serial monitor, I also tried calculating distance & time, both are coming zero, I thought time is very less so I converted it into nanoseconds still I'm getting zero.
He sayed if you are doing this in High school you ahead and you are 1 in a 1,000 chance. I am in Elemerty school and I follow along completely
thank you so much
Sir can I use A0 and A1 pins as trigPin and echoPin??
can you please give more discription about pulseIn command. in previous lesson low pulse has messured colour strength which will be 0-102400 which will be converted to 0-255 i.e., backward 255-0 but here high pulse to get time
in pulseIn we write HIGH or LOW is this for "forward and backword" or "high pulse pwm and low pulse pwm"
Pulsein HIGH . . . the signal is normally low, and you measure how long it goes high.
Pulesin LOW . . . the signal is normally high, and you measure how long it goes low.
Depends on how the sensor behaves which command you use.
thank you for the lessons, is there any chance of making lessons on microcontroller communication protocols like CAN, I2C, UART, SPI ..... i think they are intresting
Hello I have the accent same code and my serial monitor reads the speed is 'inf' could you please explain what this means because i tried but i can't figure it out on my own.
inf probably means you are dividing by zero. Before you do the calculation, print each variable that is in the calculation and make sure it has a reasonable value. Then if you have a variable that is 0 in the denominator, then find the mistake that led that variable to be zero. Use lots of print statements and figure it out.
Everything was just perfect. But if Americans could just use the SI system for fu*s sake the world would be a much better place.
Im using the metric system, so im measuring in cm per microsseconds, to convert it to km/h i multiplied the speedOfSound by 36000, but i get “inf” as a final result. Any might know what is wrong with what i did? Thnks
I get the Inf as well,, Did you ever figure out a solution?
@@SteffenABPetersen l
Lol I get the Inf as well,, Did you ever figure out a solution?
what do u exactly mean by pulse width? Is it intensity or frequency?
can u plz explain sir...
pulse width is measured in time. How wide, in time, is the pulse.
so does that means it's the frequency?
No, pulse width is TIME! How long does one pulse last. Frequency is pulses per second, which is the inverse of period. Pulsewidth is simply how long one pulse lasts.
"The Speed of Sound is: inf miles per hour" what does it mean? i'm not getting the value of the speed of sound rather this one, correct me please
inf means infinity which means you are probably dividing by zero. Print out each variable you use in your calculation equation in your program, and probably one is zero, then find out why it is zero.
Paul McWhorter thank you for your response, let me find that zero value in my variables. I'll get back to u for feedback soon. Asante sana (thank you very much)
Yes, I know the meaning of Asante Sana . . . I have been to Africa 7 times and hope to move there soon.
Hello mr Paul .My arduino after the serialprint command prints "nan" ,am i doing something wrong ?
Somewhere you are probably dividing by zero.
Is giving the target distance value necessary
It allows for an easy way to quickly change that value.
im back, the person who does not like your face. well you educated me! i spent an enormous amount of time trying to figure out the library needed to make the sensor work. BUT YOU EXPLAINED HOW IT DID. so now i dont need the library and i understand what it does, and how it does it. DONT GET IN THE HELICOPTER! their dangerous. most people die in "twins," but helicopters are second cause of death at the airports.
im trying to make an led fed but i only turn it on in off thats the code i put in
int trigPin=13; //sensor trig pin is connected to arduino13
int echoPin=11; //sensor echo pin is connected to arduino11
float pingTime; //time for ping to hit target and return
float speedOfSound; //we will calculate the speed of sound
float targetDistance=8;
int LED=6;
int writeValue
void setup() {
Serial.begin(9600); // turn on sserial port
pinMode(trigPin,OUTPUT); //set trig pin as an output
pinMode(echoPin,INPUT); // set echo pin as an input
pinMode(LED,OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW); // SET triger pin low
delayMicroseconds(2000); // pause to let signal settle
digitalWrite(trigPin,HIGH); // take trig pin high
delayMicroseconds(10); // pause with triger pin High
digitalWrite(trigPin,LOW); //finish trigger pulse by bringing it low
digitalWrite(LED,speedOfSound);
pingTime= pulseIn(echoPin,HIGH); //measure ping travel time in microsecond
speedOfSound= 2*targetDistance/pingTime; // gives us speed in inches per microsecond
speedOfSound= speedOfSound/63360*1000000*3600; // gives us speed of sound in miles per hours
Serial.print("speed of sound is: ");
Serial.print(speedOfSound);
Serial.println(" miles per hour.");
delay(3000);
}
Paul McWhorter
you dont have to answer this one i figure it out instead of this digitalWrite(LED,speedOfSound); i put this
if(pingTime/2*targetDistance){
analogWrite(LED,speedOfSound);
}
and this is why we use the metric system...
What am i doing wrong, Im not getting a ping time. Sorry its a lot of code.
int Trig=13;
int Echo=11;
float PingTime;
float SpeedofSound;
float Distance=6;
void setup() {
pinMode(Trig,OUTPUT);
pinMode(Echo,INPUT);
}
void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(3000);
digitalWrite(Trig,HIGH);
delayMicroseconds(10);
digitalWrite(Trig,LOW);
PingTime=pulseIn(Echo,HIGH);
Serial.print("Distance "); Serial.println(Distance);
Serial.print("PingTime "); Serial.println(PingTime);
Serial.println(" ");
Serial.println("SpeedofSound = 2 * Distance / PingTime");
Serial.println(" ");
Serial.print("SpeedofSound = 2 * "); Serial.print(Distance); Serial.print(" / ");Serial.println(PingTime);
SpeedofSound=(2*Distance)/PingTime;
Serial.println(" ");
Serial.print("The speed of sound is ");Serial.println(SpeedofSound);
Serial.println(" ");
Serial.println("SpeedOfSound = SpeedofSound / 63360 * 1000000 * 3600");
Serial.println(" ");
Serial.print("SpeedofSound = "); Serial.print(SpeedofSound); Serial.print(" / 63360 * 1000000 * 3600");
SpeedofSound=SpeedofSound/63360*1000000*3600;
Serial.println(" ");
Serial.print("The speed of sound is "); Serial.print(SpeedofSound); Serial.println(" MPH");
Serial.println(" ");
Serial.println(" ----------------------------------------------------------------------------- ");
delay(3000);
}
open serial port in void setup
in my measurment, i got the answer of infinite instead of some number.
isn't delay already in microseconds?
milliseconds
i keep getting "inf MPH" anybody know what that means?
My sensor wasn't reading because I was careless and sloppy in void setup check there if you're still having trouble.
Things were great until now. I keep getting 0 as a return when it divides (targetDistance*2)/pingTime. I started a new sketch and used the text code verbatim. Still getting 0. It's doing integer math on floats. I even tried changing from UNO to Micro to Nano. Nothing works. Broke it down serial.print and debug line by line. ping =11000. (Distance*2)= 12. Divide them and return is zero zero zero zero zero zero zero. Add some decimals? no difference. Define as float in global? no difference. Typecast as float during the operation? nope. 0. 0. 0. 0. 0. 0. 0.
Created another variable of 1/ping and multiplied that by the other. No division = problem solved. Still don't know why that happened. But I learned that sound moves at 1cm in 29ms and one of my sensor was garbage(ping =11,000 @6")...
maybe you would have figured as of now, nevertheless if it helps, try putting decimal values to all your ints as floating variables still return int, in your case 0
My only issue, and it's entirely personal, is that all your measurements are not scientific ie not metric.