Wow! What an excellent presentation! I especially appreciate your working from the basics--e.g. showing the math for each part of the project. (How to convert echo time to distance...how to determine the proper resistor value for the voltage divider.) This is not a cookbook, but a very clear explication of the underlying principles, so one can modify the project with some degree of confidence. Bravo!
Hi Gavin, great tutorial. I noticed that the readings were very up and down. I changed your time.sleep(.1) to time.sleep(.5). This gave me more consistent results.
Nice video, You seem to cover the whole concept of unidirectional sonar quite efficiently. I've got some improvements to the code part however: In order to get the time of the falling edge (on the echo gpio pin), you use a software based waiting loop which have 2 major drawbacks: - Without multithreading/multiprocessing, the program goes in some sort of "lock" (the infinite pass loop) while waiting that falling edge. - The mesurement precision is totally based on the tick/clock speed allocated by the OS to the program which is often varying and totally unpredictable. So, my point is, why not use the wait_for_edge function of the GPIO library which is either an hardware-based signal detection or a low-level software one (I don't really know which one to be honest). Given that this function is meant to be used with a assync callback, this would easily eliminate our first drawback. For the second onf, if this function is based on some hw signal detection, it would be totally eliminated, if however it is based on some low-level software, it would still be present but with a much higher degree of precision anyway! This isn't a criticism of your solution (which is real good as for educational purpose btw), just another approach to the same software problem.
Nice and helpful video. I have a question: I bought the HC-SR05 today, to only play and ultrasonic signal (no detection wanted), for a specific time (1 sec). Since I do not want to measure any distances, shouldn't it be fine if I only connect Vcc, Trigger and GND (without Echo) directly to my Raspberry Pi 3 B+, without any restistors?
very interesting video . bravo . i have another kind of ultrasonic sensors . the mb1202 . and i need to do measure of distance but with C langage . is this programme for any kind of ultrasonic sensors ??
Hi im interested in start working with this sensors, i wonder what happens if you put the sensor on a servo or a rotational platform so it would rotate 180 degrees, what kind of data would it give? have you tried this? thanks, awesome videos
I also initially tried to use an edge detect event but failed to get it working. After some frustration, I found that the time delay involved with an edge detect in Python was too great and my program was missing the signal from the sensor. You might have more success using an edge detect in C as Python is known to do poorly with timing.
Hi, Great video. i am working on a system which includes ultrasonic distance measurement + voice warnings + camera. is it possible to configure these three in one raspberry pi board ? thank you. big help.
could I use the ultrasonic sensor be used to know when a container is getting low? I am looking for something that I can check to see if a solid (such as uncooked corn) is a quarter full.
I have so many great ideas with inventing thing's. Its just I'm not the greatest at math. Its so frustrating. Any way I can learn because I really enjoy this!
Try the "Khan Academy". The presentations in Khan Academy will explain the math. Here is a URL to get started: www.khanacademy.org/science/electrical-engineering .
I'm using a us-100 My question: I tried it with a similar Programm: (one difference: GPIO mode is on BCM) and it does not work. The sensor isn't returning any signal... But also my Raspberry pi collects a signal, if i touch the connection wire of the Echo Why does that happen?
Beto CH yes. you would connect each sensor to a different gpio pin (and of course, each sensor to a 5v and ground). on the pi, you can: sudo gpio readall; to see which pins are gpio pins, and then you can add these to your script. Note that the GPIO number, and pin numbers are different. Example: pin 3 is gpio 2, and pin 5 is gpio 3 on the raspberry pi zero.
@@averial9831 I looked the GPIO numbers and actions on internet it says there is just 2 5V pin. But I saw in UA-cam some people connect 3 or 6 sensors ?
@@cagdastuna5505 that is correct. You could use multiple sensors on a single 5v pin, however you want to make sure that you are not drawing TOO much power directly from the raspberry pi. You should be ok to do that, but there is a limit of how many amps you can draw from the raspberry pi safely. An easy way to connect 3+ sensors would be to use a breadboard. Good luck 🙂 and have fun.
if we use three 10k ohm, than parrarel the 10k that connected to echo with 2of 10k series to the ground,... is it okay to have 3.333.. V to the echo pin? if it only recieve 3.3V it said
what is the parameter for measurement of pulse duration i.e. 10us(0.00001 sec). I mean,how did you calculate that one should have to trigger it for 10 microsec.
I have the same problem and have the code GPIO.output(TRIG, 1) time.sleep(0.00001) GPIO.output(TRIG, 0) after starting measurment. When i force it a signal by placing echo wire on 3.3 V rail he code works. Does the range finder have a ligth that shows when it is one? I feel like the range find isnt sending out a signal.
Hi Thank for the tutorial. I seem to be able to get my code to work ok but when I run it I get this error message afterwards: measuring... 0.18249154090881348 Traceback (most recent call last): File "/home/pi/Desktop/PythonCodesThatWork/ultrasonic/ultrasonicBasicv2.py", line 30, in print(stop - start) * 17000 TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' >>> Could you advise please? Thanks
Hey, I used GPIO.wait_for_edge(ECHO,GPIO.RISING) to trigger time.time(), instead of using the "while" loop like you have, but it dosent seem to be working... Any idea y? Everything else seems ok.
Awesome! Just purchased a one from www.icstation.com/arduino-ultrasonic-module-sr04-distance-transducer-sensor-p-1389.htm. And I'll use it with RPi later.
Wow! What an excellent presentation!
I especially appreciate your working from the basics--e.g. showing the math for each part of the project. (How to convert echo time to distance...how to determine the proper resistor value for the voltage divider.)
This is not a cookbook, but a very clear explication of the underlying principles, so one can modify the project with some degree of confidence.
Bravo!
Hi Gavin, great tutorial. I noticed that the readings were very up and down. I changed your time.sleep(.1) to time.sleep(.5). This gave me more consistent results.
it's amazing after all these years how great the production value and content is. Great work...anything new coming?
Congratulations, your explanations are some of the best that I've ever heard. Even for a non English person.
Really thanks!!! I have read a lot of tutorials and no one has worked well as your!
Nice video,
You seem to cover the whole concept of unidirectional sonar quite efficiently.
I've got some improvements to the code part however:
In order to get the time of the falling edge (on the echo gpio pin), you use a software based waiting loop which have 2 major drawbacks:
- Without multithreading/multiprocessing, the program goes in some sort of "lock" (the infinite pass loop) while waiting that falling edge.
- The mesurement precision is totally based on the tick/clock speed allocated by the OS to the program which is often varying and totally unpredictable.
So, my point is, why not use the wait_for_edge function of the GPIO library which is either an hardware-based signal detection or a low-level software one (I don't really know which one to be honest).
Given that this function is meant to be used with a assync callback, this would easily eliminate our first drawback.
For the second onf, if this function is based on some hw signal detection, it would be totally eliminated, if however it is based on some low-level software, it would still be present but with a much higher degree of precision anyway!
This isn't a criticism of your solution (which is real good as for educational purpose btw), just another approach to the same software problem.
Well commented and explained how to use and calculate distance in an easy to understand way. Thank you keep the videos coming please.
simply explained.. the best video about the subject! great work!!!
very good!! lot better than other videos!
You guessed right, I'm a high school Physics teacher.
Best video on this ive seen. Your videos are great!
Excellent video. Do you know if the new sensor SM351LT would allow the same and if the design would vary much?
Nice and helpful video. I have a question: I bought the HC-SR05 today, to only play and ultrasonic signal (no detection wanted), for a specific time (1 sec). Since I do not want to measure any distances, shouldn't it be fine if I only connect Vcc, Trigger and GND (without Echo) directly to my Raspberry Pi 3 B+, without any restistors?
Excellent tutorial. I can't wait to try it out with my Parallax PING sensor!
very interesting video . bravo . i have another kind of ultrasonic sensors . the mb1202 . and i need to do measure of distance but with C langage . is this programme for any kind of ultrasonic sensors ??
Thank you for the clear and insightful video!
hi, which gropePi sensor should I use to meter the level of a tank of water? tahnks
Perfectly explained! Thank you very much for a great and helpful video :)
Amazing video!
Hi im interested in start working with this sensors, i wonder what happens if you put the sensor on a servo or a rotational platform so it would rotate 180 degrees, what kind of data would it give? have you tried this? thanks, awesome videos
Great video bro
Hi, I'm pulling my hair out, I want to get the ultrasonic sensor to trigger sound files depending on distance? Any thoughts?
I also initially tried to use an edge detect event but failed to get it working. After some frustration, I found that the time delay involved with an edge detect in Python was too great and my program was missing the signal from the sensor. You might have more success using an edge detect in C as Python is known to do poorly with timing.
thanks a lot, you must be a teacher, everything clear.
Awesome demonstration, Thanks!
Fantastic tutorials!
Hi, Great video. i am working on a system which includes ultrasonic distance measurement + voice warnings + camera. is it possible to configure these three in one raspberry pi board ? thank you. big help.
Thanks a lot for your tutorial but please remember, you do not use voltage divider rule for parallel resistors! only for series resistors.
Great tutorial.
wow, very well explained, thank you so much for the video
I did it! Great tutorial, very well explained. :)
could I use the ultrasonic sensor be used to know when a container is getting low? I am looking for something that I can check to see if a solid (such as uncooked corn) is a quarter full.
Isn't V.out the voltage over R2
Man, I cannot wait to get my RPI3 and developers kit. Gonna have fun developing this stuff!
Awesome tutorial, love you video's.
Can i add 2 more sensor in the same raspberry? volts/amps problems?
Excelent video, helps alot!
I would like to make this an Internet of Things (IoT) project. I'm not well versed on IoT so any suggestions or tips ?
thank you for clear explination
hello :) is it possible for the ultrasonic sensor to detect audible sounds?
Another excellent video :)
Thank you! This will be helpful for my talking robot
I have so many great ideas with inventing thing's. Its just I'm not the greatest at math. Its so frustrating. Any way I can learn because I really enjoy this!
Try the "Khan Academy". The presentations in Khan Academy will explain the math. Here is a URL to get started: www.khanacademy.org/science/electrical-engineering .
Sir could you explain how to interface PH sensor with raspberry pi.
I'm using a us-100
My question:
I tried it with a similar Programm: (one difference: GPIO mode is on BCM)
and it does not work. The sensor isn't returning any signal...
But also my Raspberry pi collects a signal, if i touch the connection wire of the Echo
Why does that happen?
udates?
is it possible to use multiple ultrasonic sensors in the raspberry?
Beto CH yes. you would connect each sensor to a different gpio pin (and of course, each sensor to a 5v and ground). on the pi, you can: sudo gpio readall; to see which pins are gpio pins, and then you can add these to your script. Note that the GPIO number, and pin numbers are different. Example: pin 3 is gpio 2, and pin 5 is gpio 3 on the raspberry pi zero.
@@averial9831 I looked the GPIO numbers and actions on internet it says there is just 2 5V pin. But I saw in UA-cam some people connect 3 or 6 sensors ?
@@cagdastuna5505 that is correct. You could use multiple sensors on a single 5v pin, however you want to make sure that you are not drawing TOO much power directly from the raspberry pi. You should be ok to do that, but there is a limit of how many amps you can draw from the raspberry pi safely. An easy way to connect 3+ sensors would be to use a breadboard. Good luck 🙂 and have fun.
if we use three 10k ohm, than parrarel the 10k that connected to echo with 2of 10k series to the ground,... is it okay to have 3.333.. V to the echo pin? if it only recieve 3.3V it said
what is the parameter for measurement of pulse duration i.e. 10us(0.00001 sec). I mean,how did you calculate that one should have to trigger it for 10 microsec.
thank's very good work
you are genius! thanks
how much it costs?
Thanks a lot, it worked.
thanks a lot man :D
How do you incorporate this with a 9volt and a housing on it?
my code just hangs after the "Starting Measurement" routine. It gets into the while GPIO.input(ECHO) == 0: and never leaves
any ideas?
same problem here. help
same here
Add after print "Starting Measurement"
GPIO.output(TRIG, 1)
time.sleep(0.00001)
GPIO.output(TRIG, 0)
I have the same problem and have the code
GPIO.output(TRIG, 1)
time.sleep(0.00001)
GPIO.output(TRIG, 0)
after starting measurment.
When i force it a signal by placing echo wire on 3.3 V rail he code works.
Does the range finder have a ligth that shows when it is one?
I feel like the range find isnt sending out a signal.
Same
I don't understand why R2 is needed (2:18). What would happen if R2 were not used?
what happens if you don't use the voltage divider and have 5V go to the gpio input pin?
Thanks man it worked :)
Awesome
Hi Thank for the tutorial. I seem to be able to get my code to work ok but when I run it I get this error message afterwards:
measuring...
0.18249154090881348
Traceback (most recent call last):
File "/home/pi/Desktop/PythonCodesThatWork/ultrasonic/ultrasonicBasicv2.py", line 30, in
print(stop - start) * 17000
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
>>>
Could you advise please? Thanks
can i run the code with python idle?
yep, and you can run gpio in python3 as well.
Thanks a lot...Thanks a lot...
Hey, I used GPIO.wait_for_edge(ECHO,GPIO.RISING) to trigger time.time(), instead of using the "while" loop like you have, but it dosent seem to be working... Any idea y?
Everything else seems ok.
Why can't I just use the 3.3V PIN from the Raspberry Pi instead of 5V ? In that case I won't need the voltage divider
how make increase at ulturasonic sensor distance
please share the above code
Please share the code with us
I'm not getting a continuous output. I need to keep pressing Run on the code in order to get a single reading. Anyone knows how to fix this?
I had connected one but how can I make them 3 ?
bc there is just two 5V pin in raspberry pi
for me it stops on starting measuring.... :(
any ideas ?
why my sensor output always return value 6 cm ?
How can I make the measurement repetitive?
How to make realtime ultrasonic read?
use a while loop . if you know python basics you will be able to do it
It has
Awesome! Just purchased a one from www.icstation.com/arduino-ultrasonic-module-sr04-distance-transducer-sensor-p-1389.htm. And I'll use it with RPi later.
how come everyone else uses a 1k ohm and 2k ohm resistor?
nano... Unix...
nice but programming in C would be much better, Python isn't efficient enough
hello, my ultrasonic sensor is Ks103, will it work the same way as this one?