Keep on getting -1 as a reading when trying to send info from an SR04 sensor to thingspeak

so i am having trouble with the ultra sonic sensor SR04 because when i try to send thingspeak data it only gets -1. im not sure why so here is my code:

// This #include statement was automatically added by the Particle IDE.
#include "HC_SR04/HC_SR04.h"

int distance = 0;

int cm;

int trigPin = D2;
int echoPin = D6;

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);

void setup() 

void loop() 
    distance = rangefinder.getDistanceCM();
   cm = distance;
    Particle.publish("ultra_sensor_test", String(cm), 60, PRIVATE);

im not sure why i keep getting -1 as reading. i have the wiring correct and the ultra sonic sensor works fine. if anyone could help that would be great. thank you.

For some reasion this condition evaluates to true

  if (distance < _minCM || distance > _maxCM){
   return -1;

where these are the limits

  _minCM = 10.0;
  _maxCM = 250.0;

As ScruffR pointed out, make sure you are taking measurement within the Default Range of 10cm to 250 cm.

I believe You can also change this range with the following line before Setup()

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin, 5.0, 500.0);

I found (and use) code for my JSN SR04 that doesn’t use a Library. It performs great, but the actual minimum distance I can reliability measure is 11 inches with this sensor. Let me know if you want to try it.