Arduino + HC-SR04

Arduino + HC-SR04


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:



    • Epilog X Contest

      Epilog X Contest
    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • PCB Contest

      PCB Contest

    4 Discussions


    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

    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(){
    pinMode(echoPin, OUTPUT);
    pinMode(triggerPin, INPUT);

    void loop(){
    digitalWrite(echoPin,LOW); //Inicia en bajo - start in Low
    digitalWrite(echoPin, HIGH); //Enviar el pulso Send the pulse
    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(" cm");

    I Hope help you, see you!!!


    3 years ago on Introduction

    This project excellently some one i made just view day before

    you can copy code from mine

    1 reply