Introduction: Simple Analog Fade-in, Hold, Fade-out Circuit (used Here for Night Light)

After suffering one too many stubbed toes when stepping out of bed at night I decided to install a night light in our room. However I wanted the light to turn on and off automatically and not be on throughout the night. Connecting the light to a motion sensor serves the purpose, but the motion detector only has a ON-OFF signal and the light was too harsh on the eyes when I woke up to get out of bed. So I decided to build a circuit that would ramp in and out the intensity of the light to make it more comfortable to use. Finally, the lights were placed underneath the bed such that they provide good illumination while minimizing disturbance to the sleeping partner on the other side of the bed.

Since I was going to make the lights fade in I figured I should go ahead and also make them fade out. However, I also wanted the fade in and fade out rates to be different. This allows me to make it so the lights will fade in slowly so my eyes can easily adjust to the brightness but have the lights fade out quickly after getting back into bed so I can go back to sleep.

Here is my list of requirements:

  • Independent fade in and fade out delays
  • Controls so end user can adjust delays

That is where this circuit comes into play. My research uncovered many ways of achieving this. One method is to use a microcontroller and pulse width modulation to tune the performance. This could be the most powerful since it allows for a lot of control.

Another method is to use a 555 timer to emulate pulse width modulation. However the PWN duty cycle cannot be easily configured to manage the fade in and fade out delays independently unless you have two 555 timers in the circuit.

I settled on a purely passive components + transistors approach to keep things simple and inexpensive. Here is the result.

Step 1: FET Triode Operation.

This circuit takes advantage of the triode operating mode of a FET. A FET can operate in three distinct modes:

  1. Cutoff - Where the FET acts as an open switch and no current flows between drain and source.
  2. Triode (ohmic) - Where the FET acts as a variable resistor and the amount of current flowing between drain and source is controlled by the potential difference between the gate and the source (Vgs)
  3. Saturation - Where the FET is fully open acting as a closed switch and its internal resistance (RdsOn) is the only thing impeding the flow of current between the drain and the source.

So I decided to take advantage of the triode mode in a FET to control the current to the LED strip so the lights would fade in and out.

It is important to note that operating a FET in its triode region should be limited in time and current. The internal resistance of the FET when in triode mode can be high enough that depending on the amount of current pushed through it can generate a lot of power dissipation and cause the FET to fail.

Step 2: Circuit Layout and Explanation

This circuit uses all passive components with 2 N channel and 2 P channel MOSFETS. There is an extra P channel MOSFET in the power supply stage that provides polarity protection to the circuit, but the fades are accomplished with just 2 N and 2 P MOSFETS.

The circuit responds to a logic signal on JP1 and is configured so that a positive voltage will fade in and turn on the current through JP2 which will turn on whatever is connected across the JP2 jumper. A ground level voltage on JP1 will cause the current on JP2 to slowly decrease until it cuts off completely and whatever is connected to JP2 will turn off.

The power supply stage is very simple. It accepts DC at whatever voltage you may need to operate the device connected to JP2. Of course the rest of the components must be sized to handle this voltage. The supply stage contains a switch to turn the circuit on and off and a reverse biased P channel MOSFET for polarity protection. This MOSFET must be able to handle the full current draw, plus a safety margin, of the device connected at JP2 on the FADER stage.

The Fade In Mode

When power is first applied to the circuit at VCC, the N channel MOSFETs Q3 and Q4 will be off (assuming of course that the trigger signal at JP1 is low). With VCC connected, a high signal input at JP1 begins the process of turning on the device at JP2. First Q3 is turned on and Q2 (P MOSFET) is turned off. Because Q3 is turned on, it pulls down the voltage at the gate of Q1 which turns Q1 on. The current flows through Q1 and through the FADE_IN_TIME potentiomenter into C1. Remember that Q2 is turned off as long as the signal at JP1 is high so no current flows through it. At this point, C1 and FADE_IN_TIME form an RC pair with a time constant that ramps up the voltage at the gate of Q4. As the current flows through FADE_IN_TIME and C1 charges up, Q4 begins to enter its triode mode slowly opening the current flow between its drain and source which is also the current flowing through the device connected at JP2. If the signal at JP1 remains on long enough, C1 will charge up to VCC, which is why it must be rated to handled that voltage when installed.

The Fade Out Mode

When the signal at JP1 goes from high to low Q3 will shut off. This will cause the voltage at the gate of Q1 to go to VCC which stops the current flow into the RC portion of the circuit. Also, because JP1 is low, the voltage at the gate of Q2 will be low and it will engage the second RC circuit formed by C1 and FADE_OUT_TIME. So now, Q1 is shut down which means that the only thing keeping Q4 open and JP2 running is the voltage stored in C1. The charge in C1 begins to drain through FADE_OUT_TIME and Q2 which ramps down the voltage at the gate of Q4 causing it to enter its triode region again and progressively close the flow of current across JP2.

Function of other components

In the FADER section, R1 and R2 are pull-up and pull-down resistors that are used to neutralize noise at the gates of Q1 and Q3 as well as providing a path to discharge the gate capacitance which can make the MOSFETS respond with lag. The switch S2 provides a quick path to ground for the charge in C1. If pressed, it will short C1 to ground which will almost instantaneously shut down Q4 and JP2. It can be used as a safety switch for instance or to bypass a slow fade out time if required.

Optionally, S2 can be replaced with the ambient light enable/disable sensor. The motion sensor I have connected to JP1 has an enable/disable pin. I use this portion of the circuit with a light dependent resistor (LDR) so that the lights under our bed turn on only when the room is dark. This circuit also incorporates a DPDT switch to work as a quick discharge option.

The ENABLE_TP test point can be used to calibrate the ambient light sensitivity threshold. The datasheet for the motion sensor I used indicates what the voltage threshold is for the enable/disable pin. I calibrated mine by waiting for the natural ambient light in the room to reach the level I thought would be appropriate for the light to engage. Then I used a multimeter to measure the voltage at the ENABLE_TP and adjusted the LIGHT_SENSE potentiometer until the trigger value specified in the datasheet was reached.

Step 3: Implementation of the Circuit With Motion Sensor and LED Strip

So this is what the assembled circuit looks like on my setup. The power supply is 12 volts DC. The motion sensor I got from here: http://www.electrodragon.com/product/pir/ . The strip is a basic 12 volt white LED strip. The rest of the components I scavenged from old circuits or I ordered from DigiKey.

In my setup I added a small OLED display and an ESP8266 that connects to a temperature and humidity sensor. This extends the functionality adding a nightstand clock and environmental monitoring besides serving as just the motion activated night-light. I added this later since I had the components in hand.

As long as the power requirements for the MOSFETS operating in their triode region are kept to safe levels, this circuit can be used to modulate the start and stop of other events, such as small motors or sound players, etc. Have fun!

Maker Olympics Contest 2016

Participated in the
Maker Olympics Contest 2016