Lesson 18: Measure Distance with Arduino and Ultrasonic Sensor

Поделиться
HTML-код
  • Опубликовано: 3 окт 2024
  • In this tutorial we show simple step-by-step lesson on how to measure distance with an arduino microcontroller and an ultrasonic sensor. The measured distance is based on the ping time to the target of an ultrasonic ping. The measured distance is displayed via a servo and hand drawn scale. The sensor used is the virtuabotix ultrasonic sensor, and the servo is from the Sparkfun Inventor kit. Key concept in this lesson is to show students how important it is to apply what they know from Algebra related to lines in order to map inputs (distance measurements) onto outputs (servo angle).

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

  • @omaxshendy5732
    @omaxshendy5732 5 лет назад +5

    you are one of the rare real teachers out here in youtube , who is teaching just in sake of teaching and make people actually learn.
    thankyou!

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

    This person deserves great respect.He is making those things look very easy and that too selflessly.

  • @44mod
    @44mod 6 лет назад +3

    Thank for being a teacher and a great one at that. I am 53 years old and just learning Aurdino as a hobby and you make it so exciting. Thank you, Thank you, Thank you!!

    • @paulmcwhorter
      @paulmcwhorter  6 лет назад

      Wonderful to hear these videos are helping someone get into this hobby. Thank you for the kind words.

  • @TheArchaeus6
    @TheArchaeus6 6 лет назад +1

    You know what Paul, you're a proper educator in the very essence of the word. Thanks for the vids.

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

    Paul, this was a brilliant exercise! Combining the ultrasonic distance sensor with a servo. I am using this lesson to teach about building a self driving robot car and the idea of how autonomous vehicles avoid collisions. In our robot car, the servo changes the steering when the UDS detects an object close by. Another great lesson. Thank you so much! You need to write a book in conjunction with your video lessons!

  • @YasserIsmail
    @YasserIsmail 8 лет назад +7

    Mr. Paul, You have very amazing talent of making things simpler, we all really appreciate your great efforts

    • @poppypuppy5372
      @poppypuppy5372 6 лет назад

      Simpler? The calculation is unneccessarily complex. Look at the spec sheet for the sensor. It says to divide the pingtime by 58 to give cm and 148 for inches. No need for all that maths, unless you are interested as to how those numbers were arrived at

  • @fvazquez64
    @fvazquez64 6 лет назад +1

    I believe that the first thing to do, aside knowing the math, you have to take a moment to understand what your are doing and what you want to achieve, that's why most of the students solve a problem in theory but when they need to apply it to a real life situation they can't. You have to analyze the implications of the problem and with the proper tools how to solve it.... great tutorial!! thank you

  • @MrTiger1001
    @MrTiger1001 5 лет назад +1

    Keep up the good work. love these lesson and you are a great teacher. regards form a 44 year dude from Norway.

  • @deraltemannspielt3194
    @deraltemannspielt3194 7 лет назад +1

    This maybe is a late comment, but I'm very happy to find your lessons because you explain things from scratch and understanding is very easy. I looked for Arduino-Lessons because I want to teach my daughter mechanics / physics and computing and think doing this by use of an Arduino is a good way to do it.
    Most I had to laugh about your sentences 'do the math!', could be my words ... Of course yes, most people prefer trial and error and thats a terribly behavior :-)
    Thanks for all the effort and time you spend at your desk producing all this lessons.

  • @McGavel1
    @McGavel1 8 лет назад +1

    Awesome! I love how you made your own output scale with the servo - what a creative way to have an output - thanks for the ideas!

  • @davidryalls2368
    @davidryalls2368 8 лет назад

    Dear Paul - I thank you very much for your tutorials - your style of presentation and explanation is exactly what I like. - Thank You. I have viewed many C++ RUclips tutorials and for me yours are by the far the best. A BIG Thank you

  • @makincracksent
    @makincracksent 9 лет назад

    Thank you for that presentation Mr. McWhorter. I am working on a personal project and this lesson just helped me with my concept a lot. I plan on watching ALL of your lessons over the next few days. Thanks again sir.
    -Kareem-

  • @shubhamkshirsagar6429
    @shubhamkshirsagar6429 6 лет назад

    Great...Thank you...He is still contributing to the Arduino Lessons series ....Thank you so much....

  • @erygion
    @erygion 5 лет назад

    Great lesson Mr. Mcwhorter, I have to go back and really take in the steps and formulas used cause the potential applications for this is far and wide. Very handy and powerful stuff thank you sir.

  • @Furyblaze5555
    @Furyblaze5555 5 лет назад

    I find it funny that only now I'm starting to use math to create in reality through the way you explained it. Never knew why I had to learn grahps and statistics, I couldn't find the logic in it. But now I do, and even if it isn't in my native language....I still picked up a lot more because of your teaching methods. Thank you kind Sir to rekindle my intrest in math :)

  • @seimela
    @seimela 8 лет назад +2

    there is not tutorial like this on youtube .....appreciate

  • @TheBobbykey
    @TheBobbykey 7 лет назад

    you say the servo requires a library, but it doesnt library's just make it easier.I know you know this but beginners need to know that its not required just makes it easier .Great tutorials BTW

  • @ifjkl
    @ifjkl 8 лет назад

    Very elaborate instructional. Thank you very much! I subscribed, too!
    I'm planning to do a ultrasonic sensor to control, wether my garage door is opened or closed and wether a car is parked in it (by placing the arduino with the ultrasonic sensor at a special place on the ceiling). Your instructional helped me very much with my project.

  • @sebastianfernandez596
    @sebastianfernandez596 8 лет назад

    Best tutorial I've ever seen.

  • @Ancientlaws
    @Ancientlaws 7 лет назад

    Thank you sir. Rather than just learning how to use the libraries its nice to actually understand the implementation.

  • @rodgerrodger6298
    @rodgerrodger6298 9 лет назад

    this is a really awesome video i very much appreciate you not lieing with the code
    i strongly dislike the people that do that

  • @manmenboy
    @manmenboy 8 лет назад

    Man appreciate you. Excellence video!!!!!!!!!!!! Best ive ever seen on RUclips

    • @paulmcwhorter
      @paulmcwhorter  8 лет назад +1

      +Da'Neil Pitts Thanks for the kind words.

  • @ChrisBentley
    @ChrisBentley 9 лет назад +1

    Sir, you have made my day by getting my sensor to work.

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

    I am learning so much and so fast since I discovered this channel. The teaching reveals a well thought methodology that allows easy understanding and follow-along. Thank you so much.
    I was wondering how you stuck that arrow to the servo. Glue? CHeers!

  • @mohammadken2470
    @mohammadken2470 6 лет назад

    Very helpful tutorials.... learned everything about arduino just from these vedios😘😘😘

  • @3reebdar355
    @3reebdar355 9 лет назад +8

    Just wannna say you are a great person.

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

    Sir, I am beyond words to thank you. Your effort surpasses all the appreciations that could be given. One small question. You had mentioned that the servo draws a lot of currents, and in case we attach to Arduio for passing the current to the servo, it might harm the Arduino board itself. Then why are you passing the current via the board? I might have missed something. Please advise.

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

      Its been 2 years since you commented, got your answer yet

  • @mark879
    @mark879 9 лет назад +3

    Awesome video! You just got yourself a new subscriber.

  • @pc.languageteacher8448
    @pc.languageteacher8448 7 лет назад

    Very interesting parts of this lesson is saying about guessing students which are idle to use math counting It is right as about me. Thanks for remaining me to be not idle to use math in engineering life.

  • @aritrasurroy4794
    @aritrasurroy4794 8 лет назад

    Great way to teach in an interesting manner.

  • @zaharouni1
    @zaharouni1 10 лет назад +30

    Very helpful tutorial... For(i=0, i

  • @antonviper7803
    @antonviper7803 7 лет назад

    Great tutorials, and understand them well, thank you. I see you use a distance "meter" in your diagram, but then calculate in old fashioned units in your code. There would be no confusion for your students code errors if you just use metric though.

  • @rajcodes100
    @rajcodes100 5 лет назад

    Great explanation Paul.

  • @clichereful
    @clichereful 8 лет назад

    Thank you for these great tutorials!! Really helping me out !!

  • @grandota1
    @grandota1 7 лет назад

    I can only say that, thank you very much, it has helped me too much for my project of ball and beam, greetings

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

    I'm in love with you sir ❤️❤️
    From india 🇮🇳

  • @McGavel1
    @McGavel1 8 лет назад

    So then a fun way to calibrate the speed of sound would be to add a temperature sensor and adjust it based on current temp. This is so fun - thanks again.
    Cool point too about how a high pulse goes low/high/low and a low pulse goes high/low/high. Also neat how we can delayMicroseconds!

    • @McGavel1
      @McGavel1 8 лет назад

      I looked up the equation for speed of sound in air based on air temp, which uses Celsius. I prompted the user if they want to enter temp in Celsius of Fahrenheit then ask user for current temp and convert it to Celsius if they chose Fahrenheit. Then I find the speed of sound based on their input temp and use that for my measuring with the ultrasonic sensor.
      I also looked up how to write functions so I made some to do these conversions. I found out you say void myFunction if don't need it to return a value or instead of void, whatever the variable type that should be returned like float myFunction(float tempTime, float soundSpeed) {float result; ...result = calculations...; return result;}

    • @McGavel1
      @McGavel1 8 лет назад

      I added a conversion from inches to feet if target distance > 12 inches for my serial output.
      Also added a red LED for if the target is "in range" meaning closer than a foot that brightens as target gets closer and dims until off as target gets farther away. This is fun - thanks again!

  • @cleisonarmandomanriqueagui9176
    @cleisonarmandomanriqueagui9176 6 лет назад

    Thanks , from Peru !!!

  • @GTV1965
    @GTV1965 7 лет назад

    Fantastic tutorial! Great job!

  • @MadMax-gv9mg
    @MadMax-gv9mg 8 лет назад

    love your videos, learned a lot. keep it coming!

  • @8Kexperience
    @8Kexperience 8 лет назад

    Your tutorials are great Paul. I am looking for sensor which can measure longer distances. Can you guide me where to go for them?

  • @rurouniraphael
    @rurouniraphael 9 лет назад

    AWESOME explanation... THANK YOU SO VERY MUCH.... subscribed and gonna watch other video's

  • @musheeTV
    @musheeTV 8 лет назад

    pretty great teaching sir

  • @sourabhgoyal9366
    @sourabhgoyal9366 5 лет назад

    sir these lectures are awesome . i am a big fan of u . i completed the arduino projects . so what is the next step to learn. if you reply then it would be helpful for me.

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

    Do you need a pinMode for the servo? In video 17 of this series, you didn't include a pinMode with the servo so I'm confused as to why you included it here.

  • @SUDSY0
    @SUDSY0 5 лет назад

    You are like my Mr. Miyagi!!! Thank You

  • @MuhammadAmin-th4bp
    @MuhammadAmin-th4bp 8 лет назад

    Hi Pual i hope you will be right........look i don;t have words to use that time. i thanks but thanks very much for the giving us this nice knowledge .......

  • @tbinarab
    @tbinarab 7 лет назад +1

    Hi teacher thank u very much for all that helpful lessons I bought the kit and also some robot parts (tank ) it comes with sex wires I get stuck

  • @badri20031
    @badri20031 6 лет назад

    Greeting SirI have one question, which is related to "can we measure the distance of the object based on color ! ".For example, If we are in the farm and we need to measure the distance between two plant !Many thanks

  • @hakankarakurt1100
    @hakankarakurt1100 9 лет назад

    Thank you for excellent lesson Mr. McWhorter. Can you please make a lesson about controlling dc motor with arduino? Thank you for your attention

  • @RIBERA7891
    @RIBERA7891 10 лет назад

    very good video

  • @manofmesopotamia7602
    @manofmesopotamia7602 6 лет назад

    great tutorial, Many Thanks

  • @namocrafts1101
    @namocrafts1101 7 лет назад

    Hello sir thank u for u sharing ur knowledge with us
    One q plz every thing working fine but why some time the sensor fluctuate? And goes back to the actual reading again ?

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

    Hi
    Why is my servo spinning the wrong way? If I increase distance, arrow goes to the left (decreases instead of increasing )

  • @lanzevalencia6614
    @lanzevalencia6614 10 лет назад

    Very precise tutorial... thank you sir, you're the real MVP ^_^V

    • @paulmcwhorter
      @paulmcwhorter  10 лет назад

      Lanze Valencia Thanks for the encouraging words!

  • @frankshen2739
    @frankshen2739 8 лет назад

    Great video, thanks Paul! I have an advice, can we set a limit to servo angle like if(servoAngle143) servoAngle=143;

  • @seimela
    @seimela 8 лет назад

    i want to measure distance when is 15mm at has to move down to 10mm and when is 5mm it has to drive stepper motor and move to back to 10mm

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

    AH, my sensor seems not to be quite as calm as yours! Looking at the serial port i notice that it reads a few distances that are way off before settling down and reading more accurately. When I wrote these values to the servo it was jittering all over the place. The servo couldn't keep up with the values produced by the ultrasonic sensor. Is this a hardware issue? Can i fix in the code some how? Any help would be greatly appreciated.
    thanks for the lessons.

  • @nishantsinghal5846
    @nishantsinghal5846 6 лет назад

    Very helpful tutorial...
    Sir, plz make a tutorial video on gyro+acc sensor (mpu 6050), because i want to make a project using this sensor

  • @PrasadGavhane
    @PrasadGavhane 9 лет назад +1

    How to display the measurements on a 7 segment LED ?

  • @tymonh854
    @tymonh854 5 лет назад

    Great tutorial! Do you know if these sensors would work with a liquid? I'm trying to create a project that uses the same technology as well as a pump and valves to fill a cup or beaker with water to a user specified volume.

  • @partsdave8943
    @partsdave8943 7 лет назад

    Paul, Do you think an ultrasonic sensor would work as a paper detector on a printer? I'm looking for a solution to notify employees when paper comes out of a printer that isn't easily seen, by turning on an LED or buzzer.
    Thanks again for the videos.

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

    thank you for this grate lesson and I wanna ask something what if I put my sticky notes farther than 7 inch

  • @AhmadAbdi
    @AhmadAbdi 6 лет назад

    Hi Paul, i am looking for a way to detect a small metal or tag but from about 35cm ... any way to isolate the Ultrasonic to only detect this target piece and ignore any other devices between? great channel by the way

  • @fiifinenyi2156
    @fiifinenyi2156 7 месяцев назад

    Please I need help
    I want to measure the capacity of water in a tank using the ultrasonic sensor
    Please am facing some problems

  • @654785439
    @654785439 10 лет назад

    very good

  • @darkdevil9550
    @darkdevil9550 5 лет назад

    Hi sir thank you for this video

  • @mohammadken2470
    @mohammadken2470 6 лет назад

    What was pinMode(servocontrolpin,output) used for....i guess it shouldn’t be written

  • @richtankone
    @richtankone 6 лет назад

    Hey Paul, Need some help here. So Plan to do something similar but instead of a servo I want to use a stepper. So basically the ultra sonic measure an initial distance and then as soon as it measures a different distance of more than 8-10" greater than the initial distance it would write that to a stepper motor. So if the stepper motor was attached to a ball screw it would then move the change in distance measured relative to the necessary rotations. Any suggestions?

  • @havajc1
    @havajc1 9 лет назад

    It keeps writing 0cm, but i did everything the same as you did, please help

  • @emanuellucas1470
    @emanuellucas1470 6 лет назад

    Dear Paul i'm working on something that combine PIR and Ultrasonic sensor and i'm not that good in programming is it possible to combine the two??Thanks

  • @roboguru6178
    @roboguru6178 6 лет назад

    Hi my name is Pratham.
    I to make this arduino program
    When the distance between ultrasonic sensor and object is low
    Then low number of led should glow but when the distance is high
    Then the number of led glow must be increased

  • @ChristianDiaryUG
    @ChristianDiaryUG 7 лет назад

    I want to connect a speaker to speak the distance between the sensor and the target, how can I do it?

  • @ujjawalpanchal
    @ujjawalpanchal 8 лет назад

    Is it compulsary for echo pin to be an analo pin? or digital ones work?

  • @cassablancas8325
    @cassablancas8325 8 лет назад

    i need to build automatic following trolley for my final project
    hopely u can give further information

  • @sourodipbiswas2001
    @sourodipbiswas2001 7 лет назад

    Why am I getting zero distance on this code?! I searched help for online and saw the library of NewPing but still the problem is not solved. Please help....

  • @sooofyfarsi272
    @sooofyfarsi272 8 лет назад

    its great I like it .. but please can you help me with the code I need like to add led lights as extra to this whole project
    for example:
    if the object became close to the sensore for about 2 seconds the red light should turn on
    or if it is less than 2 seconds the green light will turn on
    please help to write this code

  • @amjadraza6003
    @amjadraza6003 7 лет назад

    hello Sir,
    i am facing a problem,i have a arduino mega.
    and measuring distance through ultra sonic sensor.
    i am doing same as it is,just skipping the servo step in the code.
    my sensor not measuring the distance
    as i am not using servo,i just want to measure distance and check it from serial monitor.
    kindly figure me out.
    thankyou.

  • @cuongnguyenmanh3430
    @cuongnguyenmanh3430 5 лет назад

    please I asked you: i connected correctly to arduino, but when you load the code (though not load the library up), arduino lighting up , but servo is only spinning 2.3 round and stop, the ultrasonic sensor is not work, hope you help me, thank you very much!

  • @rodgerrodger6298
    @rodgerrodger6298 9 лет назад

    hey can i have a little help i have a smaller bread board an it only go up to 30 and also when i start it up it works awesome but my servo has a spasm so i will thank you for any ones help

  • @azrieltan5960
    @azrieltan5960 6 лет назад

    Hello Mr.Paul McWhorter, I really need your help with Ultrasonic HCSR04 and BeagleBone Black in Python. I could not use the pulseIn library and I am stuck. Hope that you have the solution for me.

  • @canygirl1234
    @canygirl1234 8 лет назад

    hi how did you do the diagram been looking them up and can not see 1 so i can mock a diagram

  • @GTV1965
    @GTV1965 7 лет назад

    Does this ultrasonic sensor work well outdoors?

  • @akhilsaji95
    @akhilsaji95 7 лет назад

    sir, after the tutorials will you teach us how to make the arduino wireless? currently i am at lesson 16

    • @paulmcwhorter
      @paulmcwhorter  7 лет назад

      I think I did some demos on using Xbee radios . . .
      www.toptechboy.com/tag/xbee/

  • @top10games26
    @top10games26 7 лет назад

    I could not find servo librery

  • @8Kexperience
    @8Kexperience 8 лет назад

    How far an ultrasonic sensor can measure distance?

    • @paulmcwhorter
      @paulmcwhorter  8 лет назад

      +akaban01 Depends on the sensor. The simple ones are only good to about 9 feet.

    • @8Kexperience
      @8Kexperience 8 лет назад

      +Paul McWhorter Thanks for your reply. How about if I want to go longer like about 100 feet, should I use lidar then?

  • @goran586
    @goran586 8 лет назад +1

    How accurate are the measurements with this setup in terms of distance in mm?
    What is the maximum measurement sampling rate?

    • @renomcglay3957
      @renomcglay3957 8 лет назад

      paul ?

    • @mams2944
      @mams2944 8 лет назад +1

      Hello
      The sensor used in this tutorial is (Virtuabotix Ultrasonic Proximity Sensor) and the ranging accuracy is 3 mm, max distance 5m and min distance is 2cm and the realstic distance in door is 300m.

    • @sourodipbiswas2001
      @sourodipbiswas2001 7 лет назад

      Why am I getting zero distance on this code?! I searched help for online and saw the library of NewPing but still the problem is not solved. Please help....

  • @arvindh13
    @arvindh13 7 лет назад

    how to control a dc gear motor using ultrasonic sensor?

  • @bushrafarhat3798
    @bushrafarhat3798 6 лет назад

    thank you so much for the effective tutorials. I am trying to access your website today but it's not possible.Is there some glitch?

  • @evanator3165
    @evanator3165 9 лет назад

    How would I make the serial monitor show a picture of like a radar scanner if the servo was panning and the ultrasonic sensor was on the servo rotating.

    • @paulmcwhorter
      @paulmcwhorter  9 лет назад

      +iEvanator That is probably not going to be something you can do in the serial monitor. You could do really cool animations in Vpython. Watch my series of lessons on Python and Arduino. It will show you how to do what you want, just not in the serial monitor.

    • @evanator3165
      @evanator3165 9 лет назад

      +Paul McWhorter Ok thanks, I saw something like that but they were also using processing to make a radar thing pop up on their screen

  • @abhaysanillohith5925
    @abhaysanillohith5925 7 лет назад

    Dear Paul is it possible to make the target distance be read in centimetres because that is the unit of measurment we use in my country

    • @paulmcwhorter
      @paulmcwhorter  7 лет назад

      Yes, just do the conversion in arduino. It is one extra line of code.

  • @qamiellfirdaus321
    @qamiellfirdaus321 6 лет назад

    Guys can help me.. How to connect solar panel to arduino to funtioning the sensor using solar power..

  • @lilalila1376
    @lilalila1376 5 лет назад

    So we have to measure the speed of sound first right ?

    • @shabir301
      @shabir301 5 лет назад

      It's already calibrated by manufacturer under normal conditions.

  • @das250250
    @das250250 8 лет назад

    What resolution does it have mm ?

  • @bubunmazumder
    @bubunmazumder 8 лет назад

    Why do we write "pulseIn(variable,HIGH)"?can we write "pulseIn(variable,LOW)"?

    • @paulmcwhorter
      @paulmcwhorter  8 лет назад

      There are "high" pulses and "low" pulses. The color sensor puts out a high pulse, so that is what you need to measure.

  • @safugam
    @safugam 8 лет назад

    Plzz how i can measure long distance about 500 meter or more ??i

  • @saptangshumanna9919
    @saptangshumanna9919 7 лет назад

    Sir I wanted to ask that is the programming on an arduino uno is the same as in all the other arduinos like Leonardo, 101 or mega

    • @paulmcwhorter
      @paulmcwhorter  7 лет назад

      They are very similar . . . some have extra pins and ports, but overall they are very similar

    • @saptangshumanna9919
      @saptangshumanna9919 7 лет назад

      Thanks sir. I think I will buy an 101.

  • @tb2537
    @tb2537 7 лет назад

    this works whit pir?

  • @theodorefevoros4215
    @theodorefevoros4215 5 лет назад

    Hey Paul, I created a really awesome project on my Arduino Uno but then I wanted to make it smaller. So I made the exact same thing with the Arduino Nano but when I upload the code to the Arduino Nano It says problem uploading to the board. So I tried to install drivers but when I install drivers for serial port com 6 it says that the best drivers is already installed on my computer. Please tell me how I can get the code to upload to my Arduino Nano.
    Thanks so much.

  • @roboguru6178
    @roboguru6178 6 лет назад

    You can help me in this project?