Can't get new ping to read anything

Hey there. I’m using a simple HC-SR04 sensor and the new ping library from this thread: How to add NewPing.h libary on Particle cloud ide?

Issue: Can’t get the sensor to read anything. Code verifies and uploads. My sensor is wired as such: GND to ground, VCC to VIN, ECHO to 6, TRIGGER to 2.

But of course, nothing works. My system is 1.0.0 I’m using a particle photon. I can get the
HC_SR04 library to work, but I’m confused why this one does not work. Any thoughts?

#include <NewPing.h>

#define TRIGGER_PIN   2       // Arduino pin tied to trigger pin on ping sensor.
#define ECHO_PIN      6       // Arduino pin tied to echo pin on ping sensor.
#define MAX_DISTANCE 200       // Maximum distance we want to ping for (in centimeters). 6 feet = 180  4 feet = 120 7 feet = 210

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)


I have tried your code (although using TRIGGER_PIN D0 & ECHO_PIN D1) and for me it works.

Oh that’s odd. Is it hard coded into the lib or something?

Nope, I just used these pins as they were easiest to access

Hmm. that’s really weird. What happens if you use different pins? I know it sounds odd, because it shouldn’t matter, but stranger things have happened.

I use the NewPing library with the C0/C1 and C4/C5 pins (Electron) :slight_smile:

As it seems D6 is not a good choice for the echo pin. When I use D6 I also don’t get any readings.
But I’ll keep testing