Time Delay Dimmer for Led's

Hi Everyone,

I am just new to arduino and was wondering if it would be possible to use an arduino to create a dimmer switch with a time delay for running an led strip.

Ideally I want it to fade from 0% brightness to 100% brightness over 30 seconds when turned on and fade from 100% brightness to 0% brightness over 30 mins when turned off.

If anyone knows if this is possible I would be grateful for any advice.

Best Regards
Chris

Yes

Thanks for the fast response,

Any idea how I would need to code it as I don't have much knowledge of coding

What knowledge do you have ?

Have you got an Arduino and if so, what type ?

Assuming that you have an Arduino then what have you tried ?
Where is/will the LED strip get its power from ?

I have an arduino Uno and was powering it from pin 9 and ground i can get it to light up changing the example for fade but that is it.

I have found codes that claim to do what i need online but when i try them they are way to fast even with the delay increased

powering it from pin 9

You are in grave danger of damaging the Uno by taking too much current from it. The LEDs should be powered from an external supply.

As to code that does not do what you want, please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless and post the code here

I didn't realise it would draw that much current that it would damage the Uno.

I think i will keep tinkering with one of the codes i found online as I seem to be starting to get somewhere but i'll use an external supply when i put it into use.

Thanks for your help

You can refer to how to dim LED in a period without using delay () function

Thats very handy thank you

Can you show your current code?

Blackfin:
Can you show your current code?

This is what I have so far
// Fade an output on/off using analogWrite(pin,value) and a timer
// CONFIGURATION
#define OUTPUT_PIN 3 // PWM pins are marked ~ (3,5,6,9,10,11)
#define START_FADE_PIN A5 // input pin, LOW starts the fade
#define MAX_BRIGHTNESS 255 // max value: 255
#define MIN_BRIGHTNESS 0 // min value: 0
#define FADE_INTERVAL 10000 // ms between fade steps, smaller is faster
// END CONFIGURATION
// DECLARATIONS
byte setpoint; // value to fade towards
byte value; // current value
unsigned long timeforfadestep; // fade step timer
// END DECLARATIONS
void setup() {
pinMode(START_FADE_PIN, INPUT_PULLUP);
} // END SETUP
void loop() {
if (!digitalRead(START_FADE_PIN)) setpoint = MAX_BRIGHTNESS;
else setpoint = MIN_BRIGHTNESS;
if (millis() > timeforfadestep) {
timeforfadestep = millis() + (unsigned long)FADE_INTERVAL;
if (value < setpoint) value++;
if (value > setpoint) value--;
analogWrite(OUTPUT_PIN, value);
}
} // END LOOP

It works fine for the fade in but it fades out over the same amount of time if someone could help I would appreciate it as I now have no clue what i need to do as it's taken me a few weeks of tinkering with code i found online to get this far.

Ideally I want it where when I disconnect A5 it takes 30 mins to fade out

Code tags are nice

micahfriesen:
Code tags are nice

Sadly I can't take credit I found the code that way

ceason87:
Sadly I can't take credit I found the code that way

But you can Auto format it in the IDE and post it here in code tags

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

// Fade an output on/off using analogWrite(pin,value) and a timer

// CONFIGURATION
#define OUTPUT_PIN 3 // PWM pins are marked ~ (3,5,6,9,10,11)
#define START_FADE_PIN A5 // input pin, LOW starts the fade
#define MAX_BRIGHTNESS 255 // max value: 255
#define MIN_BRIGHTNESS 0 // min value: 0
#define FADE_INTERVAL 10000 // ms between fade steps, smaller is faster
// END CONFIGURATION

// DECLARATIONS
byte setpoint; // value to fade towards
byte value; // current value
unsigned long timeforfadestep; // fade step timer
// END DECLARATIONS

void setup() {
  pinMode(START_FADE_PIN, INPUT_PULLUP);
} // END SETUP

void loop() {
	if (!digitalRead(START_FADE_PIN)) setpoint = MAX_BRIGHTNESS;
	else setpoint = MIN_BRIGHTNESS;

  if (millis() > timeforfadestep) {
    timeforfadestep = millis() + (unsigned long)FADE_INTERVAL;
    if (value < setpoint) value++;
    if (value > setpoint) value--;
		analogWrite(OUTPUT_PIN, value);
  }
} // END LOOP

like that?

For "regular" LED strips you'll also need a driver (you can leave out the diode since you have a non-inductive load). With addressable LEDs you still need a separate power supply but you don't need a driver. (The software for addressable LEDs is more complicated.)

For the software I'd suggest you study the Fade Example and the Button Example so you can understand how if logic works.

Rather than "finding" existing code it's MUCH better if you start with something simple that you can understand, and then add a few lines of code at a time testing as you go-along.

You'll probably need a couple more loops... A fade-up loop, a fade-down loop with a "do nothing" **while() loop **in-between that just sits there looping until you press the button. ...Maybe an identical do-nothing loop at the beginning before the button is pushed. There are also for() loops and **do-while() loops **that you might find useful Generally, these loops are nested inside you main loop().

ceason87:

// Fade an output on/off using analogWrite(pin,value) and a timer

// CONFIGURATION
#define OUTPUT_PIN 3 // PWM pins are marked ~ (3,5,6,9,10,11)
#define START_FADE_PIN A5 // input pin, LOW starts the fade
#define MAX_BRIGHTNESS 255 // max value: 255
#define MIN_BRIGHTNESS 0 // min value: 0
#define FADE_INTERVAL 10000 // ms between fade steps, smaller is faster
// END CONFIGURATION

// DECLARATIONS
byte setpoint; // value to fade towards
byte value; // current value
unsigned long timeforfadestep; // fade step timer
// END DECLARATIONS

void setup() {
 pinMode(START_FADE_PIN, INPUT_PULLUP);
} // END SETUP

void loop() {
if (!digitalRead(START_FADE_PIN)) setpoint = MAX_BRIGHTNESS;
else setpoint = MIN_BRIGHTNESS;

if (millis() > timeforfadestep) {
   timeforfadestep = millis() + (unsigned long)FADE_INTERVAL;
   if (value < setpoint) value++;
   if (value > setpoint) value--;
analogWrite(OUTPUT_PIN, value);
 }
} // END LOOP



like that?

Yes, thank you.

Hi guys I appreciate the assistance but have found an easier way of doing it with a fish tank timer I found on amazon

Thanks again

Chris