Ws2812 neopixel LED strip will only light up 1 LED

The strip is connected to an Uno (5V) and a color sensor, I’ve checked both the code and connections and have tried a few different changes but it only seems to light just 1 LED at the start and it complies and uploads perfectly. though i know they all light up becuase ive tested the supplied example code so im not sure how to go about it.

Anyone have any Ideas?

#include <Adafruit_NeoPixel.h>  
#ifdef __AVR__  
#include <avr/power.h>  
#endif  

#define LED_PIN 3
#define LED_COUNT 120
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

   
int delayval = 333; // delay  
 
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
 
int frequency = 0;
int Red, Green, Blue;
 
void setup() {
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
 
  // Setting frequency-scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
 
  strip.begin(); //always needed
  strip.show(); // 0 data => off.
}
 
void loop() {
  // Setting red filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 25,72,255,0);
  if (frequency < 0) {
    frequency = 0;
  }
  if (frequency > 255) {
    frequency = 255;
  }
  Red= frequency;
  // Printing the value on the serial monitor
  Serial.print("R= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
 
  // Setting Green filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 30,90,255,0);
  if (frequency < 0) {
    frequency = 0;
  }
  if (frequency > 255) {
    frequency = 255;
  }
  Green = frequency;
  // Printing the value on the serial monitor
  Serial.print("G= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.print("  ");
 
  // Setting Blue filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  // Reading the output frequency
  frequency = pulseIn(sensorOut, LOW);
  //Remaping the value of the frequency to the RGB Model of 0 to 255
  frequency = map(frequency, 25,70,255,0);
  if (frequency < 0) {
    frequency = 0;
  }
  if (frequency > 255) {
    frequency = 255;
  }
  Blue = frequency;
  // Printing the value on the serial monitor
  Serial.print("B= ");//printing name
  Serial.print(frequency);//printing RED color frequency
  Serial.println("  ");
  strip.setPixelColor(0, strip.Color(Red,Green,Blue)); // Moderately bright green color.
  strip.setBrightness(255);  
  strip.show(); // This sends the updated pixel color to the hardware.
}

This is where you set the color of the first led, led number 0.
The rest (led 1 up to led 119) are not used.

ah I see, how would i cleanly (not having to copy the line) include the rest of the LEDs?

A for-loop

Something in the line of

for(uint8_t ledCnt=0;ledCnt<LED_COUNT;cnt++
{
  strip.setPixelColor(ledCnt, strip.Color(Red,Green,Blue));
}

===
Can you please edit your opening post, select all code and click image in the toolbar ; next save your post. As a result it will show in a scrolling window and will have a copy button. It also prevents mangling of your code by forum software and ” is replaced by a normal " so we don’t have to fix code before we can compile it.

Ah my bad fist time forums user, im not good with code so with the loop you’ve sent is it a copy paste in as is or am i missing a step?

Thanks for fixing the code.

// set the colour of all pixels
for(uint8_t ledCnt=0;ledCnt<LED_COUNT;cnt++
{
  strip.setPixelColor(ledCnt, strip.Color(Red,Green,Blue));
}
// set the strip brightness
strip.setBrightness(255);
// update the strip; this does the `physical' transfer of the data (that you have just set) to the strip
strip.show();

No worries, but for some reason this dosnt turn any of the LEDs on now, and ive copied it exactly as is and added ‘int cnt’. am i missing something?

Nvm i got it working, Thanks for the help, i really aprpeciate it :slight_smile:

So you really need to explain how you got it working. Other people might find it helpful. :+1:

Ah My Bad, I had rewritten the loop becuase it wasnt complete, though now it works perfectly, besides a little flashing here and there.

for(uint8_t ledCnt=0;ledCnt<LED_COUNT;ledCnt++)
{
  strip.setPixelColor(ledCnt, strip.Color(Red,Green,Blue));
}

Next time if things don’t work out as you expect, post your new code :wink:

What do you mean with that ?

1 Like

Well im not sure if its the Strip or something else but if you set the brightness more than 60-70 the Leds Flash slightly.

strip.setBrightness(255);

That is probably caused by power issue. How are you powering the strip ? for 120 leds you will need an external 5v power supply.
Even when using a 5v power supply, it is probably a good idea to add a sizeable capacitor on the 5v rail.

Not sure what you mean here.

Of course you need a power supply for the LEDs. What does “external” mean?

If you had just 8 LEDs, you might be able for testing purposes, connect them to the “5V” pin of the Arduino while it was powered by the USB port, but that cannot be called “power supply” as such. :roll_eyes:

For 120 LEDs you require a (120 x 0.055) 7 Amp power supply. Basically, a 10 Amp supply to give some “headroom”.

Powers coming stright from the Arduino 5v pin, ive used the example code the strip came with and the leds seem to work full brightness without flashing. unless something in the code is causing it.

copied as is from the website but i had changed the brightness to 255

#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 120
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
 strip.begin(); //always needed
 strip.show(); // 0 data => off.
 strip.setBrightness(50); // ~20% (max = 255)
}
void loop() {
 int n = strip.numPixels();
 // fph = FirstPixelHue
 for (long fph = 0; fph < 5 * 65536; fph += 256)
 {
 for (int i = 0; i < n; i++)
 {
 int pixelHue = fph + (i * 65536L / n);
 strip.setPixelColor(i,
 strip.gamma32(strip.ColorHSV(pixelHue))
 );
 }
 strip.show();
 delay(10);
 }
}

Generally people working with LED’s seem to think they can get away with :

‘external’ is just to emphasize not to use the USB power.

Well the ratings vary a little and most strips use a lot less than specified, even if they are on white & full-brightness, but yes, i’d rather be safe than sorry, though most USB ports provide nearly 1amp (but are rated for 500mA) and have a over-current auto shut-off, or just don’t provide more, but i would rather be safe than sorry.