Problems with HC-SR04 and ESP-32

hello I am beginer and my esp32 suddenly started crashing or what so could you please help me.
here is the code

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-hc-sr04-ultrasonic-arduino/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

const int trigPin = 5;
const int echoPin = 18;

//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

void setup() {
  Serial.begin(115200); // Starts the serial communication
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}

void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance
  distanceCm = duration * SOUND_SPEED/2;
  
  // Convert to inches
  distanceInch = distanceCm * CM_TO_INCH;
  
  // Prints the distance in the Serial Monitor
  Serial.print("Distance (cm): ");
  Serial.println(distanceCm);
  Serial.print("Distance (inch): ");
  Serial.println(distanceInch);
  
  delay(1000);
}

here is the crash mesage

19:53:48.815 -> ets Jul 29 2019 12:21:46
19:53:48.815 -> 
19:53:48.815 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
19:53:48.815 -> flash read err, 988
19:53:48.815 -> ets_main.c 384

All this code is from random nerd tutorials.
Thanks for the efort this forum will put into this.

That appears to be boot-up messages and all the same time stamp. It looks like maybe the boot flash has been damaged. Static can do that, I think. I would grab another board and see how it does, being careful to wear a ground strap attached to ground.

Is there somerhing I could do to prevent this next time?

looking at esp32-pinout-reference-gpios pin 5 is a strapping pin used at boot time
generally it is a good idea to avoid strapping pins

if you remove the HC-SR04 and try a simple program such as blink can you then load and run?

Yes even if I disconnect the HC-SR04 it returns zeros to the serial monitor

if the program starts but returns 0's try moving the trigger to a different pin

I tried pins 22 (triger) and 21 (echo). I also tried diferent code that used pin 4 (echo and trigger were connected)

The HC-SR01 is a 5V device, make sure you're feeding it with 5V (Randon Nerd Tutorials uses Vin pin of an ESP32 board that is fed by USB, which means 5V).

In the example of their site, the connections are xcrossed:

make sure when making the circuit that you have connected the trigger to pin 5 and the echo to Pin 18, or whatever other pins you want to use (that are not strapping pins preferably).

I think that i wired it corectly
but here are some photos and thanks again for help everyone




Thanks for the pics. It helps a lot!

I don't think so...

The pin next to 5V is not GND. Is CND. You need to move this black wire to a GND.

thanks a lot @Brazilino :joy:

You're welcome! Have fun! :upside_down_face:

Could you guys please look at my other project? I need to know whats wrong with it.
Name is: ESP-NOW and a server problem.

Sorry, I have already used ESP-NOW protocol, but I have almost no knowledge on web servers. :man_shrugging:

Okey😢