neopixel led is not working with External power

I have arduino uno, neopixel led strip and 4 aa battery pack. When I connect Arduino to my laptop, the led works.

but It does not work when an external power source is connected to the battery pack.

led strip: WS2812B ( 4 LED ), conneted to Arduino VCC, GND, D5 port

external power: 4 AA battery pack, connected to Arduino

#include <Adafruit_NeoPixel.h>
#define PIN            5                              // contol pin
#define NUMPIXELS      4                            // LED COUNT
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
  pixels.begin(); // This initializes the NeoPixel library.
void loop() {
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.; // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).

How can I find a compatible external battery? with out USB power.

I want to supply LEDs and aduino power only use battery.

The final project will have 10 leds and four sensors.

Well, if you tell us what you are actually doing, what you are connecting to what, exactly what each part is, we might be able to help!

Need a proper diagram for a start.

I'm sorry. I modified the post in detail.

How much current is your project consuming?

One thing that is lacking in the image where your battery is connected.

OK, now tell me what "when an external power source is connected to the battery pack" means?

Four NeoPixels can be comfortably powered from the 5 V pin when you are supplying USB power as their maximum consumption is 240 mA. It is impractical to operate a much larger number of LEDs via the USB supply and of course you could never even dream of powering this via "Vin" or the essentially decorative "barrel jack" but a 4 AA battery pack will give 6 Volts so I am puzzled by your suggestion. :astonished:

An "external power source" would need to comprise a regulated 5 V to the LED strip and back to the "5V" pin as you indicate.

How can I find a compatible external battery?

If you told us what you had then we could tell you if it is compatible.

Simple things like what battery is it and how you wired it up.

Basically a WS2812 needs 5V and if your battery can't supply that directly ( no battery supplies 5V directly ) you have to regulate the battery to supply this voltage.

external power: 4 AA battery pack, connected to Arduino

How? My guess is that you haven't connected the battery ground to the Arduino ground.

Well, my sneaking suspicion here is that he thinks - because the Arduino "tutorials" regrettably suggest this - that it can in some perverse fashion, be powered through the "Vin" pin (or the "barrel jack"). :astonished: