I would like to control a 48v led strip with the help of an arduino. I know how to dim high power leds with arduino pwm using mosfets and transistors but the application I want now is quite different.
I want to make a step dimmer using mains switch as the only input. Each time I flick the power switch on and off I want the arduino to cycle through a predefined dimmer setting.
Example-
power on (first time) ->100%
power off and on ( within 2 seconds ) -> led strip 50%
power off and on ( within 2 seconds ) -> led strip 10%
Using a 'mains switch' doesn't necessarily mean mains power. Using a wall switch just as a normal switch on an mcu IO doesn't need anything special.
The Arduino needs to be on the whole time if a time element is wanted. Having the whole setup turn on in the next mode is doable, just won't be keeping the time window.
INTP:
Using a 'mains switch' doesn't necessarily mean mains power. Using a wall switch just as a normal switch on an mcu IO doesn't need anything special.
The Arduino needs to be on the whole time if a time element is wanted. Having the whole setup turn on in the next mode is doable, just won't be keeping the time window.
Can't the arduino be 'on' only for a few seconds more than the delay be enough? just a few seconds more than the delay is detected?
Example - Arduino 'on' only for 5 to 10 seconds after mains power is turned 'off'. Enough time to wait for the mains to turn back 'on' and if it didn't detect it can stay 'off'.
You're going to need to describe your setup in detail.
What is powering the lights, what is powering the Arduino, what is controlling the lights, what exactly is the light setup (strip? controller? dimmer? is it even dimmable?), how is it controlling the lights, how is the Arduino controlling whatever it is controlling, all of it.
We have no idea what you're envisioning in your head. For all we know you think you can dim a ballasted LED setup by controlling the AC going into it, or you want the switch to control the AC side before the DC psu for the Arduino, or who knows what.
INTP:
We have no idea what you're envisioning in your head. For all we know you think you can dim a ballasted LED setup by controlling the AC going into it, or you want the switch to control the AC side before the DC psu for the Arduino, or who knows what.
Sorry, I should have been more specific. I want my arduino to control DC, not AC. Here, I'm attaching a very rough sketch of my setup.
Here the arduino is powered on by a 5v usb wall wart which is connected to 220v mains supply. The 48v led driver is also connected to the same 220v mains supply. The transistor in the picture will be replaced by a suitable mosfet module for arduino.
The arduino should be able to detect the ac power loss and start cycling through the predefined pwm modes each subsequent power on attempt if within 2 seconds.
You say LED driver. With those numbers, we might be talking about a 150mA constant current supply, not an 48V supply. It would be a very bad idea to try to switch it on the constant current side. I have LED drivers that immediately kill a COB led when it is hotplugged, which is essentially the same as switching. Is that the case?
it is not a CC driver. Just a regular 48v wall wart that has max 150mA output. The strip itself needs way more current than that but the supply is limited just to 150mA.
You can update a variable if EEPROM every time the Arduino resets (ie in setup()), and use that
to control the state of the LEDs brightness. Put another way use a state machine, but store its
variables all in EEPROM.
MarkT:
You can update a variable if EEPROM every time the Arduino resets (ie in setup()), and use that
to control the state of the LEDs brightness. Put another way use a state machine, but store its
variables all in EEPROM.
That's a brilliant idea! Just what the doctor ordered. Why didn't I think of that before??
So basically there won't be anything inside the loop right? I think I got it figured. Will upload a code tomorrow and see if it works.
@MarkT - all these years I never knew that the arduino had an EEPROM :-\ . You saved me from a lot of headache and extra components.
Here is the code that I compiled and tested on a single 8mm LED and it worked fine. Please advice if it needs and improvement or has any faults.
#include <EEPROM.h>
int led = 5; //Define pin number for led
int brightnessA = 64; //Define brightness at 25%
int brightnessB = 128; //Define brightness at 50%
int brightnessC = 255; //Define brightness at 100%
byte ledState; //Define the state for led as byte
void setup()
{
pinMode(led, OUTPUT); //Define pin for led as output
Serial.begin(9600); //Open the serial port at 9600 bps:
byte cycle =EEPROM.read(0); //Read stored value (0-255) from EEPROM address 0
//Since no values were stored in the EEPROM
//because of first time use, the default value
//of 255 will be fetched
if (cycle == 255){ //If stored value in EEPROM = 255
ledState = cycle-254; //Then led state = 255-254 = 1
analogWrite(led, brightnessA); //Write led at 25%
EEPROM.write(0, ledState);} //Write new value into EEPROM address 0
//This will set the value for the first time
//in the EEPROM
else if (cycle == 1){ //If stored value in EEPROM = 1
ledState = cycle+1; //Then led state = 1+2 = 2
analogWrite(led, brightnessB); //Write led at 50%
EEPROM.write(0, ledState);} //Write current value into EEPROM address 0
else if (cycle == 2){ //If stored value in EEPROM = 2
ledState = cycle+1; //Then led state = 2+1 = 3
analogWrite(led, brightnessC); //Write led at 100%
EEPROM.write(0, ledState);} //Write current value into EEPROM address 0
else if (cycle == 3){ //If stored value in EEPROM = 3
ledState = cycle-2; //Then led state = 3-2 = 1
analogWrite(led, brightnessA); //Write led at 25%
EEPROM.write(0, ledState);} //Write current value into EEPROM address 0
Serial.println(ledState); //Print the newly stored value in serial monitor
}
void loop()
{
}
Using EEPROM means you're planning on cutting power to the Arduino? As I said, if you turn it off, it won't be able to keep any time. I held back on the EEPROM advice since it seemed the timing was important to you.
If you're turning it off for the sake of saving whatever little bit of current it takes for the Arduino to run and do nothing, I don't think it's worth the EEPROM use.