title: Arduino Ultra Sonic Sensor always returns 0
body: <p>I am doing a basic project in <strong>Arduino UNO</strong> connecting an <strong>Ultra Sonic sensor</strong> (HC-SR04) which should print in the serial monitor the distance of the closest object but it always print 0.</p>
  
  <p>This is my code:</p>
  
  <pre><code>long distance;
  long time;
  
  void setup(){
    Serial.begin(9600);
    pinMode(4, OUTPUT); 
    pinMode(2, INPUT); 
  }
  
  void loop(){
    digitalWrite(2,LOW);
    delayMicroseconds(5);
    digitalWrite(2, HIGH);
    delayMicroseconds(10);
  
    time = pulseIn(4, HIGH);
    distance = int(0.017*time); 
  
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm.");
    delay(1000);
  }
  </code></pre>
  
  <p>And this is the breadboard:</p>
  
  <p><img src="https://i.stack.imgur.com/G4L2r.png" alt="enter image description here"></p>