I am making an automatic chicken door for my chicken coop and am using an LDR to detect daylight and night and open and close the door accordingly. The whole project is running off 4 nimh AA batteries. As of now i just have the sensor in series with a 10k resistor going from VCC to GND. But to save battery, I was thinking I might be able to power it from a GPIO pin, so I could turn it on, take a reading, and turn it back off. My question is, if I were to go that route, how long would I have to leave the GPIO pin HIGH before I take a reading? And then can I turn it off immediately or should I leave it HIGH for a few milliseconds? Thank you all in advance
What is that? An LDR? If so, please post a link to its datasheet.
As long as the I/O pin never is forced to deliver more than 20 mA it should be okey.
Does the time matter much? Make a test sketch! Turn on the output and make readings every, say 10 ms and see what You get!
Turning off... Do it as soon as the reading is done.
A 10K resistor alone will draw 0.5mA, so well under the 20mA limit for a GPIO pin. Your LDR will range from a somewhat low resistance to a very high resistance, further decreasing the current draw in series with a 10K resistor. Like @Railroader said, make a test sketch to determine your timing.
p.s. @Railroader, LDR = light dependent resistor.
-
Immediately, but suggest you take say 10 readings then determine what should be done.
-
If it was me, I would use a logic level P MOSFET high side switch, however, the GPIO will probably work well.
-
You can sleep the Arduino and wake up to take readings too.
I know.
So from what I hear, I don’t need any delay in order for the values to stabilize? I was planning on adding a few milliseconds before taking a reading because I believe there would be a spike in voltage or current as soon as it’s switched on, and I was under the assumption that it would kind of bounce back and forth until it equalizes. But if I can get away without any delay I will. So something like - digitalwrite pin high, analogread sensor pin, digitalwrite pin low - should give an accurate reading without any delay in between? Haven’t had a chance to try it yet is why I’m asking instead of trying it
You are powering/reading a purely resistive load and the LDR will change resistance very slow. There shouldn't be any voltage spikes, but a simple test shouldn't be so hard.