I want to build something that will switch between a regular LED and an IR LED at dusk and dawn.
I’m very new to all this and I’m sure for most this is a simple thing to do but I’m hoping someone will be kind enough to advise how I can do this.
My reasons?
I have a nest box with Native owls in it, and the past few years I’ve been filming them but I need a little more light in there during the day and an IR illuminator of a night. I’d like to switch between the two either automatically on dusk and dawn or via wifi manually if needs must.
I’d be grateful for friendly non judgmental advice please.
There should be no problem doing what you describe
You need to detect the light level to determine whether it is the right moment to switch one way or the other then the code becomes
if (lightLevel > threshold)
{
digitalWrite(irLedPin, LOW); //turn off IR LED
digitalWrite(normalLedPin, HIGH); //turn on normal LED
}
else
{
digitalWrite(normalLedPin, LOW); //turn off normal LED
digitalWrite(irLedPin, HIGH); //turn on IR LED
}
So if I understand correctly I’ll need to get a light sensor and obviously the two leds, stick that all on the board and then this will be driven by the sensor rather than by some predefined dusk/dawn times like the likes of iPhone etc use.
This would mean the sensor would need to be outside the owl nest I guess.
Would there be a way to predefine when it switches from one to the other so I can do away with the sensor?
Haha, no need. We all friends here, no judgements.
If you wanted, you could use an RTC real time clock and track the time for dawn and dusk.
I like using a light sensing element LDR or similar. If you go that route, some hysteresis might make things less twitchy at the time of changing.
# define DAY 600
# define NIGHT 400
//... in the loop somewhere, two if statements
if (lightLevel > DAY)
{
digitalWrite(irLedPin, LOW); //turn off IR LED
digitalWrite(normalLedPin, HIGH); //turn on normal LED
}
if (lightLevel < NIGJT)
{
digitalWrite(normalLedPin, LOW); //turn off normal LED
digitalWrite(irLedPin, HIGH); //turn on IR LED
}
It's your home thermostat logic. Turn on the heat when the temperature is below a lower temp threshold, don't turn off the heat until the temperature is above a higher temp threshold.
You'll have to experiment with the sesnor and the numbers I picked arbitrarily.
You could define the time of the change from one to another but as others have pointed out it would be better to use a light sensor. If you used time to determine when to change from one LED to another then at the very least that will need to change over a period which makes things more complicated