Arduino + HC-SR04

Arduino + HC-SR04

assembling

Step 1: Video

This projects consists to use the HC-SR04 sensor with Arduino.

This sensor can be used to measure distances or overcome obstacles.

How this happend?

Well, one transducer send a ultrasonic signal , an the other waits for captured the signal when return.

Let's get started!

Step 2: Required Hardware

  1. Arduino
  2. Sensor HC-SR04
  3. Wires
  4. Breadboard
  5. Rule

Step 3: Circuit

This same diagram created with Fritzing was as connect all circuit.

The sensor consists of 4 pins:

  1. "VCC" connected to the output of 5V.
  2. "Trig" connected to digital pin board responsible for sending the ultrasonic pulse.
  3. "Echo" to the digital input pin to receive the echo said pulse.
  4. "GND" grounded.

Step 4: Code

The code has the explanation how the signal is obtained.

Step 5:

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Optics Contest

      Optics Contest

    4 Discussions

    0
    None
    thomcomstock

    2 years ago

    Where is the code in this instructable? I see only two photos below Step 4: Code with one containing only a part of the sketch.

    1 reply
    0
    None
    guschabalthomcomstock

    Reply 2 years ago

    Hi This is the code:

    /*
    Descripción -Description:
    Programa que permite leer la distacia entre un objeto y el sensor HC-SR04
    Program allow read the distance between an object an sensor HC-SR04
    Version: 1.0
    */

    int echoPin = 9;//Pin pulso ultrasonido - pin ultrasonic pulse
    int triggerPin = 8;//Pin para tiempo rebote del ultrasonido - pin reboot time
    long distancia;
    long tiempo;

    void setup(){
    Serial.begin(9600);
    pinMode(echoPin, OUTPUT);
    pinMode(triggerPin, INPUT);
    }

    void loop(){
    digitalWrite(echoPin,LOW); //Inicia en bajo - start in Low
    delayMicroseconds(5);
    digitalWrite(echoPin, HIGH); //Enviar el pulso Send the pulse
    delayMicroseconds(10);
    tiempo=pulseIn(triggerPin, HIGH);
    /* Usando la formula para calcular la distancia como un valor entero
    Se divide la distancia entre 2 porque solo necesitamos la de ida (0,034 cm/microseg)/2
    Using the formula to calculate the distance as an integer
    The distance between 2 is divided because we only need the round (0.034 cm / microseconds) / 2
    */
    distancia= int(0.017*tiempo);

    //Imprimir valor - print value
    Serial.print("Distancia ");
    Serial.print(distancia);
    Serial.print(" cm");
    Serial.println("");
    delay(1000);
    }


    I Hope help you, see you!!!

    0
    None
    ZakariyeA

    3 years ago on Introduction

    This project excellently some one i made just view day before

    you can copy code from mine https://www.instructables.com/id/Distance-measurement-using-Ultrasonic-sensor-and-A/

    1 reply