sfr05 Ultrasonic sensor random measurements when no surface is close

Good evening,

I’m working with a sfr05 4 pin ultrasonic sensor, to measure distances but i’m having trouble when the is no surface in front of the device (for example, pointing it to the open sky or a very farl wall). When the sensor is point to something close, the reading is accurate. But, when there is nothing infront of it it measures random values.

I’m wondering if some has run into the same problem
Code:

#include <NewPingESP8266.h>
#include <Adafruit_NeoPixel.h>
#define NUMPIXELS 1

const int PIN =13;

float duracion =0;
int iterations = 1;
float distance;

#define TRIGGER_PIN 14
#define ECHO_PIN 16
#define MAX_DISTANCE 400

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

NewPingESP8266 sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
// pinMode(ledPin, OUTPUT);
Serial.begin (9600);
pixels.begin();

pixels.setPixelColor(0, pixels.Color(255,0,0));
pixels.show();
delay(500);

pixels.fill((0,0,0));
pixels.show();
delay(500);

pixels.setPixelColor(0, pixels.Color(255,0,0));
pixels.show();
delay(500);

pixels.fill((0,0,0));
pixels.show();
}

void loop() {

duracion = sonar.ping_median(iterations);

distance = (duracion/2)*0.0343;

if (distance >= 180 || distance <= 10) {
Serial.println(“Out of range”);
pixels.fill((0,0,0));
pixels.show();
delay(10);
}
else {
Serial.print(distance);
Serial.println(" cm");
pixels.setPixelColor(0, pixels.Color(0,255,0));
pixels.show();
delay(10);
}

}

Thank you,
Camilo