my circuit is complet yet simple. I connect 3 digital pin of my arduino to three optoisolators to detect some signals from my alarm system.
The pins are in a pull-up configuration, connected to the 3.3 pin and to a 1 k resistor.
When on of the optoisolator close, the corresponding "circuit" is closed and 1.6 mA are used.
This is perfectly fine!
The point is that I'm trying to minimize the power consumption. Since I read the pins status every 15 seconds, in the worst case scenario I'm going to waste 1.6*3 mA for ~15 seconds.
I would like to be able to consume power only when necessary.
What if I change the +3.3 reference in the pull-up configuration, using another pin to act as the 3.3v ref?
My idea is to set HIGH this special pin, read all three digital pins, then set DOWN again.
This way I will draw 1.6mA of current for a very short amount of time.
Is this a reasonable approach? Any drawback?
To give you more details, I'm using a ESP8266 12e, programming it with the Arduino EIDE. I hope they're are so similar to let me ask for your help.
I'm too lazy, right now, to attempt to find a datasheet for your "ESP8266 12e", but I suggest you give that a try and see if you can find out how much current each Digital Pin can source. More than likely it's more than 1.6mA [my guess is around 12mA]. So, if it's clear that at least 1.6mA can be sourced, and if the total current the device can allow is at least 3 * 1.6mA [or 4.8mA] (and I'll be surprised if it isn't), then, yes, that will work. In fact, I've used that technique, in various designs, for the same reason.
Now, to be clear, "can be sourced", includes the ability to source the required current, and still supply the requisite voltage required by what you are powering. When an output goes HIGH, and when the thing it is connected to draws current from that output, there is, typically, a voltage drop. So, you need to determine what that voltage drop will be, for the 1.6mA that will be drawn (from that output), and if that will be a show stopper.
I also suggest you consider that there might be a "power up timing" -- in other words, when the Digital Output [that is powering the Optos] goes HIGH, their may need to be a slight delay included, in your sketch, between this Power Up point, and the point where you actually read the Opto states. Probably not more than a microsecond or two. If you have an oscilloscope, you can measure the rise time on this output, and determine if it's fast enough to not be an issue, or if a delay needs to be added to your code.
I've done something similar to keep from heating a thermistor by applying voltage from an output pin for a few mS while reading it, so your scheme will probably work, but, without seeing your wiring, I can't say for sure. Can you post a wiring diagram?
(The left part of the project is some wiring coming from my alarm system connected to the optoisolators.)
ReverseEMF:
Now, to be clear, "can be sourced", includes the ability to source the required current, and still supply the requisite voltage required by what you are powering.
I suppose I would not have such a problem in the current scenario, am I right?
ReverseEMF:
I also suggest you consider that there might be a "power up timing"
Yeah, I was already thinking to test some short delay (say <5 ms) and check whether it would be enough.
outsider:
I've done something similar to keep from heating a thermistor by applying voltage from an output pin for a few mS while reading it, so your scheme will probably work, but, without seeing your wiring, I can't say for sure. Can you post a wiring diagram?
The diagram is above (not very formal, excuse my lack of skills!).
Should I use a digital or an analog pin set as output?
When all 3 optocouplers are on, you have your 3.3v (minus the voltage drop of the transistors) connected to GND through 3x 1kΩ in parallel. That draws 8 ... 10 mA. If your I/O pin can't source that, you could use a PNP transistor or P-mosfet on the high side.
This is essentially a 3x1 input-matrix that you're scanning with a lot of dead time.
Jobi-Wan:
When all 3 optocouplers are on, you have your 3.3v (minus the voltage drop of the transistors) connected to GND through 3x 1kΩ in parallel. That draws 8 ... 10 mA. If your I/O pin can't source that, you could use a PNP transistor or P-mosfet on the high side.
This is essentially a 3x1 input-matrix that you're scanning with a lot of dead time.
I think you are forgetting that there will be an LED in series with each of those 1k resistors. The OP says the individual currents are 1.6mA, and that will be true if the Opto's internal LED has a forward drop of 1.7V [thus the total current would be 3 * 1.6mA = 4.8mA.
But, I've know that voltage to be as low as 1.1V, which would result in a current of (3.3V - 1.1V)/1k = 2.2mA -- for a total current of 3*2.2mA = 6.6mA.
@Wawa,
Leo, for a "generic" opto, how much LED current is required to cause the phototransistor collector to pull down to, say, 0.5V with a 10k pullup?
Actually I was using 1k ohm resistors since I designed the circuit with a Raspberry PI Zero, which seemed unable to sense HIGH/LOW states when using resistors >1 k.
In the current circuit I can use 10k Ohm resistors. And I will!
I also try using a digital pin as 3.3v output, and it works great.
This way, I have improved the power saving of this system, while keeping it very similar to yesterday.