#include <NewPing.h>
#define TRIGGER_PIN 5
#define ECHO_PIN 4
#define MAX_DISTANCE 400 // Maximum distance we want to measure (in centimeters).
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(9600);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
int distance = sonar.ping_cm(); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
}
Yes, the connection is good, it is connected straight to 5v and gnd. Here is the pcb layout.
A valid connection between two points in a circuit should have resistance very close to zero Ohms, much less than 1 Ohm.
To be successful in this hobby, using a multimeter to read voltage, current, resistance and check circuit continuity is one of the very most basic of all needed skills.