12v/2W LED control ANALOG

Design:
We need to detect the level of the ambient light, which can be done by an LDR (Light Dependent Resistor)
Assume this level is converted to and 'light'/'dark' signal or 'on'/'off' signal, then we need a next signal which limits the 'on' time to a user controlled time. That signal should turn on/off the LED, but we also need to control the light level by a PWM, analog that can be controlled by an RC time.

My first thought was to use 555 timer chips. But how many do you need. Digitally speaking there are 3 different states:
1) Daylight, the LED is off
2) Night, the LED is on
3) Night, the LED is off since the 'on' time duration is passed and the light should stay off
Thus digital you would need two flip-flops to track these three states. Analog: I was not able to implemnent this in one 555 timer, I needed two. Maybe the digital explanation about states clarifies that this is likely not possible.

After above considerations I drew the timing diagram, here there is a lot flexibility, since you can as well invert the U(LDR) signal by swapping the LDR and R1/R2. Here it is crucial to know that the SET has priority over RESET in the 555. See the functional block diagram:

Functional model of the 555 timer:
- When the Threshold (TH) pin is above 2/3 of the supply Vcc
  then the FF is RESET, the output pin (OUT) turns to 0V.

- When the Trigger (TR) pin is below 1/3 of the supply
  then the FF is SET, the output pin (OUT) turns to Vcc.

- In case both above conditions are met:
  SET has priority over RESET.

- The 'control' level can be externally influenced by aplying
   a voltage on the Voltage Control (VC) pin.

- The FF controls a Discharge (DIS) pin
   when the output is low (0V) then Qn is high and the
   transistor conducts, current can flow from DIS to ground.

- Function is overruled by holding the flip-flop in reset
   when RSTN pin is low, FF is in RESET state, output=0V.

- Diagram includes pin numbers related to 8 pin DIL package.


Supply:
4.5V ≤ Vcc ≤ 16V


IC1:
Converts the light intensity, measured by the LDR, to an on/off signal IC1(OUT). The ambient light level is controlled by R2.

IC2:
Controls the on time by using an RC time. The RC time t = 1.1 * R5 * C2.
When IC1(OUT) is high, (ambient light above the set level, U(LDR) turns low), the capacitor C2 charches fast via R6 and D1.
When IC1(OUT) gets low, (it gets dark), C2 discharges into IC1(OUT). First the real on/off timed output (IC2(OUT)) needs to be toggled, in this case it is turned low by Resetting the FF by using TH. TH should get higher than 2/3 Vcc, this is done by inverting IC1(OUT) by T1. Now we have to toggle the output again when the capacitor is discharged, in this case we Set the FF by connecting the capacitor voltage to the TR pin. All this results in signal IC2(OUT).

IC3:
Implements the PWM by the RC time R10/R11/C4 The charge and discharge uses two different paths, controlled by D2 and D3, thus the resistor postion of R11 controls the PWM pulse width. Calculation is in the diagram below. This PWM signal should only be generated during the on-time. Since the reset pin is low active, we need to invert the output of IC2, this is done by T2.

Power driver:
The 555 cannot direclty control the LED. The BD139 can but it requires a base current of 1/10th of the collector current, collector current = 2W/12V=167mA, thus Ib=17mA to reach saturation. This is hard for the 555 in PWM fast switching mode, but more important, the transistor does not get fast enough out of saturation, thus the LED is always on. Therefor T3 is added, this highly reduces the current delivered by the 555. The total hFE is 100*40=4000, thus Ib is less than 1mA. Further it reduces how hard the BD139 goes into saturation and the base charge can discharge over T3 switching off T4. Transistor T3/T4 are put into a darlington configuration. The led 'module' X1 is turned on/off by the PWM signal on the basis of this darlington. You can also use a MOSFET (better solution), but I did not have those available (AO3400)

Test:
This schematic is implemented and tested, it works, BUT.....
Under normal conditions this implementation works well, there is however a case which is not explicitly mentioned before:
What happens when the ambient light level increases to daylight while the led is in the on state?
The implementation below does not turn off the led in that situation, it stays on. Nasty side effect of a corner case, but good to be aware of.

Cost:
For an overview of the cost comparason Analog/Digital, see the cost comparison page.

Schematic: