Bird dimmer

Hello,i would like to make a 24 hours dimmer for birds. I want to simulate the day.
I have this timer switch
http://www.ebay.com/itm/LCD-Digital-Power-Programmable-Timer-220V-24V-12V-Time-Relay-Switch-/131090570966?pt=LH_DefaultDomain_0&hash=item1e859b5ed6
.For example, I adjust the timer switch at 7:00AM and i want for the next 20 or 30 minutes(i want to adjust this) a lamp from 0% to light to 100% like it's dawning.
And at night with my timer switch ,for example at 6:00PM i want from 100% the lamp goes to 0% in 20-30-40 minutes (i want to adjust this) like it's getting dark.
How am i going to do this??

How do you plan to control the artificial dawn/dusk times? Typically they would vary throughout the year. Do you intend to have this related in any way to the actual local dawn/dusk times? (A solution using an LDR to detect actual dawn/disk and generate an artificial dawn/dusk using a PWM ramp would be pretty simple, if you use a low voltage DC light source.)

i will manual change the timer switch to difference hour zone between the seasons. I need a PWM circuit to control a triac ,but how can i control the time that the lamp will go on, for example in 30 minutes i want from 0% to light 100%.
Do you thing i would be easer with a 555 circuit than an arduino?

Hi alfadex,

I'm not sure how that timer switch is going to work with your circuit. An arduino could bring the light level over an hour up once the timer comes on, but how can it know when the timer will switch off so that it can begin dimming 1 hour before?

You may be better off attaching an RTC (real time clock) to the Arduino and using that timer for another project.

Also I agree with PeterH. The project would be much easier and safer if you could use low voltage lighting. What size of area do the birds live in? A massive barn with 20,000 chickens, or two budgies in a cage?

Paul

Hi paul
I have to control just one room with around 10 cages ,i need 230V lamp. I
So, I 'll try this to the breadboard ,i think it is what i need,but i don't know the timings

S1 , is going be my timer switch.
P2 , i will change the period that the lamp start on, for example 20-30 minutes.

I wish i could done it with arduino but i don't know programming,,i know it would be easier. I have rtc ,arduino and everything i need ,I don't know how hard is it ,but if somebody could help with programming ,it would be great full.

The timer you posted the link for, did you buy the 12, 24 or 230V version?

I don't know much about triacs or diacs, I'm sorry I can't help much with that. Does the scematic you posted allow dimming? If so, it seems to do this with a potentiometer. Arduino analog outputs actually give a pwm signal, the sketch can control the duty cycle.

It seems to me that the Arduino has little to do if your timer is in the circuit also. But it will make the programming easier.

so, to re-phrase the question on this post.....

I have an Arduino, am RTC and a dimming circuit,

I am a beginner and am just learning how to program.
Can anyone help me or point to examples that might help ?

I want to have a time in the morning when lamps for my birds will start to come on, to simulate the sunrise. the time from off to full on should be about 20 minutes.

then, at the end of the day, I want to simulate sun set and ramp down over about 20 minutes.

any pointers or examples would be greatly appreciated.

(then I would look at PWM and try to dim an LED to get used to programming)

forget about the timer if you want to use an arduino and an RTC

or lose the RTC as it would be useless when you have an external signal.

the input sees the signal from the clock and starts to ramp up for the period you program.
it stays at full brightness as long as the timer contacts are closed.
when the timer contacts open, the signal is lost and the program starts to dim over a 20 minute period.

bread board a switch and an LED
turn on the switch and start to pwm the led.

turn off the switch and then ramp the led to off.

dave-in-nj you are right,i need this exactly,i didn't phrase it very well. :roll_eyes:
Let's dim a led,there is no problem, i can convert it afterwards to control a 230 v lamp

My timer is 12 volts

dave-in-nj:
forget about the timer if you want to use an arduino and an RTC

or lose the RTC as it would be useless when you have an external signal.

the input sees the signal from the clock and starts to ramp up for the period you program.
it stays at full brightness as long as the timer contacts are closed.
when the timer contacts open, the signal is lost and the program starts to dim over a 20 minute period.

bread board a switch and an LED
turn on the switch and start to pwm the led.

turn off the switch and then ramp the led to off.

yes this is, but it would be better to use the timer ,because i have to change the signal from the clock. For example today it sunrise at 7:00AM, after a month will sunrise 7:15AM,
If i don't use a switch timer how could i change the sunrise time without my computer or programming.

12 volt timer to an opto isolator.

the opto is nothing more than an LED so you set the current with resistors.

12v lights the LED, that equals the start.
once the program sees the start, it begins to turn the lights on.

when the 12v is removed, the program begins to turn them off.

easy peasy.

I like how you are isolating the signal from the mains. you are really on the right track !

here is where the programming can take over from getting a thing working to a technological masterpiece.

the RTC will offer the actual time. you can set the day, there are probably a multitude of ways to match the natural sunrise time, and there are plenty of calendars to do that.

one way is that Dec 23 is the winter solstice. the shortest day of the year. 365 days later it is back.
182 days later is the summer solstice. the longest day.
dead in between, or 91 days, is the vernal equinox or 50% day, 50% night. 12 hrs on, 12 hrs off
set the time the sun rises, add a 1 for each day. until you hit 182, then subtract a 1 after that until you reach zero.

the time of sun rise is dependent on your latitude, note the time it rises and sets (local tide tables may have this)
you can calculate how much it changes each day., say it is 1 minute. (again the tide tables should show this)

so, here we are 20 days out of the winter solstice and 71 days before the vernal equinox. you know that the vernal equinox has 12 hours of light. subtract your 71 minutes and you have a starting point.

I am sure there are many to do this. but, this was a way I did this with an old PLC. you can get pretty close without libraries and look-up tables and such.

of course, someone else should be able to offer a much more accurate way to use the RTC for your project.

I see your rationale ,it's very good,everything can be done

So, what would the programming for just turn on the switch and start to pwm the led for around 30 minutes and
turn off the switch and the led goes of in 30 minutes again.

alfadex:
So, what would the programming for just turn on the switch and start to pwm the led for around 30 minutes and
turn off the switch and the led goes of in 30 minutes again.

It depend a lot on the LED. The "off" level may not be at the end of the PWM range, and the "fullbrightness" may not be at the other end of the PWM range.

You can find these levels by trial and error. Once you find them, just divide 30 minutes by the difference between off and full on.

Of course, you can always go right to each end of the range (0 to 255), but you may find that it's taking too long to see a change, or too soon reaching full brighness (or at least apparent full brightness).

You can start off doing it without the RTC, if you time the increase and decrease changes with millis(). See the BLink Without Delay example that came with the IDE. 30 minutes is 30,000 milliseconds, so you can increase the PWM every 117 milliseconds until you reach 255. For starters, though, use a shorter time. Allow the PWM to increase from 0 until you can just see the glow of the LED. FOr this, you can use a switch and only increase the PWM value while the switch is held down. If you serial..print the PWM value whenever it changes, you'll now know what value make it start to glow, as you will release the switch at this point. Do the same for decreasing from 255, and as soon as you see a dimming, release the switch. Now you have a range.

Best programming practice is to do one thing at a time, testing as you go. The program will practically build itself this way.

Setting aside the issues of when the dawn/dusk transitions need to occur, and setting aside the design of the circuit to convert a PWM signal into a brightness, I would design the code to manage the dawn / dusk transitions like this:

Define a state machine with four states: NIGHT, DAWN, DAY, DUSK.

In each state, run logic to detect when to transition to the next state. For NIGHT/DAY, that would presumably be based on the RTC input. For the DAWN/DUSK states that would be based on elapsed time i.e. whether your brightening/dimming sequence is complete. In the NIGHT state the PWM output is LOW. In the DAY state it would be whatever you wanted your maximum brightness to be. In DAWN/DUSK states is would be calculated from the elapsed time in that state - probably you'd want a linear ramp between the day/night values.

I have made a circuit that i can control a 230v Halogen lamp from a digital output pwm 0-5 V of arduino. With no flickering and analog light, with analog light i mean

PWM 0v (or 10% PWM ) --> 1400 Lux
PWM 2.5v (or 50% PWM ) --> 700 Lux
PWM 5v (or 95% PWM ) --> 0 Lux

I used a 555 timer and i am thinking of to double the voltage with an op amplifier so that i can use to 0-10 volt dimmable dimmer for fluorescent lamp.

PeterH:
Setting aside the issues of when the dawn/dusk transitions need to occur, and setting aside the design of the circuit to convert a PWM signal into a brightness, I would design the code to manage the dawn / dusk transitions like this:

Define a state machine with four states: NIGHT, DAWN, DAY, DUSK.

In each state, run logic to detect when to transition to the next state. For NIGHT/DAY, that would presumably be based on the RTC input. For the DAWN/DUSK states that would be based on elapsed time i.e. whether your brightening/dimming sequence is complete. In the NIGHT state the PWM output is LOW. In the DAY state it would be whatever you wanted your maximum brightness to be. In DAWN/DUSK states is would be calculated from the elapsed time in that state - probably you'd want a linear ramp between the day/night values.

PeterH it would be the rightest method to follow in addition what i need, bu it would very hard for me in programming

lar3ry:
It depend a lot on the LED. The "off" level may not be at the end of the PWM range, and the "fullbrightness" may not be at the other end of the PWM range.

You can find these levels by trial and error. Once you find them, just divide 30 minutes by the difference between off and full on.

Of course, you can always go right to each end of the range (0 to 255), but you may find that it's taking too long to see a change, or too soon reaching full brighness (or at least apparent full brightness).

You can start off doing it without the RTC, if you time the increase and decrease changes with millis(). See the BLink Without Delay example that came with the IDE. 30 minutes is 30,000 milliseconds, so you can increase the PWM every 117 milliseconds until you reach 255. For starters, though, use a shorter time. Allow the PWM to increase from 0 until you can just see the glow of the LED. FOr this, you can use a switch and only increase the PWM value while the switch is held down. If you serial..print the PWM value whenever it changes, you'll now know what value make it start to glow, as you will release the switch at this point. Do the same for decreasing from 255, and as soon as you see a dimming, release the switch. Now you have a range.

Best programming practice is to do one thing at a time, testing as you go. The program will practically build itself this way.

lar3ry i try to use BLink Without Delay but don't know what happens.
How can i increase PWM every 117 millisecond until I reach 255? Like this?

const int ledPin = 13; // the number of the LED pin

int ledState = LOW; // ledState used to set the LED
long previousMillis = 1000; // will store last time LED was updated
long interval = 117; // interval at which to blink (milliseconds)

void setup() {
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;

if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

digitalWrite(ledPin, ledState);
}
}

dave-in-nj:
here is where the programming can take over from getting a thing working to a technological masterpiece.

the RTC will offer the actual time. you can set the day, there are probably a multitude of ways to match the natural sunrise time, and there are plenty of calendars to do that.

one way is that Dec 23 is the winter solstice. the shortest day of the year. 365 days later it is back.
182 days later is the summer solstice. the longest day.
dead in between, or 91 days, is the vernal equinox or 50% day, 50% night. 12 hrs on, 12 hrs off
set the time the sun rises, add a 1 for each day. until you hit 182, then subtract a 1 after that until you reach zero.

the time of sun rise is dependent on your latitude, note the time it rises and sets (local tide tables may have this)
you can calculate how much it changes each day., say it is 1 minute. (again the tide tables should show this)

so, here we are 20 days out of the winter solstice and 71 days before the vernal equinox. you know that the vernal equinox has 12 hours of light. subtract your 71 minutes and you have a starting point.

I am sure there are many to do this. but, this was a way I did this with an old PLC. you can get pretty close without libraries and look-up tables and such.

of course, someone else should be able to offer a much more accurate way to use the RTC for your project.

dave-in-nj i am trying with your way ,to find out how many seconds difference each day with other. When i find out the difference in seconds , how am i going to say to rtc (ds1307), for example if today getting dark at 17:45,start from 17:45 and measure 25 minutes until pwm goes from 10% -90% (5v).???????????
And, ds1307 can change the time one hour forward in March and one hour backward in December???