Problems with sensor reading! Please help

I'm using the HC-SR04 Ultrasonic Sensor, with the 'NewPing' library.

#include <NewPing.h>

#define TRIGGER_PIN  7
#define ECHO_PIN     6
#define MAX_DISTANCE 500
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup()
{
Serial.begin(9600);
}

void loop()
{
  int uS = sonar.ping();
  int distance = uS / US_ROUNDTRIP_CM;
  
  Serial.println(distance);
  if(distance > 20)
  {
   ACTION
   }
}

When i open Serial Monitor, i see that most of the readings are fair incorrect, for instance, when i get closer to the sensor it shows 196 cm, and when i go away it shows 21cm.

But when i have ONLY the sensor on the code, without the "action", it works normally.

What is going on? Can my "action" (which is a led to turn on), be affecting the readings of my sensor?

if(distance > 20)
  {
   ACTION
   }

That's going to cause problems with compilation.

The "ACTION" is to turn on a led...

But that macro is missing from your original post.
(There doesn't seem to be a way of turning the LED off)

Because that's not the part i'm having problems, the readings of the sensor are wrong...

Well, perhaps if you posted your actual code and some of the results . . .
Maybe your power supply isn't up to the job.
Who can tell?