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?

  • 3
    \$\begingroup\$ You don't need to step 5V up to 12V; you've already got 12V going into the system. \$\endgroup\$
    – Hearth
    Nov 8, 2018 at 15:03

2 Answers 2


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.

  • \$\begingroup\$ I read somewhere that the use of 7805 will generate heat and excessive power loss. \$\endgroup\$ Nov 9, 2018 at 3:09
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Remco Vink
    Nov 9, 2018 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.


#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);

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.