How to measure distance with an Arduino and Ultrasonic Sensor // HC-SR04

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ค. 2024
  • In this video I will show you a relatively accurate way to measure distance using and Arduino and an HC-SR04 ultrasonic sensor. I will walk you through the theory, setup, and coding using an Arduino.
    The following are affiliate links for products that I use in this video. Purchases through these links will result in no increase in price for you, but may result in a small commission for me. These commissions will help me continue to make informative and entertaining videos such as this one. Thank you for your support and thanks for watching!
    HC-SR04 Ultrasonic Sensor ebay.to/36ZAYva
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    For people who are lazy
    const int triggerPin = 9;
    const int echoPin = 10;
    float pulse_width, distance;
    void setup() {
    // put your setup code here, to run once:
    pinMode(triggerPin, OUTPUT);
    pinMode(echoPin, INPUT);
    Serial.begin(9600);
    digitalWrite(triggerPin, LOW);
    delayMicroseconds(2);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    digitalWrite(triggerPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(triggerPin, LOW);
    pulse_width = pulseIn(echoPin, HIGH);
    distance = (pulse_width*.343)/2;
    Serial.print("Distance = ");
    Serial.println(distance);
    Serial.println(" cm");
    delay(500);
    }

  • @ybasyionnamishka8773
    @ybasyionnamishka8773 2 หลายเดือนก่อน

    will this work on infrared sensor?

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

      I haven't used infared sensors, so I couldn't tell you for sure. Sorry!

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

    will this project work with arduino nano ??

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

      Yes. Arduino UNO and NANO use the same pinouts, so the code switches over nicely.

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

    Hello sir...i really appreciate your videos....I would like to know if I can contact you thru email? I would like to ask some advice regarding my project....from the 🇵🇭🇵🇭🇵🇭...thank you in advance...