Proximity Sensor Serial Monitor Issue

Serial Monitor stops working after a couple distance readings.

#define echoPin 7
#define triggerPin 10

void setup() 
{

Serial.begin(115200);
pinMode(echoPin, INPUT);
pinMode(triggerPin, OUTPUT);

}

void loop() 
{

Serial.print("The distance is:    ");

digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);

int distance = pulseIn(echoPin, HIGH);

distance =distance/58 ;

Serial.print(distance, DEC);
Serial.println(" cm");
delay(500); 

}

The distance is: 6 cm m The distance is: 6 cm The distance is: 6 cm The distance is: 6 cm e distance is: 6 cm The distance is: 6 cm The distance is: 6 cm The distance is: 6 cm The distance is: 6 cm Y!⸮0⸮00⸮0p11⸮d⸮0Y⸮⸮⸮@⸮!p1d⸮Y!0⸮ x1X!D⸮ p⸮⸮@p10⸮d⸮0⸮D⸮Y⸮⸮0⸮Y⸮⸮1⸮D⸮Y!⸮1⸮

I tried your code with my Uno and a known good HCSR04. It ha been working fine for several minutes, now.

So it is not the code. Please describe your setup. Have you tried a different rangefinder? Is the 5V power supply stable?

Kudos for using code tags on your first post.

I fixed it by changing the Serial.begin to (9600*)

JGC: I fixed it by changing the Serial.begin to (9600*)

Why snail's pace? Switch the serial monitor to 115200 instead.

You may have a bad USB cable or something. I have been running your code at 115200 with no problems.