Hi all, I know it’s good practice to add a delay(3000) to the start of a sketch and I have a nebulous idea of why it’s there, but I haven’t been able to find a solid explanation.
Looking through sketch comments I’ve found “power-up safety delay”, “sanity delay”, and “3 second delay for recovery”.
I’d love a more concrete explanation of the impact of adding this delay if anyone could enlighten me? Apologies if this is in the FAQ somewhere that I’ve missed.
Thanks!
I started doing that after having had multiple instances where the power draw on the first frame was high enough that the MCU would be starved for power and shut down - and on some of the devices that I was working with this was happening quickly enough that I couldn’t even upload new code to fix the problem.
Another variation on this was a case where I had a loop spinning on writing out led data and blocking interrupts, again creating a situation where I couldn’t get new code uploaded.
The delay is to give a window of time to hit pad in situations where your code might otherwise have left the device in a state where it couldn’t be updated.
Nowadays I don’t do the delay so much as I do a slow fade of brightness from 0 to the full level, still over the course of a few seconds.
Thanks @Daniel_Garcia , I appreciate the detailed response. Makes sense to me 
The bigger the power supply, the longer it can take to become stable and usable, along with any supply cables running from it to the loads (your individual LED chips).
This is all brought on by not only the internal design of the power supply itself, but things like resistances, capacitances and inductances in the entire configuration.
Big power supplies need capacitances to smooth out ripple and internal noise. If you have a scope, you can hang it on the supply output and watch the voltage come and and then stabilise. This is the point at which you can start using the power. Not before. Some manufacturers will quote this figure, otherwise you may have to ‘guess’.
I have worked on the software for stadium flood lights which is a similar problem, but in the mega-watt area of power. At first you can turn on individual lights pretty quickly one after another. But soon there is so much load and current flowing around the system, that the last 20% of flood light modules can take several minutes before the supply is stable enough to turn on another. Even more complicated when the system has metal halide lamps too and as they warm up, their electrical characteristics change as they come up to full white. And you can’t just turn them all off together either. Ever seen what 5 mega-watts of back EMF does to the grid?!! LED strips are a doddle to me after that.
If you have a small dedicated PSU for the controller and it has a spare analogue input for each big PSU, use that to monitor the bigger PSU (s) at start up. And better still, during operation, to keep any eye on things.
Yeah I’ve always had a delay(3000) in my Arduino code because I find if I start my main program right away, the register writes seem to take effect abrutly instead of smoothly. I think the capacitance explanation above makes sense. Easy way to test it is try with different power adapters and see if the delay time makes a difference.
If you use a smart power supply like atx, it will tell you when power is stable. Otherwise you have to guess or check when power is stable yourself
Thanks for the useful information everyone!