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);
delay(6000);
}
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.