How to Blink LED strip at 60 Hz?

I'm trying to blink an LED strip at 60 Hz with the following code:

#include <FastLED.h>

#define LED_PIN     7
#define NUM_LEDS    299

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  

}

void loop() {

  // Let's take 256 steps to get from blue to red
  // (the most possible with an LED with 8 bit RGB values)

  for( int colorStep=0; colorStep<256; colorStep++ ) {

      int r = colorStep;  // Redness starts at zero and goes up to full
      int b = 255-colorStep;  // Blue starts at full and goes down to zero
      int g = 0;              // No green needed to go from blue to red

      // Now loop though each of the LEDs and set each one to the current color

      for(int x = 0; x < NUM_LEDS; x++){
          leds[x] = CRGB(r,g,b);
      }



      // Display the colors we just set on the actual LEDs
      FastLED.show();

      delay(16);

      for(int x = 0; x < NUM_LEDS; x++){
          leds[x] = CRGB::Black;

      }
      FastLED.show();

 
  }



}

but when I run it, I can still see a flicker. I still see a flicker even if i set the delay to 1 millisecond.
I'm trying to get this effect: The Strobe Light Effect (Levitating Water Experiment) - YouTube
but seeing the flicker makes me think that the strip is not actually blinking as fast as the code suggests.

Any suggestions?

If you want a stroboscope, use a 12 V white strip - two connections only - with a logic level FET switching the negative line.

It is the time it takes to refresh the NeoPixels that is fouling you up.

I would not expect that delay() is accurate enough. Also your ON-time is much larger than your OFF-time.

I think you need to tweak a PWM-output and use LEDs without a controller.

Paul__B:
If you want a stroboscope, use a 12 V white strip - two connections only - with a logic level FET switching the negative line.

It is the time it takes to refresh the NeoPixels that is fouling you up.

Do you think using this method/code will work:

I'm unsure about how to use this for a 3 connection strip, but maybe I could buy a 2 connection instead.

Sorry, I'm not very familiar with electronics in general and am unsure what logic level FET switching is/how to use it for my purposes.

What are your definitions for "flicker" and "blink"?

gonnawinfantasy:
Do you think using this method/code will work:
https://www.instructables.com/id/Arduino-Stroboscopic-Light

What "method/code"? That article shows an Arduino driving one white LED with a 220 Ohm series resistor. OK, that is fine. Then it somewhat mendaciously says "You can use more LED's if you want to have stronger light". Well, you can, but as we point out, not with that circuit!

gonnawinfantasy:
I'm unsure about how to use this for a 3 connection strip, but maybe I could buy a 2 connection instead.

Well, your "3 connection strip" was a NeoPixel strip and that does not work for a stroboscope. If you want to use more than one white LED such as a LED strip (yes, two pins, and mostly operating at 12 V), you will need a FET driver.

(The IRF530 should be an IRL530.)

Paul__B:
What "method/code"? That article shows an Arduino driving one white LED with a 220 Ohm series resistor. OK, that is fine. Then it somewhat mendaciously says "You can use more LED's if you want to have stronger light". Well, you can, but as we point out, not with that circuit!
Well, your "3 connection strip" was a NeoPixel strip and that does not work for a stroboscope. If you want to use more than one white LED such as a LED strip (yes, two pins, and mostly operating at 12 V), you will need a FET driver.

(The IRF530 should be an IRL530.)

Okay, I get it. Thank you so much for your help.
Oh, and if I wanted to use RGB LEDs (nonstrip) would I just get three transistors instead?

Yep.

VictorMau:
Hello, I would like to try the same thing using a strip led WS2812B. Don't you think it is possible to set the frequency using the PWM function ?

No.

VictorMau:
Hello, I would like to try the same thing using a strip led WS2812B. Don't you think it is possible to set the frequency using the PWM function ?

So you mean to say you have just jumped in here without bothering to read the whole discussion and in particular, my reply #1, eh?

Of course I read it ! But is there any way to use the WS2812B finding a way that the NeoPixels refresh won't interact. Or maybe using the WS2812B with a FET driver ?

As I said, I am learning Arduino and electronics, and I don't understand why it could not work with the WS2812B...

and I don't understand why it could not work with the WS2812B.

I told you in a previous post. The Neopixels have their own PWM inside them to control the brightness. If you then add PWM on top of that you get beating between the two frequencies and just random flashing lights.

The Dot Star LED strips have a much faster internal PWM on them and you can ship out the data to them faster so maybe they will do what you want.
Why are you deleting your posts. Your behavior on this forum so far has been appalling and you have been told several times. So shape up or ship out.

Grumpy_Mike:
Why are you deleting your posts. Your behaviour on this forum so far has been appalling and you have been told several times. So shape up or ship out.

Well, I am not sure whether he deleted it or a moderator did, as I reported it as a cross post.

VictorMau:
Of course I read it ! But is there any way to use the WS2812B finding a way that the NeoPixels refresh won't interact. Or maybe using the WS2812B with a FET driver ?

As I said, I am learning Arduino and electronics, and I don't understand why it could not work with the WS2812B...

Well, there is the point. A WS2812 is not merely a LED, it is an ASIC, so your question resembles asking whether you could switch the power to your PC on and off every second. (And let me explain: I do not advise such an experiment :astonished: )

As I was in the middle of writing an answer when your posting on this thread mysteriously disappeared, and my answer consequently also was anulled which meant that it would take me a full 24 hours to recover to the point of even contemplating bothering to respond, you just might be able to strobe a small number of these chips on and off by updating them 60 times per second (i.e, once to program them all on and once to program them all off) and I suppose you could use millis() timing to lock that down to a 1 ms resolution, but it would not work very well.

It is simply not a sensible idea when as stated more that once, you simply have the wrong sort of LED strip.

But as so often here, you are beautifully demonstrating the XY problem. Instead of asking how to do something foolish, you need to tell us what you actually wish to do, and we can tell you how to do it. I suspect you wish to implement a stroboscope, which would mean you want to generate very short flashes of the order of a millisecond. This makes the WS2812/ "NeoPixel" even more inappropriate again.

And it has nothing to do with the PWM frequency of the WS2812/ "NeoPixel" anyway, as you would be setting the PWM value to maximum, that is, continuous.

OK, posters like Mike and Myself tend to reply from to time with a single "No!" answer. It may be misinterpreted as "not really a good idea" when it actually means "not going to happen till hell freezes over". :roll_eyes:

Grumpy_Mike:
Why are you deleting your posts. Your behavior on this forum so far has been appalling and you have been told several times. So shape up or ship out.

I didn't try to delete anything in this topic...

Thank you for your answers. I understood I purchased the wrong sort of LED strip.

Paul__B:
I suspect you wish to implement a stroboscope, which would mean you want to generate very short flashes of the order of a millisecond. This makes the WS2812/ "NeoPixel" even more inappropriate again.

Yes! I was trying to do like "gonnawinfantasy". But also, I wanted to control and change the color over time.

Grumpy_Mike:
The Dot Star LED strips have a much faster internal PWM on them and you can ship out the data to them faster so maybe they will do what you want.

So I am going to dig the question with this product. And see if I might be able to control the PWM to reach 50hz and set a color scenario.

I would like to try to do this with a pannel of 180 led 5050 I took from an strobodevice.

Paul__B:

Can someone could help me with the first sketch I made ?
Do I really need to put the R1 ? Can I use the Mosfet from the arduino starter kit instead of the IRL530 ? or is it the same ?

Thank you

So I am going to dig the question with this product. And see if I might be able to control the PWM to reach 50hz and set a color scenario.

OK you do not use this circuit with an addressable strip. You use software to turn the LEDs on and off at 50Hz.

VictorMau:
Yes! I was trying to do like "gonnawinfantasy". But also, I wanted to control and change the color over time.

Well, that was his later question. To start with, you need a plain - generally 12 V - LED strip where all the LEDs are connected in (series-)parallel. Generally in sets of three to be powered with a resistor at 12 V. If you use a white strip, then you simply switch it with the FET; if you wish to do colours, you use a tricolour strip and will require three FETs as per reply #7.

Note however, that if you are strobing it necessarily with very short pulses, it will be difficult (but not impossible) to implement a form of PWM (in software, not the PWM pin functionality) to do other than the seven basic colour combinations.

An IRF530 - which I believe is the one supplied in kits - will probably suffice, an IRF530 is the proper logic-level device.

The OP seems all over the place with what he wants and how to achieve it.

The use of a FET to PWM the power to a strip will only work if it is not an addressable strip. You try PWMing an addressable strip and you are in all sorts of trouble.

Ok perfect, thank you.
First I will try to make things happen using white leds, already connected with resistors, that I took from an old device.

Do you think this configuration will work ? Do I need to add a R1 between the arduino pin and the Fet ?

VictorMau:
Do you think this configuration will work ? Do I need to add a R1 between the Arduino pin and the FET ?

Now you are about to start a serious argument all over again!

Yes, you should because the gate of the FET has significant capacitance and every time the Arduino switches it on or off, for a few microseconds that capacitance appears as a virtual short circuit as it charges. The argument runs around whether for such a short time, that temporary overload matters and noting that with PWM as against just turning a FET occasionally on or off, that happens very often in each and every second.

Put a 220 Ohm resistor in series just to keep everyone happy. :grinning: