Ultrasonic Sensor with the Raspberry Pi

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.พ. 2025

ความคิดเห็น • 93

  • @KenSkier
    @KenSkier 9 ปีที่แล้ว +2

    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!

  • @Steven-jf4cs
    @Steven-jf4cs 2 ปีที่แล้ว

    it's amazing after all these years how great the production value and content is. Great work...anything new coming?

  • @leoguima94
    @leoguima94 9 ปีที่แล้ว

    Really thanks!!! I have read a lot of tutorials and no one has worked well as your!

  • @ganer77
    @ganer77 11 ปีที่แล้ว

    Congratulations, your explanations are some of the best that I've ever heard. Even for a non English person.

  • @CrispyDose
    @CrispyDose 9 ปีที่แล้ว +3

    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.

  • @axelpaccalin1833
    @axelpaccalin1833 6 ปีที่แล้ว

    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.

  • @rayerdinc2441
    @rayerdinc2441 9 ปีที่แล้ว

    Well commented and explained how to use and calculate distance in an easy to understand way. Thank you keep the videos coming please.

  • @paolorizzi1348
    @paolorizzi1348 8 ปีที่แล้ว

    simply explained.. the best video about the subject! great work!!!

  • @KeyAspect
    @KeyAspect 9 ปีที่แล้ว

    Best video on this ive seen. Your videos are great!

  • @TheCompbureau
    @TheCompbureau 8 ปีที่แล้ว +4

    very good!! lot better than other videos!

  • @seojosep
    @seojosep 10 ปีที่แล้ว

    Excellent video. Do you know if the new sensor SM351LT would allow the same and if the design would vary much?

  • @CirbyWeh
    @CirbyWeh 5 ปีที่แล้ว

    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?

  • @tansoon8257
    @tansoon8257 6 ปีที่แล้ว

    Thank you for the clear and insightful video!

  • @gunzfanatic1859
    @gunzfanatic1859 9 ปีที่แล้ว +1

    hi, which gropePi sensor should I use to meter the level of a tank of water? tahnks

  • @tankiss1991
    @tankiss1991 11 ปีที่แล้ว

    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 ??

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    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.

  • @jefferson1232757
    @jefferson1232757 9 ปีที่แล้ว

    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

  • @siriustoolshobbies229
    @siriustoolshobbies229 2 ปีที่แล้ว

    Can i add 2 more sensor in the same raspberry? volts/amps problems?

  • @Deernest
    @Deernest 3 ปีที่แล้ว

    Amazing video!

  • @GrooveYouVerse
    @GrooveYouVerse 6 ปีที่แล้ว +2

    Man, I cannot wait to get my RPI3 and developers kit. Gonna have fun developing this stuff!

  • @Jozie88
    @Jozie88 8 ปีที่แล้ว +1

    Perfectly explained! Thank you very much for a great and helpful video :)

  • @alexanderd.m.565
    @alexanderd.m.565 2 ปีที่แล้ว

    Great video bro

  • @plasmind1995
    @plasmind1995 6 ปีที่แล้ว +2

    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?

  • @dharshanachandrathilaka8865
    @dharshanachandrathilaka8865 10 ปีที่แล้ว

    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.

  • @rogerbayless
    @rogerbayless 8 ปีที่แล้ว

    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.

  • @hazmzaidan548
    @hazmzaidan548 3 ปีที่แล้ว

    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

  • @deirdrebennett1940
    @deirdrebennett1940 11 ปีที่แล้ว +3

    Hi, I'm pulling my hair out, I want to get the ultrasonic sensor to trigger sound files depending on distance? Any thoughts?

  • @rexyduplex
    @rexyduplex 11 ปีที่แล้ว

    thanks a lot, you must be a teacher, everything clear.

  • @nkoskhonacebolenkosi2653
    @nkoskhonacebolenkosi2653 5 ปีที่แล้ว

    Thanks a lot for your tutorial but please remember, you do not use voltage divider rule for parallel resistors! only for series resistors.

  • @EM8844
    @EM8844 5 ปีที่แล้ว +2

    Isn't V.out the voltage over R2

  • @ErikKringen
    @ErikKringen 9 ปีที่แล้ว

    Awesome demonstration, Thanks!

  • @betoch7556
    @betoch7556 8 ปีที่แล้ว +2

    is it possible to use multiple ultrasonic sensors in the raspberry?

    • @averial9831
      @averial9831 8 ปีที่แล้ว +1

      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.

    • @cagdastuna5505
      @cagdastuna5505 5 ปีที่แล้ว

      @@averial9831 I looked the GPIO numbers and actions on internet it says there is just 2 5V pin. But I saw in TH-cam some people connect 3 or 6 sensors ?

    • @averial9831
      @averial9831 5 ปีที่แล้ว

      @@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.

  • @calvinbarajas5144
    @calvinbarajas5144 6 ปีที่แล้ว

    I don't understand why R2 is needed (2:18). What would happen if R2 were not used?

  • @berkcan3475
    @berkcan3475 8 ปีที่แล้ว

    wow, very well explained, thank you so much for the video

  • @siddharthp1773
    @siddharthp1773 11 ปีที่แล้ว

    Fantastic tutorials!

  • @CrystalDataMusic
    @CrystalDataMusic 5 ปีที่แล้ว

    I did it! Great tutorial, very well explained. :)

  • @himdailungpamei983
    @himdailungpamei983 8 ปีที่แล้ว

    I would like to make this an Internet of Things (IoT) project. I'm not well versed on IoT so any suggestions or tips ?

  • @bsewelliii
    @bsewelliii 9 ปีที่แล้ว +3

    my code just hangs after the "Starting Measurement" routine. It gets into the while GPIO.input(ECHO) == 0: and never leaves
    any ideas?

    • @vivekpatt1021
      @vivekpatt1021 8 ปีที่แล้ว +2

      same problem here. help

    • @PforPianist
      @PforPianist 8 ปีที่แล้ว +2

      same here

    • @raspberry-pi-toys9715
      @raspberry-pi-toys9715 8 ปีที่แล้ว

      Add after print "Starting Measurement"
      GPIO.output(TRIG, 1)
      time.sleep(0.00001)
      GPIO.output(TRIG, 0)

    • @seffdog22
      @seffdog22 8 ปีที่แล้ว

      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.

    • @Mrkevi123
      @Mrkevi123 7 ปีที่แล้ว

      Same

  • @errolsandoval3612
    @errolsandoval3612 8 ปีที่แล้ว

    hello :) is it possible for the ultrasonic sensor to detect audible sounds?

  • @youmayatutorials
    @youmayatutorials 11 ปีที่แล้ว

    Awesome tutorial, love you video's.

  • @Priyamgupta170
    @Priyamgupta170 10 ปีที่แล้ว

    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.

  • @maxwellstrange9450
    @maxwellstrange9450 10 ปีที่แล้ว

    what happens if you don't use the voltage divider and have 5V go to the gpio input pin?

  • @PhillipLearnTeach
    @PhillipLearnTeach 9 ปีที่แล้ว

    How do you incorporate this with a 9volt and a housing on it?

  • @matheusvaz3181
    @matheusvaz3181 5 ปีที่แล้ว

    Excelent video, helps alot!

  • @osiris1309
    @osiris1309 11 ปีที่แล้ว

    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.

  • @amolpitlewad2816
    @amolpitlewad2816 8 ปีที่แล้ว

    Sir could you explain how to interface PH sensor with raspberry pi.

  • @bensmith9253
    @bensmith9253 7 ปีที่แล้ว

    Another excellent video :)

  • @CrispyDose
    @CrispyDose 9 ปีที่แล้ว

    Great tutorial.

  • @tejashwinik5920
    @tejashwinik5920 6 ปีที่แล้ว

    thank you for clear explination

  • @Netflixtr-oo6wb
    @Netflixtr-oo6wb 4 ปีที่แล้ว

    how make increase at ulturasonic sensor distance

  • @existentialchild698
    @existentialchild698 9 ปีที่แล้ว

    Thank you! This will be helpful for my talking robot

  • @crashhhhhhh3068
    @crashhhhhhh3068 2 ปีที่แล้ว

    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?

  • @pwr82
    @pwr82 6 ปีที่แล้ว

    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

  • @cagdastuna5505
    @cagdastuna5505 5 ปีที่แล้ว

    I had connected one but how can I make them 3 ?

    • @cagdastuna5505
      @cagdastuna5505 5 ปีที่แล้ว

      bc there is just two 5V pin in raspberry pi

  • @gaston4004
    @gaston4004 3 ปีที่แล้ว

    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

  • @huskie1561
    @huskie1561 9 ปีที่แล้ว

    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!

    • @richardhpaine
      @richardhpaine 6 ปีที่แล้ว

      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 .

  • @miguelangel-nv5tj
    @miguelangel-nv5tj 11 ปีที่แล้ว +1

    can i run the code with python idle?

    • @AlsoIUseArch
      @AlsoIUseArch 11 ปีที่แล้ว

      yep, and you can run gpio in python3 as well.

  • @wissemmansouri5020
    @wissemmansouri5020 6 ปีที่แล้ว

    thank's very good work

  • @singgiha
    @singgiha 6 ปีที่แล้ว

    how much it costs?

  • @anwarnurfaadhilah1072
    @anwarnurfaadhilah1072 7 ปีที่แล้ว

    How to make realtime ultrasonic read?

    • @valentinballester3196
      @valentinballester3196 7 ปีที่แล้ว

      use a while loop . if you know python basics you will be able to do it

  • @moviesclips1096
    @moviesclips1096 5 ปีที่แล้ว

    Please share the code with us

  • @satyamnayak2576
    @satyamnayak2576 5 ปีที่แล้ว

    please share the above code

  • @adhanjr
    @adhanjr 10 ปีที่แล้ว

    why my sensor output always return value 6 cm ?

  • @asimuzzaman
    @asimuzzaman 7 ปีที่แล้ว

    Thanks a lot, it worked.

  • @shivamsahil3660
    @shivamsahil3660 6 ปีที่แล้ว

    you are genius! thanks

  • @basselsak6111
    @basselsak6111 9 ปีที่แล้ว

    Thanks man it worked :)

  • @paulkrela3376
    @paulkrela3376 10 ปีที่แล้ว

    for me it stops on starting measuring.... :(
    any ideas ?

  • @danielabs5964
    @danielabs5964 5 ปีที่แล้ว

    How can I make the measurement repetitive?

  • @mehrdad-mixtape7970
    @mehrdad-mixtape7970 3 ปีที่แล้ว

    thanks a lot man :D

  • @updowndown
    @updowndown  11 ปีที่แล้ว +4

    You guessed right, I'm a high school Physics teacher.

  • @budcarr8673
    @budcarr8673 6 ปีที่แล้ว

    Awesome

  • @ANMNoor
    @ANMNoor 8 ปีที่แล้ว

    Thanks a lot...Thanks a lot...

  • @existentialchild698
    @existentialchild698 9 ปีที่แล้ว

    It has

  • @LolzerCakes
    @LolzerCakes 7 ปีที่แล้ว

    how come everyone else uses a 1k ohm and 2k ohm resistor?

  • @randydick3602
    @randydick3602 9 ปีที่แล้ว

    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.

  • @novivi4390
    @novivi4390 9 ปีที่แล้ว

    nano... Unix...

  • @jaycool5978
    @jaycool5978 9 ปีที่แล้ว

    nice but programming in C would be much better, Python isn't efficient enough

  • @lowisl289
    @lowisl289 4 ปีที่แล้ว

    hello, my ultrasonic sensor is Ks103, will it work the same way as this one?