problem with ultrasonic sensor

i have got some problems these are as follows

  1. when i connect my ultrasonic sensor to my arduino uno it automatically started working even when i dont uploaded any code i have tried to reset it using reset button but when i open serial monitor it started giving readings and RX led is continuously blinking.

  2. when i tried to upload using new ping library(INSTALLED) it is successfully uploaded but when open serial monitor it gives wrong readings and often it gives readings of 0 cm and it is too fast that i cant read them

some help from anyone will be appreciated

connections of ultrasonic sensor to uno
VCC-5V
GND-GND
TRIG-DIGITAL PIN 9
ECHO-DIGITAL PIN 12

/*
 * Posted on http://randomnerdtutorials.com
 * created by http://playground.arduino.cc/Code/NewPing
*/

#include <NewPing.h>
 
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
 
void setup() {
   Serial.begin(9600);
}
 
void loop() {
   delay(50);
   unsigned int uS = sonar.ping_cm();
   Serial.print(uS);
   Serial.println("cm");
}

THIS THE IS CODE THAT I WANT TO UPLOAD

THANK YOU

What's gone wrong
Even when I disconnect all pins of ultrasonic sensor from arduino uno clone (ch340g) it is giving wrong readings and very fast
Is this happening because of fault in my arduino uno
Plz let me know

Can anybody help me regarding this :cry: :cry: :cry:

delay(50);

Change the 50 to a higher number (500) to slow the ranging and printing. The delay() reference.

You need to let echos from previous pings to die down before initiating another ranging or you will get erroneous readings.

Thanks sir but how can I do the echos die

how can I do the echos die

Just wait a bit between pings. I usually wait 50ms to 100ms between readings, but I don't print every reading. I suggested 500ms because you wanted to slow the printing.