# Attiny45 12V LED Driver

I want a fading effect on a 12V led strip when power is turned on/off. I want to keep it simple and efficient, so I choose an Attiny45. The problem is that for the Attiny to work, I would first need to step down 12v to 5v and then step up 5v to 12v.

Are there any better alternative led drivers? If not what circuit should I use in conjuction with the Attiny to accomplish the task?

• You don't need to step 5V up to 12V; you've already got 12V going into the system. – Hearth Nov 8 '18 at 15:03

You only need to reduce the 12VDC to 5VDC to power the ATTINY, you can then use something like a MOSTFET to turn the 12VDC going to the LEDs on and off. You can using the ATTINY's builtin hardware timer to make the PWM smooth and steady.

Here is a simple example circuit....

simulate this circuit – Schematic created using CircuitLab

You can also add a decoupling cap across the ATTINY power pins, but it can work without it at slow clock speeds. Some will say that you need pull down and buffer resistors for the MOSFET gate pin, but you don't. Without the pull dow, the LEDs might blink on briefly when the system powers up before the code in the ATTINY has a chance to initialize the port, and at slow PWM speeds with a 5V driven gate the buffer resistor is unnecessary.

• I read somewhere that the use of 7805 will generate heat and excessive power loss. – Electric_90 Nov 9 '18 at 3:09
• @Electric_90 The 7805 is a linear regulator, they are not the most efficient type of regulators and some of the energy will be dissipated as heat. A linear regulator of 12Vin to 5Vout is probably around 40% efficient. So the amount of power your attiny is using multiplied by 1.5 is the amount of heat wasted in the regulator. However if you are only using a few mA for a Attiny this should do fine. Else you have to look at more efficient switching regulators. – Remco Vink Nov 9 '18 at 7:38

simulate this circuit – Schematic created using CircuitLab

After some digging on the internet I came up with the following circuit and code for a smooth fade in and fade out effect when power is turned on/off.

CODE :-

#include <math.h>

float val;

void setup()
{
pinMode(0, OUTPUT);
for(int a = 3000; a<=5000; a++)
{
val = (exp(sin(a/2000.0*PI)) - 0.36787944)*108.0;
analogWrite(0, val);
delay(1);
}
}

void loop(){}

• That capacitor on the LED is just wasting power on the FET. Besides that, this is the same circuit in @bigjosh answer. – Edgar Brown Nov 10 '18 at 17:26
• The capacitor is there for fade out effect. – Electric_90 Nov 11 '18 at 9:56
• that can be achieved controllably via PWM from the uC. – Edgar Brown Nov 11 '18 at 10:06
• But I want the fade out to occur when power is turned off. – Electric_90 Nov 11 '18 at 10:07
• You can sense the power line with a voltage divider to the ATiny. But what is the purpose of having the uC there then? – Edgar Brown Nov 11 '18 at 10:16