I am pretty new to Arduino and am doing a research experiment in which I need a light bulb to increase from no light to full intensity over the course of 30 minutes. One of research professors who has some experience with Arduinos told me to use the Arduino Fade program with PWM and change the delay. I currently have the delay set to 1,800,000 milliseconds (30 Minutes), but when I run the program nothing is happening with the bulb. If I run the program at 1000 ms I can see the affect, but it appears to be increasing the light too quickly and fading slower. I need the reverse to happen basically.
Does anyone know what I need to do to fix this issue? Is there a different code I should use? Thanks in advance.
An Arduino can't control or power almost all types of "light bulbs", except small LEDs. You will need external circuitry and an external power supply for the bulb.
Post a wiring diagram (pencil drawing) and details on the components. Also post the code, using code tags. See the "How to use this forum" post for instructions.
I currently have the delay set to 1,800,000 milliseconds (30 Minutes)
You shouldn't delay() for 30 minutes... Your program isn't doing anything during the delay() time. With 256 PWM steps you should delay about 7 seconds between steps.
but it appears to be increasing the light too quickly and fading slower. I need the reverse to happen basically.
Your eyes are not linear. Incandescent bulbs are not linear. But with a long-fade it's (usually) not as important since you can't perceive the rate-of-change. (You may see the steps at low-levels.)
I am using another piece of equipment provided by a professor. It specifically is a PWM AC Light Dimmer module
I'm not really good at drawing wiring diagrams (again, very little experience) but I will show you how I have the external piece attached to the light bulb and the Arduino.
The code is as follows:
int led = 3; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 3 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 3:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(1800000);
}/[code]
Your code is going to take 30 minutes X 51 steps = 25.5 hours to reach full brightness, and the same time again to fade down. So I think it will work perfectly, doing exactly what you are telling it to do.
If you have no experience of programming, you have to imagine yourself, alone in a small room with no windows, following a list of instructions, one by one. You don't know what purpose of instructions is but you know you must follow each instruction exactly, and in the order given. That's what a computer, including an Arduino, does. So read your code again, and imagine yourself in that room, with only a notepad and pen, a clock, and large dimmer switch dial on the wall with the numbers 0 to 255 marked around it. Follow the code step by step and use your notebook to record the current values of variables and use the clock to time your delays.
[quote
Your code is going to take 30 minutes X 51 steps = 25.5 hours to reach full brightness, and the same time again to fade down. So I think it will work perfectly, doing exactly what you are telling it to do.
[/quote]
Yes, but I need to reach full brightness in 30 minutes, not 25.5 hours.
You have one Algebra expression to solve and one number to change as a result of that calculation. My suggestion would be to stop posting and get to work!
Evanphil45:
[quote
Your code is going to take 30 minutes X 51 steps = 25.5 hours to reach full brightness, and the same time again to fade down. So I think it will work perfectly, doing exactly what you are telling it to do.
Yes, but I need to reach full brightness in 30 minutes, not 25.5 hours.
I know that. But the Arduino does not. The Arduino is doing exactly as you are telling it.
WattsThat:
You have one Algebra expression to solve and one number to change as a result of that calculation. My suggestion would be to stop posting and get to work!
Thanks for the help. I just want to double check and confirm that there are 51 steps. If so, I have figured out what the delay should be to achieve full brightness in 30 minutes.
I am going to measure the exact electron output during the 30 minutes when a spectrometer becomes available in a few weeks with the help of a professor. In the meantime, I want to begin running trials, and I just wanted to confirm my calculations are correct so that my trials will not have errors.
jremington:
Have you noticed that 30/51 = 0.59 minutes/setp, or 35 seconds/step?
Yes, I think so. Using PaulRB's equation (30 min x 51 steps = 25.5 hours) I calculated I needed .589 minutes to reach full intensity at 30 minutes, assuming there is 51 steps. I converted 0.589 minutes to milliseconds and input that number in the delay. I was just double checking that there are 51 steps.
Programming issues aside, you should verify that the bulb being used is explicitly specified to be dimable. A lot of household AC LED bulbs are not and they typically say one way or the other on the packaging.
MrMark:
Programming issues aside, you should verify that the bulb being used is explicitly specified to be dimable. A lot of household AC LED bulbs are not and they typically say one way or the other on the packaging.
you shoud read the post, not only the title, before you comment.
"If I run the program at 1000 ms I can see the affect, but it appears to be increasing the light too quickly and fading slower. I need the reverse to happen basically."
PaulRB:
The code changes the brightness from 0 to 255 and back to 0 again in steps of 5. 255/5=51 steps each way.
If you want a smoother fade, use steps of 1 instead of 5 with a delay of 7 seconds.
Thanks for the help. I tried using steps of 1 and a delay of 7 seconds, but the light bulb was not brightening at all over the course of the 30 minutes. However, at steps of 5, the light was brightening as it should (albeit, it seemed to only increase for a total of 24 minutes, but I'll figure that out myself).
int led = 3; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 3 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 3:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(7000);
}
The more testing I do, the more I'm thinking it may be a light bulb issue. Although, like I've said I can see the affect fine on lower delays, and can even see the affect over the course of 30 minutes with fadeAmount being 5.