ARDUINO NANO + Ultrasonic sensor HC-SR04

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • This video is about Arduino tutorial Ultrasonic sensor HC-SR04
    Parts list
    - Arduino UNO R3
    - HC-SR04 ultrasonic sensor
    - jump wire
    Arduino Sketch : goo.gl/Vh5TKj
    ::::::::::: SUPPORT CHANNEL ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : goo.gl/1m8Dg2
    Don't forget to subscribe!

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

  • @JakubUrbanec
    @JakubUrbanec 3 года назад +25

    #include
    const int TriggerPin = 8;
    const int EchoPin = 9;
    long Duration = 0;
    int Delay_timer = 1000;
    void setup() {
    pinMode(TriggerPin, OUTPUT);
    pinMode(EchoPin, INPUT);
    Serial.begin(9600);
    }
    long Distance(long time){
    long DistanceCalc;
    DistanceCalc = ((time * 0.034) / 2); // centimeters
    return DistanceCalc;
    }
    void loop() {
    // put your main code here, to run repeatedly:
    digitalWrite(TriggerPin, LOW);
    delayMicroseconds(2);
    digitalWrite(TriggerPin,HIGH);
    delayMicroseconds(10);
    digitalWrite(TriggerPin, LOW);
    Duration = pulseIn(EchoPin,HIGH);
    long Distance_cm = Distance(Duration);
    Serial.print("Distance = ");
    Serial.print(Distance_cm);
    Serial.println (" cm");
    delay(Delay_timer);
    }

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

    Short, effective and straight to the point - thanks for the tutorial. Also, well commented code.

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

    i cannot get the code running because Distance was not declared onscope

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

    so when i plugged it in my computer disabled usb ports because it was using to much power and i unplugged everything and it still wouldnt work

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

    I was thinking about to download a library just to do this, but you just show me how easy is to make. Tks

  • @SKY53.
    @SKY53. 2 года назад +1

    Code:
    const int TriggerPin = 8; //Trig Pin
    const int EchoPin = 9; //Echo Pin
    long Duration = 0;
    void setup() {
    // Put 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);
    }
    void loop() {
    // main code:
    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); //Wait for the Echo Pin to get high
    //Return the duration in milliseconds
    long Distance_cm = Distance(Duration); //Use function to calculate the distance
    Serial.print("Distance = "); //output to serial
    Serial.print(Distance_cm);
    Serial.println(" cm");
    delay(1000); //Wait to do the next mesurement
    }
    long Distance(long time)
    {
    long DistanceCalc;
    DistanceCalc = ((time * 0.034) / 2); //Actual calcutatio in cm
    //Distance = time / 74 / 2 //Actual calcutatio in inces
    return DistanceCalc; //Return calculated value
    }

  • @kaganbaran-yz7bl
    @kaganbaran-yz7bl 2 года назад

    I used the same code but it didn't work. The program is giving errors in the code.

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

    can we attach a buzzer with this ??

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

    My code does upload but I cant see any calculations.

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

    link broken, now redirects to firewall scam page.

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

    Is it working for Nano i know İTS not a good question but i must do it

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

    Hi can u help me in my project plz plz plz . i had already made the project but mess in its codes

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

    can you make one code for my project chargeable basis. ..

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

    const int TriggerPin = 6; //Trig pin
    const int EchoPin = 5; //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 0utput
    }
    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("Distance = "); //0utput to serial
    Serial.print(Distance_cm);
    Serial.print(" cm");
    delay(1000); //Wait to do next measurment
    }
    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
    }

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

    what is pin 7 motor?

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

    What software are you using for circuit

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

    maximum meter ?

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

    Distance kitni hogi jisme ye work kre

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

    Can u please interface two ultrasonic sensors..one will send ping and other will recieve

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

      Why is your goal with trying to use two ultrasonic sensors ? It will works with only one.

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

    i cant access to sketch :(

  • @rohit._.editzs
    @rohit._.editzs Год назад

    Dual sensor kaise lagaye

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

    how to i gave this code

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

    It is only showing output as "Distance=0 cm".. That`s it value is not changing.. Plz help me

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

      I have the same problem. Did you ever get pass it?

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

      Same here

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

      ​@@marcelodive Conseguiu resolver?

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

      @@vinicius71999 , acho que era um problema utilizando "delay()" em outras partes do código, mas confesso que não lembro 100% como consegui resolver. Quer que eu dê uma olhada no meu código mais antigo?

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

      @@marcelodive Se puder, eu ficaria agradecido, estou com dois arduínos nano e dois sensores, acredito que não seja defeito

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

    Also explain how to execute plzz

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

      I mean the whole entire working part after writing the code

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

    Code plzzzzzz
    link not working

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

    send coding

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

    tell how

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

    please share code

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

    I will donate you 7000$

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

    I will give you $7,000 and tell me how