Introduction: Arduino + HC-SR04

Picture of 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

Picture of Required Hardware

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

Step 3: Circuit

Picture of 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

Picture of Code

The code has the explanation how the signal is obtained.

Step 5:

Picture of


thomcomstock (author)2016-02-29

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.

guschabal (author)thomcomstock2016-03-02

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!!!

ZakariyeA (author)2015-09-01

This project excellently some one i made just view day before

you can copy code from mine

guschabal (author)ZakariyeA2015-09-02

Thanks, I promise prove your code

About This Instructable




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