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

КОМЕНТАРІ • 94

  • @CrispyDose
    @CrispyDose 8 років тому +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.

  • @leoguima94
    @leoguima94 9 років тому

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

  • @ganer77
    @ganer77 10 років тому

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

  • @KenSkier
    @KenSkier 8 років тому +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!

  • @TheCompbureau
    @TheCompbureau 7 років тому +4

    very good!! lot better than other videos!

  • @paolorizzi1348
    @paolorizzi1348 8 років тому

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

  • @tansoon8257
    @tansoon8257 5 років тому

    Thank you for the clear and insightful video!

  • @Jozie88
    @Jozie88 8 років тому +1

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

  • @RickHenderson
    @RickHenderson 8 років тому

    Excellent tutorial. I can't wait to try it out with my Parallax PING sensor!

  • @rayerdinc2441
    @rayerdinc2441 8 років тому

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

  • @Steven-jf4cs
    @Steven-jf4cs Рік тому

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

  • @ErikKringen
    @ErikKringen 9 років тому

    Awesome demonstration, Thanks!

  • @KeyAspect
    @KeyAspect 8 років тому

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

  • @youmayatutorials
    @youmayatutorials 10 років тому

    Awesome tutorial, love you video's.

  • @siddharthp1773
    @siddharthp1773 10 років тому

    Fantastic tutorials!

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

  • @berkcan3475
    @berkcan3475 8 років тому

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

  • @CrystalDataMusic
    @CrystalDataMusic 5 років тому

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

  • @rexyduplex
    @rexyduplex 10 років тому

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

  • @bensmith9253
    @bensmith9253 7 років тому

    Another excellent video :)

  • @matheusvaz3181
    @matheusvaz3181 5 років тому

    Excelent video, helps alot!

  • @CrispyDose
    @CrispyDose 8 років тому

    Great tutorial.

  • @Deernest
    @Deernest 3 роки тому

    Amazing video!

  • @seojosep
    @seojosep 10 років тому

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

  • @tejashwinik5920
    @tejashwinik5920 5 років тому

    thank you for clear explination

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

  • @alexanderd.m.565
    @alexanderd.m.565 Рік тому

    Great video bro

  • @tankiss1991
    @tankiss1991 10 років тому

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

  • @wissemmansouri5020
    @wissemmansouri5020 6 років тому

    thank's very good work

  • @existentialchild698
    @existentialchild698 8 років тому

    Thank you! This will be helpful for my talking robot

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

  • @asimuzzaman
    @asimuzzaman 7 років тому

    Thanks a lot, it worked.

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

  • @shivamsahil3660
    @shivamsahil3660 6 років тому

    you are genius! thanks

  • @90cat1
    @90cat1 7 років тому

    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.

  • @deirdrebennett1940
    @deirdrebennett1940 10 років тому +3

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

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

  • @basselsak6111
    @basselsak6111 8 років тому

    Thanks man it worked :)

  • @gunzfanatic1859
    @gunzfanatic1859 8 років тому +1

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

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

  • @errolsandoval3612
    @errolsandoval3612 7 років тому

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

  • @GrooveYouVerse
    @GrooveYouVerse 5 років тому +2

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

  • @EM8844
    @EM8844 5 років тому +2

    Isn't V.out the voltage over R2

  • @amolpitlewad2816
    @amolpitlewad2816 8 років тому

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

  • @maxwellstrange9450
    @maxwellstrange9450 9 років тому

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

  • @lowisl289
    @lowisl289 3 роки тому

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

  • @PhillipLearnTeach
    @PhillipLearnTeach 8 років тому

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

  • @siriustoolshobbies229
    @siriustoolshobbies229 2 роки тому

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

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

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

  • @ANMNoor
    @ANMNoor 7 років тому

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

  • @nkoskhonacebolenkosi2653
    @nkoskhonacebolenkosi2653 4 роки тому

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

  • @mehrdad-mixtape7970
    @mehrdad-mixtape7970 3 роки тому

    thanks a lot man :D

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

  • @crashhhhhhh3068
    @crashhhhhhh3068 Рік тому

    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?

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

  • @Netflixtr-oo6wb
    @Netflixtr-oo6wb 3 роки тому

    how make increase at ulturasonic sensor distance

  • @plasmind1995
    @plasmind1995 5 років тому +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?

  • @adhanjr
    @adhanjr 10 років тому

    why my sensor output always return value 6 cm ?

  • @pwr82
    @pwr82 5 років тому

    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

  • @budcarr8673
    @budcarr8673 5 років тому

    Awesome

  • @singgiha
    @singgiha 6 років тому

    how much it costs?

  • @bsewelliii
    @bsewelliii 8 років тому +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 7 років тому +2

      same here

    • @raspberry-pi-toys9715
      @raspberry-pi-toys9715 7 років тому

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

    • @seffdog22
      @seffdog22 7 років тому

      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 6 років тому

      Same

  • @betoch7556
    @betoch7556 7 років тому +2

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

    • @averial9831
      @averial9831 7 років тому +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 4 роки тому

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

    • @averial9831
      @averial9831 4 роки тому

      @@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 5 років тому

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

  • @miguelangel-nv5tj
    @miguelangel-nv5tj 10 років тому +1

    can i run the code with python idle?

    • @AlsoIUseArch
      @AlsoIUseArch 10 років тому

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

  • @huskie1561
    @huskie1561 8 років тому

    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 5 років тому

      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 .

  • @paulkrela3376
    @paulkrela3376 9 років тому

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

  • @satyamnayak2576
    @satyamnayak2576 5 років тому

    please share the above code

  • @moviesclips1096
    @moviesclips1096 5 років тому

    Please share the code with us

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

  • @cagdastuna5505
    @cagdastuna5505 4 роки тому

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

    • @cagdastuna5505
      @cagdastuna5505 4 роки тому

      bc there is just two 5V pin in raspberry pi

  • @danielabs5964
    @danielabs5964 4 роки тому

    How can I make the measurement repetitive?

  • @existentialchild698
    @existentialchild698 8 років тому

    It has

  • @updowndown
    @updowndown  10 років тому +4

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

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

  • @M4tt1mus
    @M4tt1mus 6 років тому

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

  • @novivi4390
    @novivi4390 8 років тому

    nano... Unix...

  • @jaycool5978
    @jaycool5978 9 років тому

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