Electronic – Detect self power off (and delay power off)

delaydetectionpower supply

I'm new! And quite a newby. :\

I build a project with an Arduino and some neopixels. The problem is, that the neopixels stores its last state, and when I switch on the power supply (for both), they tend to blink on start before the Arduino has the chance to toggle them off.

It is one switch that toggles on and off. So I thought, may be I can measure the power supply and detect when it is switched off, but keep it on with a capacitor (seperated by a diode, so the measurement is not falsified by the capacitor). If a LOW is detected, I could send a turn-off signal to the LEDs and voila, problem solved.

something like this

(I didn't used the right resistor-values for the voltage drop to 5V. sorry)

My first question: Is that possible at all? Or is the draw of the arduino to high for a capacitor to keep it up long enough?
How big should the capacitor be?
Or do you guys have a better way to solve this?

My other much more simple idea would be a relay, which would bypass the switch and would be powered on by the arduino at it's power up. So I can detect the power off state and do my things and then switch myself off with the relais. But my goal would be to get it done without that giant ugly and loudly clicking relay.

Best Answer

If you're dead set on the switch method, here's what I would suggest:

schematic

simulate this circuit – Schematic created using CircuitLab
This uses a DPST switch, instead of SPST. This configuration solves the diode and capacitor problems you were having, and allows you to use attachInterrupt() to create a function to wipe all of the neopixels before loss of power. Note, however, that you will need your capacitor(s) to be able to supply the arduino AND all of the neopixels while you are writing to them. This is doable, but requires high farad values. Super capacitors can be an option, but tend to be more expensive. BGMicroElectronics has some that can fit a budget. 2.7 V 50 F capacitors for a couple bucks, put them in series for 5V and 25 F, but they require lots of power to charge, too much for the vast majority of power supplies to handle. You can search for other super capacitors, but I suggest this method instead:

If you aren't powering this with a battery, use something like this (SE) (the first answer) or this (youtube) (recommended) instead, then a pushbutton is enough to tell the arduino to power down, and the arduino itself cuts off the power, after resetting all of the neopixels. These solutions do consume minimal amounts of power while powered off, which is why I don't suggest them for battery powered applications.

To echo Wesley Lee in the comments: the diode and capacitor as you have them will not work. Capacitors do not allow DC to pass, so that configuration alone wont allow power to get to the arduino,but then the diode prevents current from flowing to the capacitor anyway. I fixed that using the DPST switch to prevent backflow instead.

It could also be done this way:

schematic

simulate this circuit

Where Vin is the barrel jack connector not the arduinos 5 V line, But again youl run into the problem of chargin the capacitors, and them holding all of the energy that you need.

Related Topic