HC-SR04 sensor connected on custom shield does not provide any data when code is run

#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.

Please post the schematic for the entire circuit, not the PCB layout.

Verify all connections to the sonar unit by continuity check using a multimeter.

1 Like

what is a good continuity?

Good connection, with negligible resistance.

is a higher number more resistance?

I am getting a reading of 270

I am getting a reading of 270

Doing what, with what, and where?

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.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.