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)
Serial.println("cm");
}
Thanks.