loading

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.

<p>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.</p>
Hi This is the code:<br><br>/*<br>Descripci&oacute;n -Description: <br> Programa que permite leer la distacia entre un objeto y el sensor HC-SR04<br> Program allow read the distance between an object an sensor HC-SR04 <br>Version: 1.0<br>*/<br><br>int echoPin = 9;//Pin pulso ultrasonido - pin ultrasonic pulse<br>int triggerPin = 8;//Pin para tiempo rebote del ultrasonido - pin reboot time<br>long distancia;<br>long tiempo;<br><br>void setup(){<br> Serial.begin(9600);<br> pinMode(echoPin, OUTPUT);<br> pinMode(triggerPin, INPUT);<br>}<br><br>void loop(){<br> digitalWrite(echoPin,LOW); //Inicia en bajo - start in Low<br> delayMicroseconds(5);<br> digitalWrite(echoPin, HIGH); //Enviar el pulso Send the pulse<br> delayMicroseconds(10);<br> tiempo=pulseIn(triggerPin, HIGH);<br> /* Usando la formula para calcular la distancia como un valor entero <br> Se divide la distancia entre 2 porque solo necesitamos la de ida (0,034 cm/microseg)/2<br> Using the formula to calculate the distance as an integer<br> The distance between 2 is divided because we only need the round (0.034 cm / microseconds) / 2<br> */<br> distancia= int(0.017*tiempo);<br><br> //Imprimir valor - print value<br> Serial.print(&quot;Distancia &quot;);<br> Serial.print(distancia);<br> Serial.print(&quot; cm&quot;);<br> Serial.println(&quot;&quot;);<br> delay(1000);<br>}<br><br><br>I Hope help you, see you!!!
<p>This project excellently some one i made just view day before </p><p>you can copy code from mine https://www.instructables.com/id/Distance-measurement-using-Ultrasonic-sensor-and-A/</p>
<p>Thanks, I promise prove your code</p>

About This Instructable

1,035views

11favorites

License:

More by guschabal:Boxes for different things (screws, washers, nails) Deco Art Vodka Bottle Arduino + HC-SR04 
Add instructable to: