2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Is this actually powered by a battery, or some kind of AC-DC power supply? \$\endgroup\$ – ambitiose_sed_ineptum Nov 7 '16 at 20:17
  • \$\begingroup\$ Your diode and capacitor placement dont make much sense (diode is always reverse biased) and the capacitor is blocking DC(and backwards). How many LEDs are you lighting up? You'd have to size the capacitor to keep that powered up as well in your concept. \$\endgroup\$ – Wesley Lee Nov 7 '16 at 20:19
  • \$\begingroup\$ One keyword for you is "brown-out detection". It detects falling supply voltage. When your capacitor is large enough for sending the zero signal to the LEDs, it'll work out. \$\endgroup\$ – DPF Nov 7 '16 at 20:20
  • 2
    \$\begingroup\$ Please tell us you're not actually using a resistor-divider to make 5V from a 9V battery for your poor little abused arduino... \$\endgroup\$ – brhans Nov 7 '16 at 20:24
  • \$\begingroup\$ @ambitiose_sed_ineptum I use a DC power supply. Probably a 12V device, since I found one which enough Amps for the LEDs. \$\endgroup\$ – Patrick Nov 8 '16 at 9:27
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Okay. That is really impressive. I'm trying hard to understand everything you just explained. I get the DPST part. The 7805 somehow converts to 5V. Good to know, that will come in handy for many applications! The youtube link is also very helpful. Thanks a lot! Regarding your last drawing: Why not VIN but barrel jack? Both accept up to 12V, right? And in the picture C1 has 1 uF, but rather should be 2x2.7V50F in series, right? I would like to use this solution because it is already build the project with SPST's (Two. One on each side of the bed. Telling the Arduino to activate different LEDs) \$\endgroup\$ – Patrick Nov 8 '16 at 11:03
  • \$\begingroup\$ You can use the Vin if it is made to take that voltage. I am simply weary of it because it can be easy to mix up (or accidentally connect) Vin and 5V, and doing so can ruin the board pretty much instantly. \$\endgroup\$ – ambitiose_sed_ineptum Nov 8 '16 at 15:27
  • \$\begingroup\$ I had another thought: Why don't you just use a switch to tell the arduino to turn the lights off and back on? I.e. when digitalRead(switchPin) == HIGH, the lights are on and when LOW, the lights are off. If you do this, the arduino would just keep running at all times, but it draws so little power that it probably would cost <$0.50 per year (in the U.S. at least) \$\endgroup\$ – ambitiose_sed_ineptum Nov 8 '16 at 15:32
  • \$\begingroup\$ I simply don't feel save with an always running Arduino and some self soldered wires under my bed - especially when I'm not home. So I want it to be plugged off all the time when it is not needed. But it is anoying that the NeoPixels keep flashing on start-up, so I was hoping to find a solution. Since the LEDs draw much current (above 1A) most of the MOSFET/transistor solutions might not be suitable since they are not for this high current. (But I'm not sure) - I ordered some high Farad condensators and will give those a try if I don't find anything else... \$\endgroup\$ – Patrick Nov 8 '16 at 16:06
0
\$\begingroup\$

Your solution would have the Arduino power everything on before even taking the analog read, so that might not work as well as you'd like. Make sure you're not writing anything at all to the WS2812's when you don't want them to light, or if you want them to start off, maybe reassure that by writing 0,0,0 to each LED.

If it's definitely not a software issue, try a power MOSFET. It'll do the same thing as the relay (in this instance), no clicking noise. Just make sure you:

1) Make sure you have a pulldown resistor (for n-channel) on your MOSFET so it defaults to OFF (no current passing), then turn it on with a digital HIGH when you want the LEDs to light up

2) Choose a MOSFET with a high enough current rating for your LEDs. WS2812's pull a max of about 60mA if I recall correctly, so get something with a little wiggle room. A 2 amp MOSFET could power 33 WS2812's at max, maybe 25 or 30 to be safe. Come to think of it, if you're using that many you should p

Also NeoPixels are a brand name of WS2812 (or equivalent), in case that was a point of confusion.

\$\endgroup\$
  • \$\begingroup\$ Using a (default OFF-) MOSFET on the WS2812's power line to prevent them from getting any power before writing 0,0,0 to each LED is a great idea to solve my problem. Thanks for the tip! \$\endgroup\$ – Patrick Nov 8 '16 at 9:38
  • \$\begingroup\$ But will that really work? @ambitiose_sed_ineptum pointed out, that I have to supply all WS2812's while writing them. So I have to activate the MOSFET before sending the "set lum to zero" command, and before this information is sent the LED's might flash up.. \$\endgroup\$ – Patrick Nov 8 '16 at 9:57
  • \$\begingroup\$ Ah, that is a good point; either way, the LEDs will get powered before you're able to write to them. So it may not solve this particular problem, good catch, hopefully the other guy's solution works out! \$\endgroup\$ – Orotavia Nov 8 '16 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.