Ultrasonic Sensor with the Raspberry Pi
Вставка
- Опубліковано 24 лип 2013
- This video outlines both how the ultrasonic sensor works, and how to control one using the Raspberry Pi.
Check out Matt Hawkins' Raspberry Pi Spy website at:
www.raspberrypi-spy.co.uk
Learn more about programming, electronics, and the Raspberry Pi at:
cutequbit.zapto.org
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.
Really thanks!!! I have read a lot of tutorials and no one has worked well as your!
Congratulations, your explanations are some of the best that I've ever heard. Even for a non English person.
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!
very good!! lot better than other videos!
simply explained.. the best video about the subject! great work!!!
Thank you for the clear and insightful video!
Perfectly explained! Thank you very much for a great and helpful video :)
Excellent tutorial. I can't wait to try it out with my Parallax PING sensor!
Well commented and explained how to use and calculate distance in an easy to understand way. Thank you keep the videos coming please.
it's amazing after all these years how great the production value and content is. Great work...anything new coming?
Awesome demonstration, Thanks!
Best video on this ive seen. Your videos are great!
Awesome tutorial, love you video's.
Fantastic tutorials!
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.
wow, very well explained, thank you so much for the video
I did it! Great tutorial, very well explained. :)
thanks a lot, you must be a teacher, everything clear.
Another excellent video :)
Excelent video, helps alot!
Great tutorial.
Amazing video!
Excellent video. Do you know if the new sensor SM351LT would allow the same and if the design would vary much?
thank you for clear explination
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?
Great video bro
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's very good work
Thank you! This will be helpful for my talking robot
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, it worked.
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
you are genius! thanks
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.
Hi, I'm pulling my hair out, I want to get the ultrasonic sensor to trigger sound files depending on distance? Any thoughts?
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 man it worked :)
hi, which gropePi sensor should I use to meter the level of a tank of water? tahnks
I would like to make this an Internet of Things (IoT) project. I'm not well versed on IoT so any suggestions or tips ?
hello :) is it possible for the ultrasonic sensor to detect audible sounds?
Man, I cannot wait to get my RPI3 and developers kit. Gonna have fun developing this stuff!
Isn't V.out the voltage over R2
Sir could you explain how to interface PH sensor with raspberry pi.
what happens if you don't use the voltage divider and have 5V go to the gpio input pin?
hello, my ultrasonic sensor is Ks103, will it work the same way as this one?
How do you incorporate this with a 9volt and a housing on it?
Can i add 2 more sensor in the same raspberry? volts/amps problems?
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
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.
Thanks a lot...Thanks a lot...
Thanks a lot for your tutorial but please remember, you do not use voltage divider rule for parallel resistors! only for series resistors.
thanks a lot man :D
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'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?
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
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?
why my sensor output always return value 6 cm ?
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
Awesome
how much it costs?
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
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.
I don't understand why R2 is needed (2:18). What would happen if R2 were not used?
can i run the code with python idle?
yep, and you can run gpio in python3 as well.
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 .
for me it stops on starting measuring.... :(
any ideas ?
please share the above code
Please share the code with us
How to make realtime ultrasonic read?
use a while loop . if you know python basics you will be able to do it
I had connected one but how can I make them 3 ?
bc there is just two 5V pin in raspberry pi
How can I make the measurement repetitive?
It has
You guessed right, I'm a high school Physics teacher.
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