8
\$\begingroup\$

How can I have a LED either on or off (not in between) depending on night or day with basic electronics? I have created the circuit below, but it only shines and in darkness it dims.

This is my attemp

The photo-resistor is about 3kΩ when light shines and about 1MΩ when dark.

I want my LED to shine at night and be off at day.

What is the simplest way I can achieve this?

\$\endgroup\$

2 Answers 2

10
\$\begingroup\$

You need the LED to be lit when the photoresistor is high resistance. So replace the photoresistor with a fixed resistor R3, to supply the base current to turn the transistor on.

Then you need the LED to turn off when the light shines, and the photoresistor is low resistance. So connect the photoresistor from base to ground.

Now, when its resistance is low enough, it will drain the current from R2 to ground, and hold the base voltage below 0.6V turning the transistor off.

Say, at 3kilohms we aim to get the base voltage down to 0.3V. Then 0.3V/3k = I = 0.1ma. Then R3 must drop the remaining voltage 4.7V at 0.1ma, so R3 should be 47k.

Now the transistor will start to turn on when the photocell resistance exceeds 6 kilohms. If that's still too bright, increase R2.

Answer in a schematic

Schematic

\$\endgroup\$
6
  • 3
    \$\begingroup\$ You can add a snap-action (hysteresis) feature to this circuit, too. Add a PNP transistor with its emitter to +5V. Connect a 100K resistor between the base and the junction of R1 and LED2. Connect another resistor from the collector to the base of the NPN. The value of this last resistor will determine the amount of hysteresis. Start with 100K and experiment from there. \$\endgroup\$
    – Dave Tweed
    Commented Jan 10, 2013 at 23:46
  • \$\begingroup\$ Good job on the schematic! I updated the answer to call the new resistor R3 to match the schematic. Note that its value should be 47K or around that figure. @Dave T: good idea on adding hysteresis (snap action). \$\endgroup\$
    – user16324
    Commented Jan 11, 2013 at 9:41
  • \$\begingroup\$ This circuit won't work. The OP said that R2 will be about 3 kOhm when light. That is still much higher than this circuit requires to turn off the transistor and therfore the LED. Also, the LED will be quite dim since it will get less than 1.5 mA. \$\endgroup\$ Commented Jan 11, 2013 at 13:38
  • 1
    \$\begingroup\$ @Olin : read comments re value of R3. You are correct that 2.2K is wrong on the schematic, but I didn't put the schematic up there. A high efficiency LED will be bright enough for some purposes at 1.5ma; if it isn't, the OP can reduce R1 to fix that. \$\endgroup\$
    – user16324
    Commented Jan 11, 2013 at 13:42
  • \$\begingroup\$ No, I shouldn't have to read the comments. I see now that you mentioned R3 should be 47 kOhms, but that's not what the schematic says. Also, you can only decrease R1 so far before the LED current becomes limited by the gain of the transistor. With 47 kOhm for R3 and R2 completely off, you get 94 uA base current. At 100 gain that supports 9.4 mA LED current. That could be quite bright, but you are also loosing the threshold then, and there is still no snap action as the OP asked for. Basically, this circuit does not meet the specs. \$\endgroup\$ Commented Jan 11, 2013 at 13:50
11
\$\begingroup\$

The logic is inverted in your circuit. Photoresistors have higher resistance when dark, so the current will be small when dark and larger when light. That means you need inversion between the LDR current and the LED current since you want the LED to light when it is dark.

Since you want the LED to be either full on or full off, you need a high gain centered around the setpoint, or even better, a little hystersis.

So to summarize, you need something that inverts and has a little hysteresis. That is pretty easy to do with a opamp. I don't know whether you consider that "basic electronics" or not.

I have to run off now, but later tonight or tomorrow morning I can provide a circuit.

Added:

I'm back, so can now post a schematic of what I only had time to talk about briefly before.

This circuit will light the LED when dark, it will snap between full on and full off, and it can drive the LED to full brightness. The last two are things the other single-transistor solution can't do.

R1 and R2 form a voltage divider. This voltage goes up as R2 goes up, which means higher voltage when dark. When this voltage gets to about 500 or 600 mV, a little current flows thru the base of Q2. That causes a lot more current to flow thru its collector, which then also flows thru the base of Q1. That allows a lot lot more current to flow thru the collector of Q1, which lights the LED. With the values shown, the LED current will be nearly 20 mA when on, which is the limit for most ordinary discrete LEDs. Make R4 bigger if you want less LED current.

R3 provides a little positive feedback, also called hysterisis. It only adds or subtracts a small current from the base of Q2, but enough to tip the whole circuit to one side or the other when the light level is just at the threshold between on and off. Note how it turns Q2 on more when current is flowing thru the LED. This is what provides the snap action.

The R5 is there just to limit the Q1 base current. Without it in darkness, the Q1 base current would only be limited by the gain of Q2. It's not a good idea to rely on the maximum gain of a transistor. It is rarely specified, and can be many times more than the guaranteed minimum gain. The value of R5 was chosen to still allow for enough Q1 base current so that Q1 can saturate at the maximum LED current of 20 mA.

R1 adjusts the light level at which the circuit trips. Lower values will move the threshold towards light and higher values towards dark.

\$\endgroup\$
2
  • \$\begingroup\$ How does 2N4401 differ from 2N4403? Can I use two 2N4403? \$\endgroup\$ Commented Mar 27, 2014 at 22:04
  • 2
    \$\begingroup\$ @Alexa: The most cursory look at the datasheets or even just the schematic above shows that 2N4401 is NPN and 2N4403 PNP. No, they can't be interchanged. \$\endgroup\$ Commented Mar 28, 2014 at 12:31

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