I want to control brightness of a cob led. I have a cob led that has a maximum working voltage 12v, but my supply is 24v. I tried to control brightness with skech AnalogInOutSerial with Arduino uno board and it was working fine. Due to little space for pcb, i wanted to make same thing with Attiny85. I uploaded same skech but with other configuration for analog pin and pwm pin and the led is flashing. It is not fast flashing but it can be seen with eye. Cob led is connected with arduino through mosfet IRLZ44N.
This is the skech program
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A3; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 0; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 1, 120);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}
Any idea why is led flashing? Attiny85 is working with internal 8mhz clock, but mega328 on arduino board have an oscilator of 16mhz, could here be the catch?
Attiny85 is working with internal 8mhz clock, but mega328 on arduino board have an oscilator of 16mhz, could here be the catch?
As long as the clock rate you use matches the clock rate you select when you program it then no.
More likely is the fact that you are destroying your LED by giving it a signal that is 24V peak. These things should be fed with a constant current supply not a constant voltage and never a 24V peak signal.
drimer525:
Any idea why is led flashing? Attiny85 is working with internal 8mhz clock, but mega328 on Arduino board have an oscillator of 16mhz, could here be the catch?
Well, when you select your "board type" to the appropriate Attiny85 option, this should compile for the corresponding clock speed if you have it set up correctly.
Why have you included "Serial.begin(9600)"?
Try using a much longer delay - and see what happens. 500 for a start.
Your map function is peculiar - mapping down to 120. Is this your idea of running a 12 V COB LED at 24 V? That is a really inappropriate way to even attempt to do it. If we knew what sort of LED assembly you have we could better know how to deal with it.
To map down from 1024 to 128 just
outputValue = sensorValue >> 3;
Please read the forum instructions and go back to your first posting using the "More -> Modify" option below the right hand corner of your post - don't post it again - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code and click the icon.
Paul__B:
Why have you included "Serial.begin(9600)"?
This was from original code and I forgot to delete it..
Paul__B:
Try using a much longer delay - and see what happens. 500 for a start.
Ok, i will try it.
Paul__B:
Your map function is peculiar - mapping down to 120. Is this your idea of running a 12 V COB LED at 24 V? That is a really inappropriate way to even attempt to do it. If we knew what sort of LED assembly you have we could better know how to deal with it.
Yes this was my idea, how would you set the limits, or do you have any other solution in mind?
Then be aware that this will not work. It is the peak current that matters in damaging an LED not the average current. Yes the average current will determine the average heating and there are many people on the internet that think that is all that matters but they are wrong.
The problem with that thinking is:-
It assumes the heat can dissipate from around the junction into the surrounding chip instantly. It can not, it takes time and during that time the junction will be hotter that the maximum junction temperature permitted.
A sudden thermal shock given with this peak current stresses the bond wires which over time can flex and break.
You get a thing called carrier depletion which reduces the number of free charge carriers in the junction which reduces the efficiency of the light making process in the junction.
The proper way to power a high power LED like this is either :-
To vastly under run the current so as to keep it safe.
or
If you have access to the full datasheet for the led (Not very likely for Ebay stuff), there will often be a curve showing time vs current, i.e. if you use 1ms pulses you may use up to X current, if you use 10ms pulses you may use up to y current. Or some other way to say how much current for how long.
Chinese datasheets may lack that information.
The important part is that power increases faster than current, i.e. when applying double current in short pulses, the power may be 3 times as high, i.e. there are multiple limits: Maximum average current, maximum peak current, maximum average power and maximum peak power. You have to stay below all of these.
Paul__B:
Is this your idea of running a 12 V COB LED at 24 V? That is a really inappropriate way to even attempt to do it.
And I really, really meant it, note the bold text. Flashing red text? Couldn't be bothered at the time.
HKJ-lygte:
The important part is that power increases faster than current, i.e. when applying double current in short pulses, the power may be 3 times as high, i.e. there are multiple limits: Maximum average current, maximum peak current, maximum average power and maximum peak power. You have to stay below all of these.
No, it's worse than that even. It is not obvious from the images, what is actually limiting the current on that device. I see no resistors and the back is simply an aluminium heatsink (board substrate). We then suspect that it is limited only by the internal resistances of the LEDs (as with cheap LED torches ). This means that any increase in the voltage applied beyond the nominal 12 V will result in a massive increase in the current drawn, whether or not PWM is applied.
We must assume that if you are driving this with 24 V, the current is being limited only by the FET, power supply and wiring and it is no surprise that it is flickering under these absurd conditions!