Ultrasonic sensor:
https://bit.ly/3eNsqrs

Recommended soldering iron- TS100:
https://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.

, https://i.ytimg.com/vi/Lx7KEaRLOU0/hqdefault.jpg

source

38 Comments

  1. Heres the code. Enjoy:

    #include <NewPing.h>

    #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);

    }

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

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

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

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

  6. Just wondering, I want to make one of these but I also want there to be a vibration motor in the circuit, but I want the vibration motor to only activate if anything gets 6 feet or closer to the sensor. How can I do this? Could you you also please explain what the schematic would look like (because I am not sure where the vibration motor would go)?

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

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

  9. how could i make it so that if the distance > 0, it does myservo.Write(90);

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

  11. 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

  12. 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
    }

Leave a Reply

Your email address will not be published. Required fields are marked *