Standalone Operation using SparkFun_APDS9960.h using power supply, without serial connection to PC

Hello! I bought an uno and a sensor. I connected the sensor to the arduino and use just a power-supply (5V) to get data without connecting the uno board to pc(Standalone Operation). As com port is connected to PC everything works fine while by disconnecting things go wrong. Here is my code:

#include <Wire.h>
#include <SparkFun_APDS9960.h>
 
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint16_t ambient_light = 0;
uint16_t red_light = 0;
uint16_t green_light = 0;
uint16_t blue_light = 0;
int pushButton = 8;
 
void setup() {
  pinMode(pushButton, OUTPUT);
 
  if (apds.init()) {
    apds.enableLightSensor(true);
  }
  
 
  delay(500);
}
 
void loop() {
  
  // Read the light levels (ambient, red, green, blue)
  if (  !apds.readAmbientLight(ambient_light) ||
        !apds.readRedLight(red_light) ||
        !apds.readGreenLight(green_light) ||
        !apds.readBlueLight(blue_light) ) {
  //  Serial.println("Error reading light values");
  } else {
    
  }
  
  // Wait 1 second before next reading
  delay(1000);
if (red_light>green_light) {
digitalWrite(pushButton, HIGH);
delay(2000);
digitalWrite(pushButton, LOW);
delay(5000);
      };


}

What can be wrong? Should I change power-supply to

Do you have the 5V power connected to the Uno Vin pin or to the 5V output pin?
Are you powering the APDS9960 with a separate 3.3V?
Do you have a level shifter for the I2C lines?

Your question is a bit confusing, please post an annotated schematic showing exactly how you have wired it. Be sure to show all connections, power, grounds, and power sources.

Hi jim-p, we just use the Barrel connector to supply 5 Volt. No powering the APDS9960 with a separate 3.3V and no level shifter for the I2C lines.

Best to use a 3.3V Arduino with a 3.3V sensor.

The barrel connector voltage must be greater than 7V and less than or equal to 12V.
The APDS9960 should have a separate 3.3V supply. You should not use the Uno 3.3V you may damage the Uno
You must have level shifters since the Uno operates at 5V and the APDS operates at 3.3V. If you don't you will damage the APDS and/or Uno

You have right, now by applying 10 volt using the Barrel connector task completed.
Many Thanks (;