Get Started in Electronics #8 - Using the HC-SR04 Ultrasonic Sensor

Поделиться
HTML-код
  • Опубликовано: 26 июл 2020
  • Hello, 3D Printing & Electronics friends! Today we're going to find out how to control an Ultrasonic Sensor with an Arduino Uno, writing code in the Arduino IDE! This one is quite simple to do!
    In this series, we're using the Elegoo Uno Super Starter Kit. Want to buy an Elegoo Uno Super Starter Kit for yourself? You can pick one up here:
    • amzn.to/2B92t4i 🇺🇲US [affiliate link]
    • amzn.to/2IR2n5n 🇨🇦Canada [affiliate link]
    LINKS:
    BV3D Arduino Prototyping Base
    • www.thingivers...
    Did this video help you out, save you a bunch of time, or help you learn something new?
    If so, please consider becoming a channel member, or buying me a coffee, or leaving a tip! Your support really helps, and is VERY MUCH APPRECIATED!
    ✅ BV3D Channel Membership: ruclips.net/user/bv...
    ☕️ Buy Me a Coffee: www.buymeacoff...
    👍🏻 PayPal tip jar: www.paypal.me/...
    *️⃣ The BV3D Channel Storefront on Amazon:
    • www.amazon.com...
    *️⃣ Popular 3D printer affiliate links:
    • BIQU: shrsl.com/3s4hr
    • Creality: shrsl.com/3qu2u
    • Comgrow: bit.ly/33xcDtB [Check out the Creality REFURBS!]
    • Elegoo: shrsl.com/3pu98
    • FLSun: flsun3d.com/?r...
    • Pergear: bit.ly/BV3Dper...
    • Sovol: bit.ly/3h90d2L
    • Sunlu: bit.ly/3hGNzpQ
    • Voxelab: bit.ly/3vVG9Wq
    *️⃣ In the market for a magnetic flexible build system for your 3D printer?
    💥Wham Bam Systems flex plates: bit.ly/2YzogLZ
    As a Wham Bam Systems Associate I earn from qualifying purchases.
    *️⃣ Shop for just about anything:
    🛒🇺🇲US: amzn.to/2x4hBxS [affiliate link]
    🛒🇨🇦Canada: amzn.to/2Ycb5ju [affiliate link]
    As an Amazon Associate I earn from qualifying purchases.
    SOCIAL MEDIA
    Follow me on Twitter (@bryan_vines): / bryan_vines
    Disclosure:
    I sometimes receive compensation such as discounted or free products, and when applicable, this is disclosed in videos and their descriptions. Whether free, discounted, or paid full price, any reviewed product is tested to the best of my ability, and I give my honest impression. All opinions expressed are my own.
    #BV3D
    #BV3DChannel
    #3DPrintingFriends
  • НаукаНаука

Комментарии • 98

  • @mikeboehk2307
    @mikeboehk2307 2 года назад +15

    Looks like you haven't had comments in a while, but just wanted you to know people are still watching and learning from your Videos. I think your pacing is great, you take just enough time to explain stuff that experienced people can type along without pausing, while newer people get the details and then can pause as they study and enter the code.
    Good job.

  • @gibsonsimpson
    @gibsonsimpson 4 года назад +10

    I like the way you walk through the code. It's helpful to build my understanding of the programming side. Keep up the great vids!

    • @BV3D
      @BV3D  4 года назад +4

      Hi! Thanks - That's what I'm trying for! A lot of tutorials (even the ones included in this kit) are all about loading the code from disk and running it, but they don't really go over what the code is actually doing. Thanks for watching! 😀

  • @marcuscurtis5128
    @marcuscurtis5128 Год назад

    LOVE this series: easy-going presenter, very simple instructions and demos, and lots of room to do personal tinkering. I'm working on learning Arduino, and this series is BY FAR the most helpful one I've found.

  • @SteveH-TN
    @SteveH-TN Год назад

    Bryan I’ve been binge watching this series of videos for several days. Today I took a break and watched a couple of other people present videos about Elegoo Starter kits.
    I want to Thank you for your through preparation, outstanding performance and presentation. Your videos have professional quality, smooth execution and enjoyable to watch. By far you are one of my RUclips favorite channels

  • @romanhlohowskyj
    @romanhlohowskyj 8 месяцев назад

    Me and my son just got done using our ultrasonic sensor for the first time. Having a lot of fun going through this series and can't wait to start doing some of our own projects

  • @silvrfoxgamr6183
    @silvrfoxgamr6183 Год назад

    I picked up the Elegoo Super Starter Pack for Christmas and your mini projects are great. Easy to follow and the wiring setups are really helpful. Keeps the wires tidy. Nice job!!!!

  • @kenlipper874
    @kenlipper874 4 года назад +3

    The HC-SR04 is used for the "Eyes" on the Vorpal I built: drive.google.com/file/d/1O12K5ldPR0UUFCPeC5wZuYCAOtIbBEIO/view?usp=sharing
    Check out the project if you're interested - Great project: www.thingiverse.com/thing:2513566

    • @BV3D
      @BV3D  4 года назад

      That's *_really_* cool! Thanks for sharing your video and the link to Thingiverse! 😀

  • @TheEdgeofTech
    @TheEdgeofTech 4 года назад +2

    Nice work Bryan!

    • @BV3D
      @BV3D  4 года назад

      Thanks Jim! 😄

  • @michaelshiloluzano6076
    @michaelshiloluzano6076 4 года назад +1

    Thank you very much for sharing the video. I actually used your video series to teach myself how to use the arduino uno and program. I like the way you simplify things. When I saw your last video I was kinda sad thinking that would be your last one about this topic but now I'm glad you're back. I started watching other channel but yours still is way easier to understand. I'm now on the Crystal LCD display section but I will still watch your future videos on this subject to make sure I understand it well. Great instructional videos

    • @BV3D
      @BV3D  4 года назад

      Hi! I try to release one of these about every month, but sometimes it goes a little longer between episodes. I'm glad you like them (and congrats on getting up to the LCD part!) 👍

  • @codydodd2060
    @codydodd2060 Год назад

    thank you going through your kit guide now and appreciate the code commentary and thorough walkthrough for every video.

  • @drewb9022
    @drewb9022 Год назад

    This Get Started Electronics series got me to subscribe, really hope to see more of these!

  • @NickLocapo
    @NickLocapo Год назад

    This video series is so damn good.

  • @richardtovar2540
    @richardtovar2540 4 года назад +2

    Great video! I love these series of videos you have made, they have helped me further my knowledge past the basic instructions provided in the elegoo kit. I will be anxiously waiting for the next video to help me along. Thank you for the content!

    • @BV3D
      @BV3D  4 года назад

      Hi Richard! I am glad you like them! 😃

  • @julianyumanji1159
    @julianyumanji1159 3 года назад

    I love your videos because they are comprehensive and show the code too!

  • @JR-je7ce
    @JR-je7ce 3 года назад +1

    I think this series is great the only thing I wish you would have done diffently is explain why certain things are the way they are like you pointed out the capital D but never said why just that it was important

  • @MisterMakerNL
    @MisterMakerNL 4 года назад +2

    Great tutorial, and I am glad you go further than just 3D pringing.
    A tipf for this sensor, is to stack the check.
    If distance >100
    then
    If distance >100
    then
    do this
    This way you filter out some noise.

    • @BV3D
      @BV3D  4 года назад

      Hi MisterMaker! Great tip, and keeps the weird distance readings at bay! 👍

    • @certified-forklifter
      @certified-forklifter 4 года назад +1

      @@BV3D you could also just take like 10 readings and then average it :D

    • @BV3D
      @BV3D  4 года назад +1

      id True, I could, but that would take a lot longer to get a reading. I like the idea of just throwing out excessively large readings and trying again. 😀

    • @certified-forklifter
      @certified-forklifter 4 года назад +1

      @@BV3D okay :D

  • @peterrisberg7150
    @peterrisberg7150 4 года назад +2

    Hi Bryan. I'm new on your channel. Starting with the Get Started in Electronics series. Love it.
    I just have to ask. Are you relative or brother with Adam Savage from Myth buster?
    You to semes to have much in common. Electronics and both of you are creative with a lot of stuff. And are kinda look alike.
    Keep it up.

  • @spikekent
    @spikekent 4 года назад +1

    Another fantastic pun-ridden video. Great work Bryan.

    • @BV3D
      @BV3D  4 года назад +2

      Thanks Spike! 😂 I really only had the one good one (SONAR so good)... 😊

    • @spikekent
      @spikekent 4 года назад

      @@BV3D One is always better than none 😊

  • @Cleverwolfano
    @Cleverwolfano 7 месяцев назад +1

    Thanks!

    • @BV3D
      @BV3D  7 месяцев назад +1

      Sure thing!

  • @wherami
    @wherami 2 года назад

    You did a great job with this series

  • @awiranata3191
    @awiranata3191 3 года назад

    I like the way you are explaining every things, it sounds so clear for me. by the way, I also bought this Elegoo Uno R3 project kit. it's price is reasonable :)

  • @chrisb7250
    @chrisb7250 Год назад +1

    I am going to use it to measure the depth in a tank, then open and close a valve using a servo to maintain a certain depth.

    • @BV3D
      @BV3D  Год назад +1

      Cool idea!

  • @nicolasquintanaariste6614
    @nicolasquintanaariste6614 3 года назад

    This is a fascinating component im sure ill use it in alot of projects. Thank you for teaching me how to use it.😁

  • @davidcastro9399
    @davidcastro9399 3 года назад

    Awesome classes you are an awesome teacher

  • @tussah8874
    @tussah8874 8 месяцев назад

    For some reason, I only get '0' over and over for this one. I can't find any syntax or wiring errors, but I have to think I'm overlooking something. The only difference I can see between my code and yours is that on line 9 SR04 sensor = SR04(echo_pin, trig_pin); the first instance of SR04 isn't showing red in my IDE.
    EDITED to add: Son of a gun. I rebooted the PC and tried again this morning and now it's working. Enjoying your videos!

    • @jamesgames4380
      @jamesgames4380 6 месяцев назад +1

      i know you have now fixed the problem but you possibly didnt have the library for the sensor chosen?

  • @pantera1907
    @pantera1907 4 года назад

    Great video, I've learned so much with clear and easy instructions. Can you do another lesson working with LCD screen, I think that is one of the main components I'm missing from your tutorials.

  • @AbrahamIsaacDuran
    @AbrahamIsaacDuran 3 года назад

    I really like this series, hope you can keep them up! I like your approach to Elegoo projects and the added explanation. I appreciate the fact that you go over the basics repeatedly, not because I want them, but because someone joining the series at a later state can still understand the fundamentals.
    However, I see that sometimes certain things go unexplained; in that sense, could you tell me what Serial.begin(9600) does, why is needed and why 9600? Thank you very much, sir.

  • @TD3DMakes
    @TD3DMakes 4 года назад +1

    Great stuff Bryan, thanks for sharing!

    • @BV3D
      @BV3D  4 года назад

      You bet! Thanks, Thierry! 😊

  • @DbitDerald
    @DbitDerald 3 года назад +2

    I downloaded the HC-SR04 thing but when I ran the code it said " SR04.h: No such file or directory" and I couldn't run the code. do you know why this is happening and could you help me with this?

  • @moldiebrownie
    @moldiebrownie 4 года назад

    Great vids, cant wait for the next installment, tipped!

  • @zimmy1958
    @zimmy1958 4 года назад +1

    Thanks Bryan well done again.

    • @BV3D
      @BV3D  4 года назад

      Hi Zimmy! Thanks! 😃

  • @Wes_Reigns
    @Wes_Reigns 3 года назад +1

    can you also do this on windows because it is very difficult for me to follow when you use mac

  • @Ron_Ventura
    @Ron_Ventura 4 года назад +5

    I’m a retired programmer. I wish I had that shirt while I was still working.

    • @BV3D
      @BV3D  4 года назад +1

      Hi Ron! I'm glad you liked the shirt! What languages were you writing in? 👍

    • @Ron_Ventura
      @Ron_Ventura 4 года назад +3

      Started out in assembler, 100 years ago. Did some COBOL for a while (I gather COBOL programmers can write their own ticket these days). But the last 10 or so years were spent writing in JAVA, mainly as a back-end for our company’s web-based systems. And we built and maintained the web pages too. These were all test-dummy...I mean customer facing, so you found out pretty quick if you’d stuffed up.

    • @SteveH-TN
      @SteveH-TN Год назад

      @@Ron_Ventura I learned to program in GOTRAN during a summer 1964 workshop Iillinois Institute of Technology for High School students.😮 IBM released FORTRAN that summer which I also learned. Python was last language I learned over several decades.

  • @Eliminoid
    @Eliminoid 3 года назад +1

    I couldn’t include the library because I’m using windows. Could anyone please tell me why I couldn’t include it ?. Thanks

  • @randomizedletters4466
    @randomizedletters4466 3 года назад +1

    more more moreeeee
    should do one where on the screen module it shows the distance in cm

  • @jjsara123
    @jjsara123 2 года назад

    "If you come up with a good one, let me know in the comments"
    First, thank you so much Bryan for your thoughtful and extremely well explained and produced videos. Walking through the code is so important compared to just cut/paste!. It's reminding me of C programming in a past life ;) SO- my goal here is to set up the sensor on the porch for Halloween. When kids come up the stairs, I'd like to trigger some other lights to shin on a skeleton inside the window, make some LEDs in his light up, etc. How I might set that up?

  • @precisionriflejunkiesjimmy6587
    @precisionriflejunkiesjimmy6587 3 года назад

    My son and I love your channel and are doing these along with you. On this one though we are only getting 0's on serial monitoring and the plotter. We checked our connections, and our code. Any other suggestions to trouble shoot why were not getting distances? PS were huge fans and so grateful for the videos!

  • @OthmanAlikhan
    @OthmanAlikhan 3 года назад

    Thanks for the video =)

  • @stingraymaster877
    @stingraymaster877 4 года назад

    Hey Brian how many vids will their be? Btw I love your vids and probably gonna get the kit with your link

  • @curly-hairedassassin5233
    @curly-hairedassassin5233 4 месяца назад

    Hello Bryan, how did you get the library folder at 5:22. I have the code folder, but no library folder. Did I do something wrong during your 1st video for setup?

  • @iExiledSon
    @iExiledSon 4 года назад

    Thanks Bryan, I have a project for this to measure various bin/tank fill levels. This sensor should come in handy. Only thing is that this is just returning the information to the monitor and needs direct connection to my PC. Do you the best way to have this out in the open somewhere? Perhaps a LoraWan extension for the arduino and some extra code to push that data somewhere?

  • @S3Moto
    @S3Moto 2 года назад

    how about a proximity sensor for parking in the garage?

  • @x_x3867
    @x_x3867 Год назад

    Where did you download the english library? I cant find my english library.😅

  • @DargoDog
    @DargoDog 3 года назад

    Great tutorial!!! Long time electronics and RC hobbyist, and would like to up my game with Arduino boards. Having recently taught myself 3D printing and Fusion 360, I was looking for help with learning Arduino to flatten the learning curve a bit, looks like this kit with your videos is the way to go! What programming language is that, it looks a lot like Java, but there are some subtle differences? Do you know what the horizontal and vertical beam widths are of that sonar board?

  • @waleedalbanna8505
    @waleedalbanna8505 Год назад

    Can I do the same thing for a PIC microcontroller?

  • @Diomam69
    @Diomam69 8 месяцев назад

    I have a problem .
    exit status 1
    SR04.h: No such file or directory can you help me plese?

  • @siroglethorpe311
    @siroglethorpe311 10 месяцев назад

    if u want to combine the grand theft project with this, (my ball sensor didn't work) here is the full code for ultrasonic sensor combined w/red LED and epoxy bottom speaker
    #include "SR04.h"
    int buzzerValue = 3;
    int redValue = 2;
    int trig_pin = 12;
    int echo_pin = 11;
    SR04 sensor = SR04(echo_pin,trig_pin);
    long distance;
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    delay(1000);
    pinMode(redValue, OUTPUT);
    pinMode(buzzerValue, OUTPUT);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    distance=sensor.Distance();
    Serial.println(distance);
    delay(1000);
    if(distance < 30){
    digitalWrite(redValue, HIGH);
    digitalWrite(buzzerValue, HIGH);
    }
    if(distance > 30){
    digitalWrite(redValue, LOW);
    digitalWrite(buzzerValue, LOW);
    }
    }

  • @thechuckyboi1438
    @thechuckyboi1438 2 года назад +1

    a lot of the other videos have been more informative as to what different code means, however I had trouble with this video.
    what is the point of the paranthesis after distance?
    what is point of the 9600?

    • @BV3D
      @BV3D  2 года назад +1

      Hi! Distance (with a capital D) is a function within the sensor's library. When calling a function, parenthesis are included to pass any data to the function that it may need. Since the Distance function doesn't need any data passed to it, there's nothing in the parenthesis.
      The value 9600 is the speed, in bits per second, at which the Arduino IDE's serial monitor communicates.

    • @thechuckyboi1438
      @thechuckyboi1438 2 года назад +1

      @@BV3D thank you so much for the quick response! I greatly appreciate you making these videos! I’m more of a visual learner so this helped me understand a lot of stuff a lot easier!

  • @diegocordero676
    @diegocordero676 3 года назад

    please come out with more!

  • @carbon273
    @carbon273 3 года назад

    So was this object oriented programming? Was SR04 a class and was sensor an object in the code?

  • @paulradford4100
    @paulradford4100 4 года назад +1

    Good video for those just getting started with arduino and simple electronic projects. Well done and in a clear way, as you do..
    Unfortunately adverts are becoming more common in your videos, 4 in this one. The advertising is distracting and not a good thing.

    • @BV3D
      @BV3D  4 года назад +4

      Hi Paul! Four ads on a thirteen minute video? Ugh! RUclips, what're you thinking?! I'll see what (if anything) I can do about that. 👍

  • @chrisseymour3027
    @chrisseymour3027 3 года назад

    Could the high spike be due to the speaker being covered and this causing the microphone side to not hearing the echo? Would this cause the sonic sensors circuitry to return its maximum value?

  • @kamruz360
    @kamruz360 Год назад

    Hi Bryan, Loving your show - been through video projects 1-7. I am 7 years old and like your simple explanations. I am using my dad's Mac with Arduino IDE - please help, I am stuck on video #8 - I have followed all the instructions and sketch code, when running the code I get:
    suggested alternative: 'perror'
    note: suggested alternative: 'perror'
    distance=sensor.Distance();
    ^~~~~~
    perror
    exit status 1
    'HCSR04' does not name a type; did you mean 'UCSR0A'?
    Many thanks
    Ismale

  • @stingraymaster877
    @stingraymaster877 4 года назад

    Your computer has got progressively more stickers on it throughout this series

  • @Adam-gw8jt
    @Adam-gw8jt 3 года назад

    can someone plz tell me how to download the library file for SR04? did they update it or something cuz the "English" file looks completely different for me

  • @syntaxcuemi3d53
    @syntaxcuemi3d53 4 года назад +1

    Could the sensor be used as runout filament sensor for a 3d printer?

    • @BV3D
      @BV3D  4 года назад +1

      Syntaxcuemi 3D I don’t think it would work well in that application. This sensor is more for telling how far away something is. For a filament runout sensor, you’re far better off using a device made for that purpose. Search “Filament Sensor” on Amazon to see a bunch of options, several under $10. I saw a two-pack of sensors in the $8 range. 👍🏻

    • @syntaxcuemi3d53
      @syntaxcuemi3d53 4 года назад +1

      @@BV3D looking at it again, the sensor unit, is a bit large for the application. But it got me thinking, could it be used as an abl sensor? OK, it'll need a bracket printed for it & the output signal could be used to trigger the z distance in marlin. Just like the ezabl sensor.

    • @BV3D
      @BV3D  4 года назад +1

      Syntaxcuemi 3D According to its documentation, it has an accuracy of about 3 millimeters, and the code library for it is returning values in whole centimeters. Even if you were getting it to work at its peak accuracy, it could be off by +3mm or -3mm on any given reading. It just doesn’t have a high enough resolution to be used as a bed probe. I know a lot of people like using inductive bed probes, which work by detecting (with great accuracy) the presence of the metal bed on a 3D printer. But if you have a glass surface on top of the metal bed, or you swap out flex plates with varying thicknesses, you have to adjust the Z axis offset to match each surface. With a touch probe (like a BL Touch), the probe senses the surface of the bed and so it doesn’t matter what print surface you’re using. 😊

    • @syntaxcuemi3d53
      @syntaxcuemi3d53 4 года назад +1

      @@BV3D I didn't realise there was such a high tolerance. I think 6mm tolerance is a bit much for a endstop probe 🤦‍♂️🤣 i have an inductive probe on my Ender 3 Pro (donated from work). But its rated at 12-30v. Couldnt find a compatible 5v probe 🤦‍♂️ so I had to use a relay to make it work. It does work to a sort. But it has a weird leving issue. So for now, I've gone back to mesh bed leveling.

    • @paulradford4100
      @paulradford4100 4 года назад +2

      This sensor is doubtful to be useful for filament run out. But it wouldn't be too difficult to use a led (with resistor) and a ldr (light detecting resister), if you was to set it up right and different programming of the arduino..
      For a bit of fun, I set up the arduino to sing a Christmas song whenever someone walked past it.
      You would need to do something similar, bit more refined..

  • @WhiteNucklin
    @WhiteNucklin 3 года назад

    How can I upload the code I want to run to the arduino and have it run continuously while its no longer plugged into my computer?

  • @gregbennett2437
    @gregbennett2437 Год назад

    could not get it to work (code failed)

  • @certified-forklifter
    @certified-forklifter 4 года назад +2

    awesome vid, Bryan :D small tip: if you use #define instead of int, you won't waste precious memory on the small microcontroller ;) also, i never knew about that library, i always did it without. awesome!
    also: if you plan to make more complex projects like the LED one you mentioned, i highly recommend you check out "betterbreadboarding.com" he is a really nice person and he made small labels for wires :D
    cheers.

    • @BV3D
      @BV3D  4 года назад +1

      Thanks for the info! I may start using #define instead of global INTs. It's probably a good habit to get into, rather than something to pull out of my programming toolkit if I start running out of space on the microcontroller. 😃

    • @certified-forklifter
      @certified-forklifter 4 года назад

      @@BV3D cheers! :D

  • @cole6364
    @cole6364 3 года назад

    how to get coding app?

  • @gregbennett2437
    @gregbennett2437 Год назад

    fatal error: SR04.h: No such file or directory ? anyone

  • @MiloH2023
    @MiloH2023 2 года назад

    Reverse backup beeper on a car