7 segment display brightness

Hello, I am using a HDSP-5521 dual digit 7 segment display and i build a circuit with the Arduino Uno and Arduino WiFi shield. When i power it using the USB cable the brightness was perfect, however in my project i am required to power it with an external power supply, preferably using batteries and when i use a 9V battery or a DC power supply of 5V, the 7 segment became brighter and when it does the counting, i can still see it however the background of the 7 segment can be seen which makes it hard for the number to be seen correctly. Have anyone encountered this before? Thanks for anyone willing to help.

IF anyone is wondering if its a problem with the code, below is my code:

 #include <SPI.h>
#include <WiFi.h>

// Arduino digital pins used to light up corresponding segments on the seven segment display
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F_SEG 8
#define G 9

// Push button connected to pin 18 & Sensor connected to pin 17
#define PB 18
#define digitalDistanceSensor 17

// Pins driving common anodes
#define CA1 10
#define CA2 14

const int ledPin = 15;
const int speakerPin = 16;

char wifissid[] = "------";   //  your network SSID (name)
char wifipass[] = "----";
int keyIndex = 0;

char devid[] = "---"; // Device ID for PushingBox scenario

char serverName[] = "api.pushingbox.com";
int count = 0;
boolean pinDevid1State = false; // To save last state of the pin for DEVID1
int status = WL_IDLE_STATUS; // Status of the Wifi
WiFiClient client;
char postmsg[100];
unsigned long timer1;


// Pins for A B C D E F G in sequence
const int segments[7] = {A, B, C, D, E, F_SEG, G};

// Segments that make each number
const byte numbers[10] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000}; //logic 0 to turn on segment (common anode)

void setup()
{
  Serial.begin(9600);
  delay(1000);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F_SEG, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(PB, INPUT);
  pinMode(digitalDistanceSensor, INPUT_PULLUP);
  pinMode(CA1, OUTPUT);
  pinMode(CA2, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  Serial.println("Attempting to connect to WEP network...");
  status = WiFi.begin(wifissid, keyIndex, wifipass);
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while (true);
  }
  else {
    Serial.println("Connected to network");
  }
  timer1 = millis();
  Serial.print("timer1:");
  Serial.println(timer1);
}

int unitDigit = 0;
int tenthDigit = 0;
unsigned long interval = 60000; //60 seconds
unsigned long timer = timer1 + interval;

void loop() {
  unsigned long currentMillis = millis();
  unsigned long currentMillis2 = currentMillis - timer1;

  if ( currentMillis2 > timer && currentMillis2 < timer + 3000 )
  {
    unitDigit != (unitDigit + 1) % 10;
    if (unitDigit == 0)
      tenthDigit != (tenthDigit + 1) % 10;
    sendingRequest();
    
  }

  else if (currentMillis2 > timer - 10000 && currentMillis2 < timer)
  {
    int currentState = digitalRead(digitalDistanceSensor); // read from sensor
    digitalWrite(ledPin, HIGH);
    if (currentState == LOW && pinDevid1State == false)
    {
      pinDevid1State = true;
    }
    if (currentState == HIGH && pinDevid1State == true)
    {
      count++;
      Serial.println(currentMillis2);
      Serial.print("Number of Counts : ");
      Serial.print(count);
      Serial.println();
      unitDigit = (unitDigit + 1) % 10;
      if (unitDigit == 0) {
        tenthDigit = (tenthDigit + 1) % 10;
      }
      pinDevid1State = false;
    }
  }

  else if (currentMillis2 < timer - 10000)
  {
    int currentState = digitalRead(digitalDistanceSensor); // read from sensor
    if (currentState == LOW && pinDevid1State == false)
    {
      pinDevid1State = true;
    }
    if (currentState == HIGH && pinDevid1State == true)
    {
      count++;
      Serial.println(currentMillis2);
      Serial.print("Number of Counts : ");
      Serial.print(count);
      Serial.println();
      unitDigit = (unitDigit + 1) % 10;  
      if (unitDigit == 0) {
        tenthDigit = (tenthDigit + 1) % 10;
      }
      pinDevid1State = false;
    }
  }

  // display number
  unsigned long startTime = millis();
  for (unsigned long elapsed = 0; elapsed < 600; elapsed = millis() - startTime)
  {
    tenthsDigit(numbers[tenthDigit]);
    delay(5);
    unitsDigit(numbers[unitDigit]);
    delay(5);
  }
  // reset count
  int button = digitalRead(PB);
  if (button == LOW)
  {
    //unitDigit = 0;
    //tenthDigit = 0;
  }
}

void unitsDigit(byte number)
{
  digitalWrite(CA1, LOW); // set the LED off
  digitalWrite(CA2, HIGH); // set the LED on
  lightSegments(number);
}

void tenthsDigit(byte number)
{
  digitalWrite(CA1, HIGH); // set the LED on
  digitalWrite(CA2, LOW); // set the LED off
  lightSegments(number);
}

void lightSegments(byte number)
{
  for (int i = 0; i < 7; i++)
  {
    int bit = bitRead(number, i);
    digitalWrite(segments[i], bit);
  }
}

void sendingRequest()
{
  digitalWrite(ledPin, LOW);
  digitalWrite(speakerPin, HIGH);
  delay(1000);
  digitalWrite(speakerPin, LOW);
  delay(1000);

  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    Serial.println("sending request");
    digitalWrite(ledPin, HIGH);
    delay(1000);
    sprintf(postmsg, "GET /pushingbox?devid=-----&count=%d HTTP/1.1", count);
    client.println(postmsg);
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");;
    client.println();

    Serial.println(postmsg);
    Serial.println("Host: api.pushingbox.com");
    Serial.println("Connection: close");
    Serial.println();
    digitalWrite(ledPin, LOW);
    delay(1000);
    count = 0;
  }
  else {
    Serial.println("Connection Failed");
    client.stop();
    count = 0;
  }
}

Let's see your schematic too, there may be something there.

A red filter helps to improve contrast.

Are you applying 9V to the common anodes while driving the segments direct from the Arduino?