Evil Mad Scientist Laboratories Evil Mad Scientist Laboratories

Making the World a Better Place, One Evil Mad Scientist at a Time

 
About EvilMadScientist  :  Buy Stuff  :  Contact  :  Forums  :  Links  :  Articles  :  Search  

A Simple and Cheap Dark-Detecting LED Circuit

Components Complete
Stupidly bright.

Here's a simple problem: "How do you make an LED turn on when it gets dark?" You might call it the "nightlight problem," but the same sort of question comes up in a lot of familiar situations-- emergency lights, street lights, silly computer keyboard backlights, and the list goes on.

Solutions? Lots. The time-honored tradition is to use a circuit with a CdS photoresistor, sometimes called a photocell or LDR, for "light-dependent resistor." (Circuit Example 1, Example 2.) Photoresistors are reliable and cost about $1 each, but are going away because they contain cadmium, a toxic heavy metal whose use is increasingly regulated. There are many other solutions as well. Look here for some op-amp based photodetector circuits with LED output, and check out some of the tricks used in well-designed solar garden lights, which include gems like using the solar cell itself as the sensor.

In this article we show how to build a very simple-- perhaps even the simplest-- darkness-activated LED circuit. To our LED and battery we add just three components, which cost less than thirty cents altogether (and much less if you buy in bulk). You can build it in less than five minutes or less (much less with practice).

What can you do with such an inexpensive light-controlled LED circuit? Almost anything really. But, one fun application is to make LED throwies that turn themselves off in the daytime to save power. Throwies normally can last up to two weeks. Adding a light-level switch like this can significantly extend their lifetime.



Components

Here are our components: On top: a CR2032 lithium coin cell (3 V). On the bottom (L-R): the LED, an LTR-4206E phototransistor, a 2N3904 transistor, and a 1 k resistor. This LED is red, blindingly bright at 60 candela, in a 10 mm package. It casts a visible beam, visible for about twenty feet in a well-lit room. We got the LEDs and batteries on eBay, and the other parts are from Digi-Key, but Mouser has them as well. As we mentioned, the last three cost about $0.30 all together, and much less in bulk.

The LTR-4206E is a phototransistor in a 3mm black package. The black package blocks visible light, so it is only sensitive to infrared light-- it sees sunlight and incandescent lights, but not fluorescent or (most) discharge lamps-- it really will come on at night.

Our starting point is the simplest LED circuit: that of the LED throwie, which has an LED driven directly from a 3V lithium coin cell. (Funny looking example here.) From this, we add on the phototransistor, which senses the presence of light, and we use its output to control the transistor, which turns the LED on.


Diagram

The circuit diagram looks like this; please ignore the messy handwriting. ;)

When light falls on the phototransistor, it begins to conduct up to about 1.5 mA, which pulls down the voltage at the lower side of the resistor by 1.5 V, turning off the transistor, which turns off the LED. When it's dark, the transistor is able to conduct about 15 mA through the LED. So, the circuit uses only about 1/10 as much current while the LED is off. One thing to note about this circuit: We're using a red LED. That's because the voltage drop across the transistor allows less than the full 3 V across the LED. The full three volts is really only marginal for driving blue LEDs anyway, so two-point-something really doesn't cut it. (Might be able to work around that with a cheap FET-- haven't tried yet.)

And now, let's build it. You can certainly put this together on a breadboard, but there's something more satisfying about the compact and deployable build that we walk through here.


Transistor, resistor 1 k resistor

First get the transistor and the resistor. The pins of the 2N3904 are called (left-to-right) Emitter, Base, Collector, when viewing it from the front such that you can read the writing. We're going to solder the resistor between the leads of the Base and Collector of the transistor. Unusual part: hold the resistor with its leads at 90 degrees to those of the transistor while you solder.

Stay safe when you do this: Use Mr. Hands.

After soldering, clip off the excess resistor lead that is attached to the transistor base (middle pin), as well as the excess length of the collector pin.


Phototransistor Phototransistor added

Next, we add the phototransistor. Note that it has a flatted side, much like an LED does. This pin on that side is the collector of the phototransistor. Solder the collector (flatted side) to the middle pin (the base) of the transistor, again at 90 degrees. The other pin of the phototransistor, the emitter, is left unconnected for the moment. (Here is an alternate view of what that should look like when you're done.)

Finally, we need to add the LED. To do so, we need to know which side is the "positive," or anode side of the device. Regrettably markings of LEDs are not consistent, so the best way to be sure is to test it with the lithium coin cell-- put the LED across the terminals of the cell and, when it lights up, note which side is touching the (+) terminal. (Usually, it's the one with the longer lead.) Solder the "positive" lead of the LED to the emitter pin of the transistor-- it's the one on the left, which doesn't have anything soldered to it. Trim away the excess lead of the LED that goes past the solder joint. Solder the other pin of the LED (the "negative" pin, or cathode) to the emitter of the phototransistor, the pin on the non-flatted side, which does not have anything connected to it yet.


With LED, trimmed

By this point, there are only two pins sticking down below the components: One that goes to the resistor and collector (rightmost pin) of the transistor, and one that goes to the emitter of the phototransistor and to the cathode of the LED.


Complete

To test the circuit, squeeze the coin cell between these two terminals, positive side goes to the lead touching the resistor. You can't see the LED on here because these photos were taken with incandescent lighting-- it wouldn't turn on.


Lights on lights off?

Bending the leads to contact the lithium cell a little more reliably, you can try it out a little more easily. In the photo on the right, I cupped my hand over the circuit-- so the LED turned on.


throwie! Ceiling

To make this into an actual "throwie," you still need to add some tape and a magnet, but that's quite easily done. This one makes a pretty good nightlight attached to the top of a doorframe-- when the room lights are off, it shines a bright, bright spot on the ceiling.

Where to go from here? While this little circuit can do something on its own, it would probably also be happy as part of a larger circuit. At a minimum, note that if you work with batteries that have lower internal resistance than the lithium coin cells, you should place an appropriate resistor in series with the battery before trying to operate this circuit-- or else you may put too much current through the LED. Certainly, this is one of the easiest and least expensive ways to control an LED with a photosensor. (Unlike, say, this method?) You could also consider crossing it with some more extreme mods, like the Talkie Throwies that know Morse code, or for more extreme hackers, bagel throwies.





MetaBlog links for this story: [ del.icio.us | technorati ]

Technorati tags: , , , , , , , , , ,

Trackback

Trackback URL for this entry: http://www.evilmadscientist.com/trackback.php/nightlight

Here's what others have to say about 'A Simple and Cheap Dark-Detecting LED Circuit':
The web's most interesting stories on Thu 13th Dec 2007 from purrl.net |** URLs that purr **|
These are the web's most talked about URLs on Thu 13th Dec 2007. The current winner is [read more]
Tracked on Thursday, December 13 2007 @ 03:07 AM PDT
Electronics-Lab.com Blog >> Blog Archive >> A Simple Dark-Detecting LED Circuit
Tracked on Thursday, December 13 2007 @ 05:38 AM PDT
BOHNE >> Blog Archive >> EletrĂ´nica simplista
Tracked on Thursday, December 13 2007 @ 07:38 AM PDT
links for 2007-12-14
Tracked on Friday, December 14 2007 @ 07:22 PM PDT
things to look at (December 9th - December 14th) | stimulant - changing things around. . .
Tracked on Friday, December 14 2007 @ 08:37 PM PDT
Hacked Gadgets - DIY Tech Blog >> Blog Archive >> Darkness Sensing LED Circuit
Tracked on Saturday, December 15 2007 @ 07:43 AM PDT
Kabel ab? - Braking News - Bremsen oder Gas geben?
Tracked on Friday, April 18 2008 @ 12:48 PM PDT
euxneks >> Blog Archive >> How I proposed, or LEDs are a girls best friend
Tracked on Tuesday, April 29 2008 @ 11:21 PM PDT
A Simple and Cheap Dark-Detecting LED Circuit | 29 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
A Simple and Cheap Dark-Detecting LED Circuit
From: westfw on Thursday, December 13 2007 @ 04:20 AM PDT
Your NPN transistor is in a somewhat odd place; they're usually "low side" drivers. Is the position it's in required by the characteristics of the photodiode and circuit?
Is sensitivity adjustable at all? It has seemed to me that a problem with most dark-activated circuits is that they turn on when the room/outside is far from dark, and I end up wasting batteries trying to light up an area that is already quite adequately lit by 'dusk.' It's almost worth throwing a microcontroller at.
A Simple and Cheap Dark-Detecting LED Circuit
From: Anonymous on Thursday, December 13 2007 @ 07:17 PM PDT
I'm somewhat new to electronics and interested in lighting and LEDs. Question: is there a simple (read: inexpensive, small) that could be added to this project? In other words, for example I want the light to go on for X hours then turn off until the next transition from light to dark. That way the battery doesn't expire as quickly but it can be used for applications such as Xmas lights, halloween, etc. where it doesn't need to be on all day (assuming an array of LEDs).
A Simple and Cheap Dark-Detecting LED Circuit
From: Anonymous on Thursday, December 13 2007 @ 11:42 PM PDT
next step: most folks arent aware that basic led's are themselves photo detectors (in addition to being photo emitters)...hook one up to a sensitive DMM meter to prove it for yourself.

The challenge: if we substitute an led as the detector (let's say because our junkbox has leds, resistors, and transistors lying around...but dont have any photo transistors)...can we redisign a simple circuit that operates in a similar manner using two LEDs...one for input, the other for output?
Bagel Throwies FTW!
From: Anonymous on Friday, December 14 2007 @ 06:17 AM PDT
I wondered why I was getting more traffic on Flickr - thanks, EMSL!

Steve/Irregular Shed
A Simple and Cheap Dark-Detecting LED Circuit
From: joebar32 on Friday, December 14 2007 @ 12:03 PM PDT
Could you combine this with the joule thief? Would you just insert this circuit into the joule thief circuit as if it was an on/off switch? Or would the way this circuit plays with current not make it a switch per se? I'm a mechanical with a limited electronics knowledge that doesn't extend too far past the following a recipe stage. I could guess that the low current 'off' state of this circuit might get boosted by the joule thief and end up with an always on circuit maybe.

I'm thinking it'd be nice to use up old batteries in night light or xmas decoration duty. I've got a couple outdoor wreaths that would look good with a few led 'berries' on them at night.
A Simple and Cheap Dark-Detecting LED Circuit
From: Anonymous on Tuesday, January 08 2008 @ 12:13 PM PDT
The problem I see with this circuit is that when the photocell is turned on, the full 3.6V is across the 1k resistor, which draws 3.6/1000 of an amp or 3.6 milliamps. This is not as much as the LED, but it's a substantial part of what the LED draws, so the battery will last somewhat longer, but will still go dead soon in a few days.

But by making a few changes, the battery life can be extended a lot more, to months. One way is to replace the 2N3904 with a 2N7000 enhancement mode MOSFET. This is a few cents more than the 2N3904 if you buy them from FairchildDirect.com or Mouser. Instead of a 1k, replace the resistor with a 1 meg resistor. The current drain will then be a thousand times lower when it's off. The 2N7000 requires more voltage at the gate, so to solve this, the LED must be moved from the emitter and put in the 'collector' which is called the drain in the 2N7000 (the pinout is the same as the 2N3904). Since the gate of the 2N7000 draws almost no current, you can use something other than a phototransistor. A LED might work instead. But since it can generate a voltage when it's illuminated, the LED may have to be put in backwards to _reduce_ the voltage at the gate.

Another way is to add another transistor to reduce the base bias needed. I'll have to write up a blog on this later (it's at watsonseblog.blogspot.com). But if you've experimented with the 2N3904 or other transistors, you will just *LOVE* the 2N7000! The gate is so sensitive that you can turn it on with just a touch. And since it is almost infinite input impedance, the gate can be used to detect all sorts of things like E fields. But for timers it's incredible because you can turn it on for minutes or more with a several megohm resistor and a 100uF capacitor. It's like a super transistor.
Later...
A Simple and Cheap Dark-Detecting LED Circuit
From: Anonymous on Friday, January 25 2008 @ 04:08 PM PDT
Anyone willing to post some specifics about parts to order, say from mouser or fairchild? When I search those part numbers, I get no fewer than 10 + choices each.

Thanks in advance.

Super Noob
A Simple and Cheap Dark-Detecting LED Circuit
From: Anonymous on Monday, February 04 2008 @ 07:49 AM PDT
Which change will it be in the circuit if we want more leds to light? Because i can't find the phototranzistor can i put a photodiode?and if yes which one?
A Simple and Cheap Dark-Detecting LED Circuit
From: Tarles on Monday, February 04 2008 @ 05:16 PM PDT
As I was trying to get the components to build this I wasnt able to find LTR-4206E and instead I bought BSP 103-2 which works but only when it is near a bright light.

Any ideas anyone? I would like to have it really sensitive, so if anyone can help me I woould appriciate it.

Thanks in advance.
A Simple and Cheap Dark-Detecting LED Circuit
From: Tarles on Wednesday, February 06 2008 @ 03:23 PM PDT
Nice,

still no reply?!

I wasnt able to find that Phototransistor LTR-4206E here and this one which I have needs to real close to light if I want LED to be off.

Can I make phototransistor to be less/more sensitive?

please help me guys

Thanks