EASY! Ultrasonic Sensor with Arduino

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2018
  • Ultrasonic sensor:
    bit.ly/3eNsqrs
    Recommended soldering iron- TS100:
    bit.ly/3e81eUD
    In this video, lets connect the HC-SR04 Ultrasonic sensor to our Arduino and learn how to code the ultrasonic sensor. We also learn how to run the sensor.
    The ultrasoinc HC-SR04 sensor can be used to make obstacle avoidance robots, or ultrasonic radar or other ultrasonic arduino projects.
    This tutorial for the HC-SR04 sensor should teach you how to code easily and build your arduino projects.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 130

  • @Fungineers
    @Fungineers  5 ปีที่แล้ว +53

    Heres the code. Enjoy:
    #include
    #define TRIGGER_PIN 10
    #define ECHO_PIN 11
    #define MAX_DISTANCE 20
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
    void setup() {
    Serial.begin(9600);
    delay(50);
    }
    void loop() {
    Serial.print("Distance is:" );
    Serial.println(sonar.ping_cm());
    delay(1000);
    }

    • @yousefadel6874
      @yousefadel6874 5 ปีที่แล้ว +2

      can i make NewPing sonar1 and NewPing sonar2 and so on if i want to use more than 1 sesnor ?

    • @AbdulKarim-fs5iw
      @AbdulKarim-fs5iw 5 ปีที่แล้ว

      Yes, just make sure u input right pin ids
      Examples>sensors>ping has more elaborate code..

    • @harsh....8993
      @harsh....8993 4 ปีที่แล้ว +7

      Code is wrong

    • @abdullahsalem3695
      @abdullahsalem3695 2 ปีที่แล้ว

      Thank you for your effort

    • @xeither289
      @xeither289 2 ปีที่แล้ว

      JESUS IS THE KING OF THE KINGS

  • @jubilantstudios
    @jubilantstudios ปีที่แล้ว +3

    I keep returning to this video since it seems to always answer my questions!!!! Thankyou so much for making this content.

  • @oneoverall5100
    @oneoverall5100 7 หลายเดือนก่อน

    hi, what program did you use to make the circuit?

  • @leonardomtorres6858
    @leonardomtorres6858 ปีที่แล้ว +3

    Thanks! I didn't know about this library and it just saved me a LOT of work

  • @FlooferLand
    @FlooferLand 3 ปีที่แล้ว +14

    Thank you for not making people have to input in weird math to get a simple sensor working like every other tutorial

    • @nikolaisavulkin149
      @nikolaisavulkin149 2 ปีที่แล้ว

      Well tbf - that only makes it useful for Arduino. I hoped i could get some details allowing me to make it work in my ecosystem which is a bit more niche. I did find this tutorial useful but that "weird math" in fact would also be highly appreciated

    • @DiegoSita
      @DiegoSita ปีที่แล้ว

      What's wrong with the math? It's just stuff you should have learned in High School.

  • @matts8023
    @matts8023 2 ปีที่แล้ว +12

    Substantially better than other tutorials, thank you for making this!

  • @filchaneco506
    @filchaneco506 2 ปีที่แล้ว +2

    sir what application did you use in 3:17 to show connection of each components? thanks

  • @courtneyfleming1
    @courtneyfleming1 4 ปีที่แล้ว +1

    What 3d program did use to demonstrate?

  • @Jad042
    @Jad042 2 ปีที่แล้ว +4

    Amazing, thanks for showing this library :)

  • @gravyboatdrone4060
    @gravyboatdrone4060 3 ปีที่แล้ว

    Hi, great video. Do you know how to get it to work with Arduino Nano Everyday? Thanks

  • @trevor18ut
    @trevor18ut 4 ปีที่แล้ว

    Can the Echo pin be connected to Encoder IC HT12E pin 10 as an input signal.

  • @Knekovp
    @Knekovp 2 ปีที่แล้ว +1

    thank you ! finally a library that improve the accuracy XD

  • @conversationwithgod272
    @conversationwithgod272 3 ปีที่แล้ว +2

    great job...very clear explanation.thanks.

  • @mariusberisha1015
    @mariusberisha1015 ปีที่แล้ว

    Can we use this method for underground scan? Metal, gold etc..?

  • @evolution2030
    @evolution2030 2 ปีที่แล้ว

    Can you let me know of the components you used in the video.

  • @markbarnes6012
    @markbarnes6012 2 ปีที่แล้ว +4

    I get alot more from your video you don't just run thru it thank you

  • @johnm6866
    @johnm6866 ปีที่แล้ว

    Is it possible to get to 200 khz with arduino or a similar setup?

  • @johnx9318
    @johnx9318 2 ปีที่แล้ว +2

    Great tutorial - thanks!

  • @raymi9612
    @raymi9612 2 ปีที่แล้ว +1

    Excellent. Thanks for the help!

  • @smoshfann24
    @smoshfann24 3 ปีที่แล้ว +2

    This was perfect thanks

  • @LaughN.
    @LaughN. 2 ปีที่แล้ว

    How can I hook up a led so that it blinks when I send a signal to the ultrasonic sensor?
    Thanks in advance

  • @moyzahmed4666
    @moyzahmed4666 ปีที่แล้ว

    thnks alot the library you mentioned was amazing.....

  • @nikigeek1008
    @nikigeek1008 2 ปีที่แล้ว

    this library has made so easy

  • @abusamraaslan3157
    @abusamraaslan3157 11 หลายเดือนก่อน

    hello I did the same but I keep getting 0cm as a readings should I buy a new sensor?

  • @ipanjohur3691
    @ipanjohur3691 2 ปีที่แล้ว

    Can I use ARDUINO UNO for this Project? It is same codes that you used sir?

  • @yousefadel6874
    @yousefadel6874 5 ปีที่แล้ว +4

    Awesome video as always , can you make a video for LCD and keypad ?

  • @oscarmensink3252
    @oscarmensink3252 ปีที่แล้ว +1

    What application did you use to draw your schematic?

  • @John_Wick26
    @John_Wick26 10 หลายเดือนก่อน

    Wow, This made me impressed. C++ Beginner here, Thank you.

  • @supergamer-mj9ki
    @supergamer-mj9ki 3 ปีที่แล้ว

    thank you very much bro
    god bless you

  • @raedasmeheen6543
    @raedasmeheen6543 ปีที่แล้ว

    Excuse me, I want to make 2 ultrasonic for the length, 2 for the width, and 1 for the height. Can you do it for us?

  • @antonramesh
    @antonramesh ปีที่แล้ว

    i done this project its works thank you

  • @scoopiezz
    @scoopiezz 9 หลายเดือนก่อน

    Good video!

  • @rossferguson8119
    @rossferguson8119 3 ปีที่แล้ว

    Can you send me the parts list for this please?

  • @BrysonB-pp7yo
    @BrysonB-pp7yo 2 ปีที่แล้ว

    How could I make it where when the ultra sonic sensor detects something it plays aduio

  • @wardope
    @wardope ปีที่แล้ว +1

    i actually used these around the house for various home automation

  • @TG0196
    @TG0196 2 ปีที่แล้ว +1

    What i do if i want an LED to turn on if distance

  • @ellohemelat8496
    @ellohemelat8496 4 ปีที่แล้ว

    amazing video.
    but would u give the link of the 3D Software u did it, please!!!!!!

    • @Fungineers
      @Fungineers  4 ปีที่แล้ว

      Its the Arduino serial monitor

    • @rdx9105
      @rdx9105 3 ปีที่แล้ว

      www.arduino.cc/en/software
      to download the software

  • @nsgalpha5215
    @nsgalpha5215 4 ปีที่แล้ว

    i cant get NewPing to work is there a way i can copy and paist

  • @MrMic18650
    @MrMic18650 2 ปีที่แล้ว

    What chip is that?

  • @dudeWhoLikesBasketball
    @dudeWhoLikesBasketball 3 ปีที่แล้ว +1

    thanks, it was really helpful

  • @samarthagrawal7001
    @samarthagrawal7001 ปีที่แล้ว

    thankyou
    now i will get easily

  • @embeddedmicrocontroller
    @embeddedmicrocontroller 3 ปีที่แล้ว

    Good introduction

  • @amanath5853
    @amanath5853 2 ปีที่แล้ว

    how can I code it in Arduino Uno R3

  • @johnmberi5045
    @johnmberi5045 ปีที่แล้ว

    beautiful demo, woo

  • @Aristophales18
    @Aristophales18 3 ปีที่แล้ว +1

    wow I am a kid of 9 years old and I enjoy this, keep the good work up

    • @Fungineers
      @Fungineers  3 ปีที่แล้ว

      Keep learning and start doing some stuff now :)

    • @adamhall7077
      @adamhall7077 3 ปีที่แล้ว +1

      If you understood all of that then oh my you are smart.

  • @abhigyan6820
    @abhigyan6820 ปีที่แล้ว

    How to fix 'sonar' was not declared in this scope

  • @thigaming7879
    @thigaming7879 ปีที่แล้ว

    why when i upload it it say compilation error:NewPing.h No such file or directory ?

  • @Manche-De-Pelle
    @Manche-De-Pelle หลายเดือนก่อน

    Thanks for sharing. I wanna do this project but when there's something into the range of 20cm it will send an alert/email to my cellphone... I've bought wemos d1 r32 for that project but I'm totally clueless on how to do it
    If someone can help me that would be appreciated

  • @Mygames108
    @Mygames108 11 หลายเดือนก่อน

    Thank you

  • @mohdshoibsir4501
    @mohdshoibsir4501 ปีที่แล้ว +1

    very helpful video

  • @onimusa4244
    @onimusa4244 3 ปีที่แล้ว

    Max distance?

  • @jarvisjnr2.o467
    @jarvisjnr2.o467 2 ปีที่แล้ว

    ningal oru killadi thenna 😌

  • @knowledge_seeker80
    @knowledge_seeker80 ปีที่แล้ว

    after long research we have a new technology to send data over dc lines so no need to connect 4 wires of ultrasonic module just use same dc line between module and MCU to supply module & get data

  • @auroranisha4435
    @auroranisha4435 3 ปีที่แล้ว +1

    Can we use Arduino nano instead of Arduino uno

    • @adityachaudhary4528
      @adityachaudhary4528 3 ปีที่แล้ว

      Yess ! Connect echo and trig to two digital pins e.g D2 and D3 and connect VCC and GND

  • @TheDankDev
    @TheDankDev 3 ปีที่แล้ว

    Thank you great video!

  • @mohdshoibsir4501
    @mohdshoibsir4501 ปีที่แล้ว

    thanks you brother

  • @eyesonice8545
    @eyesonice8545 4 ปีที่แล้ว +10

    const int TriggerPin = 8; //Trig pin
    const int EchoPin = 9; //Echo pin
    long Duration = 0;
    void setup() {
    // put your setup code here, to run once:
    pinMode(TriggerPin,OUTPUT); // Trigger is an output pin
    pinMode(EchoPin,INPUT); // Echo is an input pin
    Serial.begin(9600); // Serial Outpu
    }
    void loop() {
    // put your main code here, to run repeatedly:
    digitalWrite(TriggerPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TriggerPin, HIGH); // Trigger pin to HIGH
    delayMicroseconds(10); // 10us high
    digitalWrite(TriggerPin, LOW); // Trigger pin to HIGH
    Duration = pulseIn(EchoPin,HIGH); // Waits for the echo pin to get high
    // returns the Duration in microseconds
    long Distance_cm = Distance(Duration); // Use function to calculate the distance
    Serial.print("Vzdálenost = "); // Output to serial
    Serial.print(Distance_cm);
    Serial.println(" cm");
    delay(1000); // Wait to do next measurement
    }
    long Distance(long time)
    {
    long DistanceCalc; // Calculation variable
    DistanceCalc = ((time * 0.034) / 2); // Actual calculation in cm
    //DistanceCalc = time / 74 / 2; // Actual calculation in inches
    return DistanceCalc; // return calculated value
    }

    • @bahadralperen3565
      @bahadralperen3565 10 หลายเดือนก่อน

      Thaks bro ! I have a question Why duration is 0(zero) ?

  • @cfzone8685
    @cfzone8685 5 ปีที่แล้ว

    Can you make a video showing how to program a robot with Arduino code?

    • @Fungineers
      @Fungineers  5 ปีที่แล้ว

      There are so many things in the pipeline. Robots are definitely in my mind :)

  • @ikesboxxes4040
    @ikesboxxes4040 ปีที่แล้ว

    when i type newping it doesnt work anytips?

  • @devrajjadhavrao6138
    @devrajjadhavrao6138 5 ปีที่แล้ว

    Awesome Video

  • @Fixy15
    @Fixy15 10 หลายเดือนก่อน

    GND is turning off my arduino. What causes the problem?

  • @_zsebtelep8502
    @_zsebtelep8502 ปีที่แล้ว

    Is it possible to scale it up to 10m ?

    • @olegi5854
      @olegi5854 ปีที่แล้ว

      no maximum 200 cm maybe

  • @jacksonconley5117
    @jacksonconley5117 ปีที่แล้ว +1

    What’s the command for inches? You could of at least told us the name.

  • @ngkean9743
    @ngkean9743 2 ปีที่แล้ว

    Why does it read 0 too when you hand is sensed?

  • @komaneshatadi9421
    @komaneshatadi9421 ปีที่แล้ว

    Can l get the names of the materials used here pls it's urgent

  • @KIMKim-ql8zx
    @KIMKim-ql8zx 6 หลายเดือนก่อน

    Thanks.

  • @sanjeevbansal7669
    @sanjeevbansal7669 3 ปีที่แล้ว

    Easy explained

  • @xinniethep00h
    @xinniethep00h ปีที่แล้ว

    Anyone know what software is that at 3:16?

  • @pickygaming3136
    @pickygaming3136 2 ปีที่แล้ว

    it says newping.h is not a file or directory

  • @paperwelder
    @paperwelder 4 ปีที่แล้ว

    Can you have 2 sensors Nd one sends the signal the other one receives and you can track the transmitter. I'm trying to make a game with my son where I can find him by tracking him where he's hiding

    • @Fungineers
      @Fungineers  4 ปีที่แล้ว

      Each sensor has 2 units. Receiver and transmitter like I showed.

    • @paperwelder
      @paperwelder 4 ปีที่แล้ว

      I'm basically asking can this be made by Using this sensor th-cam.com/video/a_U724jTPWI/w-d-xo.html

  • @toxicscope8703
    @toxicscope8703 3 ปีที่แล้ว +1

    ITS NOT WORKING BC IT SAYS NewPing.h No such file or directory plz help

    • @neeyo7631
      @neeyo7631 3 ปีที่แล้ว +3

      download the library google NewPing.h and import the library into Arduino

  • @tomyam88
    @tomyam88 ปีที่แล้ว +1

    Great video,! Thanks for sharing 👍🏻

  • @dudeWhoLikesBasketball
    @dudeWhoLikesBasketball 3 ปีที่แล้ว

    👍

  • @chibuzordesmond3937
    @chibuzordesmond3937 ปีที่แล้ว

    Accurate!

  • @ranabiswas2266
    @ranabiswas2266 3 ปีที่แล้ว +2

    Hello sir,, can u please make a video with perfect code.. And ardino uno,,ultra sonic sensor and servo motor... Combined working mechanism..

    • @ecit
      @ecit 3 ปีที่แล้ว

      This is the video of my RADAR project with ultrasonic sensor and servo motor : th-cam.com/video/bj1nxubM8IQ/w-d-xo.html (I hope it is helpful for you)

  • @Hazmatan
    @Hazmatan 4 ปีที่แล้ว +2

    Hello! Thank you for the video but mine keep displaying a message like this: " f⸮~⸮⸮fxf⸮~⸮⸮fx" What im doing wrong?

    • @ecit
      @ecit 3 ปีที่แล้ว

      Check your LCD pin connections

    • @adityachaudhary4528
      @adityachaudhary4528 3 ปีที่แล้ว +1

      Set baud rate of serial monitor correct ! Mostly it is 9600

  • @amitasrivastava219
    @amitasrivastava219 2 ปีที่แล้ว

    What could be the maximum Distance it can sense

  • @braam828
    @braam828 ปีที่แล้ว

    It doesn’t work for me

  • @neodonut1279
    @neodonut1279 ปีที่แล้ว

    7:56 words for life.

  • @riojustineagustino8264
    @riojustineagustino8264 2 ปีที่แล้ว

    Is there a sensor that automatically releases water when plants are detected

  • @wiserguest1238
    @wiserguest1238 ปีที่แล้ว

    NewPing's broken.

  • @charansworld469
    @charansworld469 3 ปีที่แล้ว +1

    But it's only showing distance 0

    • @shadiaalhyari3811
      @shadiaalhyari3811 3 ปีที่แล้ว +1

      @Dash did you fix it ? mine is also showing only 0 !

    • @jacksonconley5117
      @jacksonconley5117 ปีที่แล้ว +2

      You have to put something in front of the sensor at a distance of less than 20 cm.

    • @lenny56050
      @lenny56050 ปีที่แล้ว +1

      @@jacksonconley5117 but it's still isn't working

    • @lenny56050
      @lenny56050 ปีที่แล้ว +1

      only showing o cm

  • @xeither289
    @xeither289 2 ปีที่แล้ว

    LOVE GOD AND EVERYONE!!!

  • @user-bb7xy9cq2g
    @user-bb7xy9cq2g ปีที่แล้ว

    #include
    int data ;
    int led1 = 2;
    int led2 = 4;
    NewPing sonar (10 ,11 ,100);
    void setup()
    {
    Serial.begin(9600);

    }
    void loop()
    {
    Serial.print("distance is : ");
    data=(sonar.ping_cm());
    Serial.println(data);

    if(data0){
    digitalWrite(led1 , 1);
    digitalWrite(led2 , 0);
    }
    else{
    digitalWrite(led2 , 1);
    digitalWrite(led1 , 0);

    }

    }

  • @WAQASJOGI
    @WAQASJOGI 5 ปีที่แล้ว

    😎😎😎😎 niiicceee

  • @Fungineers
    @Fungineers  5 ปีที่แล้ว

    Trying to keep these videos under 5 mins :(

    • @joseb6068
      @joseb6068 4 ปีที่แล้ว

      hey i have a error can you please help?
      this is my code.i wrote it exactly like you and installed the library.
      but it shows an error called :"expected initializer before 'sonar' "
      my code :
      #include
      int trigpin=9;
      int echopin=8;
      int
      NewPing sonar (trigpin,echopin,20);
      void setup() {
      Serial.begin(9600);
      delay(50);
      }
      void loop() {
      Serial.print("Distance is:" );
      Serial.println (sonar.ping_cm());
      delay(1000);
      }
      pls help me as soon as u can.:((

  • @xeither289
    @xeither289 2 ปีที่แล้ว

    ❤❤☦❤☦☦😊

  • @dkoorse
    @dkoorse ปีที่แล้ว

    Hello. Tutorial not work. You Bad, but one Kebab please, with baraninka

  • @xeither289
    @xeither289 2 ปีที่แล้ว

    GOD IS REAL!!!

  • @xeither289
    @xeither289 2 ปีที่แล้ว

    JESUS IS THE KING OF THE KINGS!!!