Saturday, February 12, 2011

LED Fade in / Fade out

Introduction

I found a small project at another site about fading an LED in and out smoothly, without a microcontroller. I changed it a bit. In my version I removed one of the transistors and changed some resistor values. This is supposed to result in lower costs and smaller footprint. I know it's a very small difference, but still.

The circuit

In default state (when S1 button is depressed) capacitor C1 is discharged, so transistor T1 is closed, hence the LED is off. When the button is pressed, C1 gradually charges, which gradually opens T1 lighting up the LED slowly. When the button is released, C1 discharges through R1-R2, slowly closing T1, gradually fading the LED. (If we omit R2, the discharge process would take forever a very long time.) By changing the values R1, R2, C1 one can change the speed of fade in, fade out. The given values result in roughly 1.5 second for both fade in and fade out.
The simpified circuit

22 comments :

  1. If you were a bit more specific I might be able to help...

    ReplyDelete
  2. Well I did everything in the diagram I even did that 1k resistor short from V+ to GND. My transistor is a 2n2222. I used a 2200uf Capacitor and I'm running the circuit from 9V not 5V. (I don't think it matters anyway.)

    ReplyDelete
  3. The capacitor should not make much of a difference, right. I know it sounds obvious, but can you double check the connections of the LED and the transistor? Also, when using 9V instead of 5V you might have to adjust the resistors.
    Can you tell me what exactly is the symptom? "Not working" can mean it doesn't switch on, or that it doesn't switch off.

    ReplyDelete
    Replies
    1. Viktor I was wondering I'm running a 12v led strip and want a fade in and out effect but don't want to cut voltage down at all. How would I got about the circuit to still get about a 3sec fade in/out. Thanks.

      Delete
    2. There is nothing stopping you from experimenting with different R and C values in this circuit... :)

      However, for anything more complex than the above circuit I would go with a microcontroller, especially if the project has one anyway.

      Delete
  4. Sorry Vitya i'm an eediot!!! I thought that it dims on and off by itself, I didn't realize that I have to press the button.

    Sweet site by the way, I really like your homemade bench power supply.

    ReplyDelete
  5. Hi, I am try to light up 13 steps on a set of stairs, each step has 2 LED's, one either side of the step, 26 LED's in total.

    I want each step to fade on gradually so the step 1 comes on, then 1/4 second later step 2 fades on, then 1/4 second later step 3 fades on and so on up to step 13.

    Then when the power is switched off each step fades off starting with step 1 up to step 13.

    I propose to use 13 of your above circuits, one for each step.

    Can you tell me what value of capacitors I need for each circuit and if I need different resistors?

    vp

    ReplyDelete
  6. I built the circuit. Works as advertised -- pretty cool!

    You mentioned another site -- the one that inspired you to design this one-transistor fader. Do you still have the other site's URL handy?

    ReplyDelete
  7. Wow. I just spent far more time on this circuit than I had been expecting to. Figuring out how it works intuitively is straightforward, as is calculating the steady-state voltages. Move R2 so that it branches off before R1, on the other hand, and the steady-state calculations get more interesting. (I say more interesting as a person who's just starting out learning electronics; I'm sure it's trivial that way too to someone who's been doing this for ages)

    ReplyDelete
  8. @simmonmt: I'm afraid I don't have the site anymore.

    Good luck learning electronics - it's a lot of fun!

    ReplyDelete
  9. @Anonymous: I think you can use the values in my circuit as a starting point, then you can experiment with different values to get the desired effect.

    ReplyDelete
  10. @simmonmt: I think this is the other website http://pcbheaven.com/circuitpages/LED_Fade_In_Fade_Out_Dimmer
    I took mine from there for a 5m LED-strip in the living at the curtains.

    ReplyDelete
  11. wow lol this works

    ReplyDelete
  12. I want it to only fade out. What changes do I need to make plaese?

    ReplyDelete
    Replies
    1. That's very simple, you just have to use a capacitor paralel to the LED and its resistor and that's it.

      Delete
    2. Thanks for you help.

      Delete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Hi Vitya,

    I only have a 2N3904 transistor ---having one heck of a time finding a 2N2222 transistor but not in 100+ quantities. Will the 2N3904 work in this circuit? And the capacitor, the best I have is a 470uF ---I suppose this regulates the fade on/off time ---am I correct? Anything you have to say will be greatly appreciated.

    ReplyDelete
    Replies
    1. Hey Jack,
      Any transistor should be OK, since there is nothing special to the circuit. It doesn't work on high frequencies etc.
      Yes, using a smaller capacitor will result in faster transition. However, you can use several 470uF capacitors in parallel to achieve greater capacitance. This is just an idea, obviously I don't know your setup, maybe you don't have room for more capacitors, but it is a common way of achieving greater capacitance with standard values.

      Delete
    2. Thanks Viktor,
      I will give it a try. I have found a 1000uF capacitor and will buy it when I get the time to do so. Multiple 470uF's will take up to much space and the 1000uF appears to be 2/3 the size. New at this ---4 weeks old ---hobby. Understanding transistors on my own will take time.

      Thanks for the help,
      Jack

      Delete