Tutorial on Ultrasonic sensor HC-SR04 - Connections, interfacing & coding with Arduino

Поделиться
HTML-код
  • Опубликовано: 14 июл 2024
  • In this tutorial you will learn how to connect the ultrasonic sensor HC-SR04 OR ping OR range sensor to Arduino along with the coding part !
    00:00 - Intro
    00:19 - Requirements
    01:08 - Connections of ultrasonic sensor HC-SR04
    05:04 - Arduino Code for HC-SR04
    07:08 - Testing
    Code available here :-
    mechstuff.com/connection-inte...
    Like my page on Facebook :-
    MechStuff/?r...
    For more interesting mechanical news, engines & robotics stuff, visit my site - MechStuff ! ;)
    mechstuff.com/
  • НаукаНаука

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

  • @sudheerchakrawarti2636
    @sudheerchakrawarti2636 6 лет назад +5

    thanks sir ....you explained well.....

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

    Very good tutorial, simple and no winding talking. Code is short and easy to understand. Thank you very much for showing how to use the HC-SR04 sensor.

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

    great, thanks for helping me with my project

  • @alibishbishy6177
    @alibishbishy6177 7 лет назад +2

    thanks for that cool tutorial nice video

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

    Awesome bro thanks for the video ,i found it very useful

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

    Thanks bro it's very very useful

  • @kritimishra6715
    @kritimishra6715 5 лет назад +2

    Thanku sir...It will working😊

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

    it actually works. thankyou very much !!!

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

      Of course it works! ;)

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

    This video was really help full, thanks
    will subscribe

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

    It, s works very well thanks

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

    Really nice video

  • @RidZzGaming1
    @RidZzGaming1 5 лет назад +3

    Thank you man, very short code and helpful.

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

    thank you soo much sir......its working.

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

    you NAILED it.

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

    the fist working project i made with an ultrs soniuc sensor thanks a lot bro

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

      Great 👍

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

      Bro can u send me the code plz ??

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

    you are smart man ....continuous

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

    Really nice video you earned a sub from me! Thanks bhai

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

    very good explanation

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

    thanks boss.... u r great

  • @user-zq2mw2yv4s
    @user-zq2mw2yv4s 3 месяца назад

    First off, cool intro man 😂

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

    thank you bro! I'm Brazilian and you still help me!

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

    Thanks a lot it worked

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

    Really Good Work!!! Nicely Explained!!! Helped me in my Project!!! Thank you
    Also subscribed to you...

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

      Thanks and welcome 😉

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

    Thanks sir. This will help me with my project.

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

    thank you soo much man this is very short and helpful may GOD bless you !!

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

    Thanks, you teach me good, I am a beginner. And this video is helpful for me.

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

    thanks brother u saved my day...:)

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

    Thanks for nice video is simple but very helpful, if possible please make tutorial for new ultrasonic sr04t. Thanks

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

    thx!like ur vid

  • @ravichandransrinivasan5453
    @ravichandransrinivasan5453 4 месяца назад

    Very good to have a program without header files, as they are many and sometimes not compatible

  • @angel5wing
    @angel5wing 5 месяцев назад

    thank u so much

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

    You are godsent

  • @littlegamerzLTD
    @littlegamerzLTD Месяц назад

    ধন্যনাবাদ দাদা 😂😂😂😂😂😂😂😂😂😂😂😂😂🎉😂🎉🎉😂🎉🎉😂🎉😂🎉😂🎉😂😂🎉🎉😂🎉😂😂🎉🎉😂😂🎉😂🎉😂🎉😂🎉🎉😂😂🎉🎉😂😂😂😂😂😂😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊😂😊

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

    THANK YOU I COULDNT MAKE IT WORK NOW I CAN.

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

    keep it up

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

    superb

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

    tq. good vid

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

    Nice bro

  • @khyatiparikh2929
    @khyatiparikh2929 3 года назад +3

    accurate... man.... thank you so much
    please all subscribe him

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

    Thanks!

  • @lysnes_
    @lysnes_ 7 лет назад +9

    Thanks bro, you save my life!!!

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

    Thank u so much such wonderful experience

  • @GK-rr3fe
    @GK-rr3fe 5 лет назад

    output comes perfectly .i am expecting more videos from you

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

    can i say thanks for providing the video and also the code, most helpful

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

    THX MAN!!!!!

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

    thanks bro

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

    TNX u bhaiya

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

    Sir esi hi video Bana kar bhejte rahna

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

    can u tell me coding and diagram for ultrasonic blind stick gps tracking

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

    tq u save my life too..aleeeeeeeuuuuuuutoooooo muah

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

    good

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

    thanks bro ,it's works..

  • @songoku-oe4px
    @songoku-oe4px 7 лет назад +7

    A question if i want to connect a buzzer where would i go

    • @Flaretech.in_
      @Flaretech.in_ 3 года назад

      you can connect a buzzer instead of led ,the wiring is same

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

    you r doing great job bro

  • @Islamic_Quizzzz
    @Islamic_Quizzzz 2 года назад +2

    Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
    Sketch uses 3122 bytes (9%) of program storage space. Maximum is 32256 bytes.
    Global variables use 190 bytes (9%) of dynamic memory, leaving 1858 bytes for local variables. Maximum is 2048 bytes.
    An error occurred while uploading the sketch
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

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

    Very useful information, thank you. When I try this myself for my school project, the LED turns ON from the time the circuit is powered on. It does not wait till the sensor receives an input. What could be wrong? Please help!

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

    Thanks

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

    sorry..i got it.
    thank you.

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

    Thank you..

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

    thank you bro
    It's very helpful for beginners
    But, please upload more videos for arduino tutorial

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

      yes... sure... I had some technical problems... I'm gonna post videos soon.. Subscribe so that you'd come to know when I post them & stay tuned :)

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

    Hey, I just constructed the ultrasonic sensor and uploaded the code, but I have a problem. The pager motor I used for vibration keeps on vibrating, and the sensor doesn't detect any objects or distance. What should I do?

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

    Thanks! 😊

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

    Can you show the values that you are printing on the serial monitor??

  • @SangramJagtap996
    @SangramJagtap996 7 лет назад +2

    how to control pneumatic solenoid valve using ir sensor

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

    thanyou

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

    does the code also contains sms text message phone feature?

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

    Thank you so much bro!

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

    Thx, you helped me!

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

    Great tutorial. I can't find the HC-SR04 part for sale on the Arduino website, is this part still available?

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

      You can buy it in a very reasonable price from this link : botuniverse.in/index.php/product/hc-sr04-ultrasonic-sensor/

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

    This code for who found that the led stay on , this because you didn't clear the trigger , check the following code
    int trigger=9;
    int echo =10;
    void setup(){
    Serial.begin(9600);
    pinMode(trigger ,OUTPUT);
    pinMode(echo,INPUT);
    pinMode(7,OUTPUT);
    }
    void loop(){
    long duration,distance;
    digitalWrite(trigger ,LOW); //clears the trigger , else its not gonna measure more than one value
    delay(0.2);
    digitalWrite(trigger,HIGH);
    delay(0.1);
    digitalWrite(echo,LOW);
    duration=pulseIn(echo,HIGH);
    distance =(duration*0.034)/2;
    Serial.print(distance);
    Serial.println("CM");
    if(distance 10){
    digitalWrite(7,LOW);
    }
    delay(1);
    }

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

    I'm using an arduino provided by elegoo, i was working on a home security System as a school project. And i did somthing similar to what you did and everything works fine when i connect the ultrasonic sensor alone. However, when i add other sensors and motors a started getting wrong reading which turn on the alarm for no reason. What do you think is the problem?

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

      For those who has similar problem s, try using Relays with external output source and take the average of the sensor readings. The more readings you take the better but with more delay.
      That solved the problem for me. Hope it works for you

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

    bhai kya aap aisa border security system sensor bana sakate ho ki border ko kisi bhi kone ko touch kare udhar hi gun fire kare please mi replay

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

    can i modify this circuit for gps tracking and water and light senser blind stick???????

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

    bro can you upload a video about how to connect ultra sonic sensor with arduino and motor without any motor driver and diode and transistor

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

    Brother can you prepare obstacle avoiding robot with help motor shield

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

    Hi bro I want to do this project. Can u helpe

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

    nice explanation .can u upload how to dump programme into the aurdino so that i can complete my project

  • @1994grigala
    @1994grigala 7 лет назад

    thank

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

    Also for line 20, why do you have a * operator instead of a =?

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

    can you give me the link of the aduino

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

    Sir plz programming ka video banayeg

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

    Plz , make a video on 2.4" tft Screen

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

    please paste the code in the description

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

    Better to use different color wires to avoid confusions
    Overall i liked this video

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

    can you pls tell which software to use for coding and how to upload the program to the board.

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

    Bahiya ye mila kahan se apne khud program kiya ya example mai se liya hai

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

    Can we increase the distance of 10 centimetre ?

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

    sir if you want to add buzzer whats the code
    plz tell me sir

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

    What should i do if i want to set the distance on 1 meter or 1 centimeter ?

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

    Problem occurs when coding uploading to board...what can i do?

  • @tanishqsachinmandolkar9529
    @tanishqsachinmandolkar9529 4 месяца назад

    best

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

    I'm trying to transfer the distance I get from hc-sr04 sensors to thingspeak using Nodemcu. Only when measuring distance the sensors work very well but when I write the code to transfer the data to thingspeak or firebase the sensors work very slowly. What could be the reason for this? how can i fix it

  • @brandonb2201
    @brandonb2201 5 лет назад +4

    Nice tutorial! Instead of using a LED you can use the builtin LED on the arduino. Instead of int led just use the function LED_BUILTIN where you digital write.

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

    Bro pls give best buy link for aurdino

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

    Bro,what is 29.1 value stands for in distance formula

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

      It's the inverse of the speed of light in centimeters per microsecond units (see full explanation below) - i.e. 29.1 ~ 1 / 0.0343
      Let's use the following abbreviations and operations:
      S - speed
      D - distance
      t - time (or "duration" in the video)
      m - meters
      cm - centimeters
      s - second
      μs - microsecond
      * - multiplication operation
      / - division operation
      We know that the speed of sound is 343 m/s or 0.0343 cm/μs.
      Distance equation is: D = S*t
      Function "pulseIn()" returns the full time traveled by the sound in microseconds.
      Since we know the speed (the speed of sound) and time traveled ("duration" value returned by the "pulseIn()" function), we get D = 0.0343 * duration.
      We actually need only half of the distance because the "pulseIn()" function returns the time traveled to the object and back, but we need only the distance to the object.
      Hence, we divide the full distance traveled by the sound by two, and our distance to the object is equal to: 0.0343 * duration / 2.
      We can rewrite this as: (duration / 2) * 0.0343 or (duration / 2) / (1 / 0.0343)
      Since (1 / 0.0343) is equal to approximately 29.1, we get the distance to the object (in centimeters) equal to: (duration / 2) / 29.1

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

    Clear label sansor u can say

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

    Will the led not burn?

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

    how will you put code in ardino

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

    Very Good tutorial but you should given the circuit diagram also

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

      Please visit link in the description for the circuit diagram!

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

    very nice ,plz where to find the code