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 Наука
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.
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!
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! 😀
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.
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
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
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!!!!
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
That's *_really_* cool! Thanks for sharing your video and the link to Thingiverse! 😀
Nice work Bryan!
Thanks Jim! 😄
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
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!) 👍
thank you going through your kit guide now and appreciate the code commentary and thorough walkthrough for every video.
This Get Started Electronics series got me to subscribe, really hope to see more of these!
This video series is so damn good.
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!
Hi Richard! I am glad you like them! 😃
I love your videos because they are comprehensive and show the code too!
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
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.
Hi MisterMaker! Great tip, and keeps the weird distance readings at bay! 👍
@@BV3D you could also just take like 10 readings and then average it :D
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. 😀
@@BV3D okay :D
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.
Another fantastic pun-ridden video. Great work Bryan.
Thanks Spike! 😂 I really only had the one good one (SONAR so good)... 😊
@@BV3D One is always better than none 😊
Thanks!
Sure thing!
You did a great job with this series
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 :)
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.
Cool idea!
This is a fascinating component im sure ill use it in alot of projects. Thank you for teaching me how to use it.😁
Awesome classes you are an awesome teacher
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!
i know you have now fixed the problem but you possibly didnt have the library for the sensor chosen?
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.
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.
Great stuff Bryan, thanks for sharing!
You bet! Thanks, Thierry! 😊
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?
Same!!
Great vids, cant wait for the next installment, tipped!
Thanks Bryan well done again.
Hi Zimmy! Thanks! 😃
can you also do this on windows because it is very difficult for me to follow when you use mac
I’m a retired programmer. I wish I had that shirt while I was still working.
Hi Ron! I'm glad you liked the shirt! What languages were you writing in? 👍
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.
@@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.
I couldn’t include the library because I’m using windows. Could anyone please tell me why I couldn’t include it ?. Thanks
more more moreeeee
should do one where on the screen module it shows the distance in cm
"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?
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!
Thanks for the video =)
Hey Brian how many vids will their be? Btw I love your vids and probably gonna get the kit with your link
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?
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?
how about a proximity sensor for parking in the garage?
Where did you download the english library? I cant find my english library.😅
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?
Can I do the same thing for a PIC microcontroller?
I have a problem .
exit status 1
SR04.h: No such file or directory can you help me plese?
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);
}
}
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?
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.
@@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!
please come out with more!
So was this object oriented programming? Was SR04 a class and was sensor an object in the code?
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.
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. 👍
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?
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
Your computer has got progressively more stickers on it throughout this series
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
Could the sensor be used as runout filament sensor for a 3d printer?
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. 👍🏻
@@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.
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. 😊
@@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.
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..
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?
I believe WiFi
us the 9V battery
could not get it to work (code failed)
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.
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. 😃
@@BV3D cheers! :D
how to get coding app?
fatal error: SR04.h: No such file or directory ? anyone
Yea same
Idk what to do
Reverse backup beeper on a car