Connect with us

dark sensor circuit

Discussion in 'Sensors and Actuators' started by jptrsn, Jul 1, 2010.

Scroll to continue with content
  1. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    Hi everyone,

    A project I'm working on needs to have a circuit that will, when powered up, take input from a light sensor, and switch a relay once the light has dropped below a certain threshold. I've come up with a schematic diagram of what I think will work, and preliminary work on a breadboard suggests that it is functional, but I wanted to get some opinions on potential problem spots.

    There are some superfluous details in the schematic, such as the jumper connections to a couple of switches, but the real meat of the circuit consists of a photodiode (PD1), resistors, a CD4066, and a DPDT relay. It's for an automotive application (necessitating the relay and the 7805).

    Please let me know of any ways that this circuit could be made more robust. However, it is an absolute requirement that the relay is in the same state in daylight as when there is no power to the circuit.

    Thanks for any and all help!
    jptrsn

    [EDIT] I forgot to mention that I've assembled this from salvaged parts, which is why I have such a strange assortment of pieces. That's another of the goals of the project - recycling discarded e-waste.

    [​IMG]
     
    Last edited: Jul 1, 2010
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,301
    2,738
    Jan 21, 2010
    The fuse should be on the other side of the voltage regulator (closest to the incoming power)

    I would be extremely surprised if a 4066 can switch a relay -- you need a transistor. You also need a diode to protect your circuit from the voltage spike when the relay is turned off.

    D1/Q1 look like a combination that will short your 5V power supply to earth.
     
  3. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    Hmmm. No problem to throw a transistor in to power the relay. Good point about th fuse, too. Does the protecting diode get reverse-biased across the relay's power terminals?

    I had intended R1 to pull up the 4066 input high when the photodiode PD1 is not conducting - Q1 is supposed to work as an NPN switch. How could I configure it to do this? My guess is R5, but I don't know what kind of current the 4066 input draws, so I'm not sure about the value of R5 - I'm guessing something about 10k?

    Thanks for all the help. I'm mostly self-taught, so understanding the bugs is as important to me as getting the circuit to work.

    [​IMG]
     
    Last edited: Jul 2, 2010
  4. Resqueline

    Resqueline

    2,848
    2
    Jul 31, 2009
    I'm not sure what functions you're after, but I can't see the 4066 doing anything useful at all in that circuit. You'll also want PD1/R5/Q1 to have an adjustable trip point.
     
  5. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    I was using the 4066 to get the hysteresis I was after; I tried it out with only the transistor, and it did not give me a good on/off output - the relay wouldn't come on fully, or switch off clearly with direct changes of light input. Would I be able to eliminate the 4066, and maybe use a darlington set up instead? I was hoping to get a good digital signal from the IC - something that doesn't seem to happen cleanly with just transistors.

    What range should I try using in R5?

    Come to think of it, I do have some inverting buffers kicking around in my parts drawer that I can probably use instead of the transistors and 4066. Is it worth trying to reconfigure this circuit, or should I scrap it?

    Alternatively, maybe I could use all the switches on the 4066 to get the current I need to drive the relay, and scrap Q2? Think it would work?
     
    Last edited: Jul 2, 2010
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,301
    2,738
    Jan 21, 2010
    A 4066 is an analog switch. It has no hysteresis. The 4066 has a typical ON resistance of around 170 ohms at the voltage you're using.

    Maybe you meant to use a 40106? It's a hex schmitt trigger.

    The diode across the relay coil should be reverse biased, yes. As the field collapses, the generated voltage will be dumped across the diode rather than stressing your components.

    You would be far better off using an LDR than a photodiode. A phototransistor would be another option. Photodiodes produce very little current. If you use a photodiode, it needs to be reverse biased (you show it forward biased) and the collector resistor (r1) needs to be far far higher (in the order of several hundred k). There is no need for the resistor in series with the photodiode, all you're doing at the moment is ensuring the transistor is permanently on. The other problem is that with the resistor as a collector load, you are effectively adding heaps of negative feedback which will reduce the voltage swing considerably. The resistor should be in series with the emitter, with the collector connected to +5V. You then sense the level at the emitter of the transistor. Of course this will invert the signal, so your logic may need to change.

    I think it is worth understanding how the components work and how each stage will work before you try to build up an entire circuit. Grabbing the datasheets on the components would be a good idea.

    Also, whilst your diagram is very neat, it's also very confusing with all the connectors shown (especially when they have the same numbers).
     
  7. Resqueline

    Resqueline

    2,848
    2
    Jul 31, 2009
    What steve says. One transistor can't amplify straight from a photodiode to a relay. You'll have to use a darlington connection (or inverters, followed by a transistor).
    Also, you have not connected your signal to the control input of the 4066. The way it is now current/voltage in is just passed straight through, with the addition of 170 Ohms.
    You'd need to parallell all inverters of 3 CMOS 4049 chips running on 12V to be able to drive an ordinary car relay.
     
  8. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    So now that I've learned all this, I'm going to redesign the circuit from scratch, and forget about the 4066 (since it can't do what I was hoping it was doing in the first place!) Perhaps the trouble I'm having is due to the analog nature of the 4066 (which I hadn't realized).

    Sorry for the confusion in the diagram; it's a necessary evil of the (free) software I use to diagram circuits and boards.

    I will try to get something working with a 74HC240, since it's something I've got available (no 40106s in my parts bin), maybe a LDR or photodiode, and a transistor or two. The relay I'm using is a 5V, DPDT relay (not an automotive relay) so it seems to be working fine when I directly connect it with 5V. The problem I have had with the LDR is that it does not have a high enough resistance to shut the transistor off, or low enough resistance to saturate it - it's somewhere in the middle.

    Why would I have to reverse-bias the photodiode to get it to work? I'm still a bit hazy on the whole concept of reverse-biased diodes - what they do, how they do it, and where to use them. I have found it a big challenge to find information online for someone who has read the introductory and beginner tutorials, but isn't yet savvy enough to get into the ee literature.

    I suppose that I may be setting the bar a little high for myself, trying to design a circuit from scratch to do something specific using only junked parts. I really appreciate all the help, and I'm sorry to keep coming back with more and more questions... If anyone has any recommendations for good, intermediate-level tutorials, I'd happily read as much as I can.

    Thanks so so much for the fast, clear, and friendly advice!
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,301
    2,738
    Jan 21, 2010
    74HC240 is a line driver. In general, they are capable of much higher output current than regular gates. Read the specs on them, and on your relay. It its quite likely that they will be able to drive it. You may have to parallel several outputs together. Again, as a general principle, you are better off paralleling ALL of the outputs rather than just what you need (unless you're using the others for some other purpose).

    How much current is required for your relay? Whilst reusing a 74HC240 may be viable, a single transistor is a far better solution (it's also smaller).

    What you *really* want to find in your box of parts is something with a schmitt trigger input. This will provide rapid switching and hysteresis. As long as you can get a fairly wide voltage swing with changes of light intensity near your trigger point (you haven't said whether the levels are at all critical) then it should be possible to fiddle the sensor to trigger the circuit at around about the light level you're interested in.

    Most CMOS Schmitt trigger inputs trigger at 1/3 Vcc and 2/3 Vcc. and is pretty predictable. This does not apply to TTL, LSTTL, and "A" series CMOS (the latter having TTL input levels).

    A forward biased photodiode will simply allow current to pass through it like a regular diode. In certain circumstances (i.e. with *very small* currents) the effect of light on the junction can be detected, however as you show it, the effect will be totally swamped.

    A reverse biased photodiode will block voltage. However, a voltage (or a very small current) will appear across the photodiode when exposed to light. In this case it is acting more like a very tiny solar panel.

    The easiest way of using a photodiode is to have it reverse biased in series with a resistor. As it is exposed to light, the small current causes a voltage to appear across the series resistor. This series resistor can also be the input impedance of an amplifier (so it doesn't physically exist as a component). In this case you can see it as injecting current.

    This should give you more information. The key point is that photodiodes are always used with high-impedance amplifiers.

    Using junked parts is not a problem. All design has constraints. You are just applying a different constraint (incidentally, designing from "stock components" is not awfully unusual -- it's just that your stock is probably small and eclectic :) The first step is to get the datasheets on everything you have (and put aside the rest). Then read all the datasheets and design notes (if you can find them) and get ideas how to use the components.
     
  10. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    Thanks for the great resource on photodiodes! I'm going to use one of the example circuits as a component in my overall circuit (the one displayed in figure 3b).

    I'm not sure what parts in my bin have a schmitt trigger (if any). The rapid switching isn't really necessary, but the hysteresis would be nice! I'll check the output of the photodiode circuit to see if it's got enough of a range to switch the relay on and off - I'm hoping it does. I do have some amplifier transistors in my parts box, and I'm almost certain I've got an operational amplifier in there somewhere, too.

    The really tricky part is that I've not been able to find any datasheets for my relay. I actually have two relays to choose from, both of which I have searched for extensively, but found nothing.

    Here's my next attempt at cobbling together a light-detecting circuit. I'm sure that to seasoned experts, it would be like Shakespeare reading a text message, but maybe it'll work...

    Thanks again for the helpful information. I always appreciate an explanation why, rather than simply being directed to "do it this way."

    [​IMG]
     
  11. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,301
    2,738
    Jan 21, 2010
    Unfortunately you do need rapid switching or bad things will happen.

    Give us a list of all the stuff you have and we'll google them for you and see if any have the word "Schmitt" in their name (seriously -- that's the first step).

    The main things you need to know are the voltage and current requirements for the coil. You should be able to measure the current and have a reasonable guess at the voltage.

    The second thing is the voltage/current capacity of the contacts. If you're switching a low voltage and low current device, it's probably not an issue, but if you want to switch mains it certainly is.

    You really need to test just that part and make sure it does what you want it to.
     
  12. jptrsn

    jptrsn

    7
    0
    Jun 16, 2010
    I breadboarded circuit 3A from the pdf you linked for me, and it seems to work well switching the relay without any unnecessary parts.

    I'm fairly sure that the relay is a 5 volt relay, because I pulled it off a board with a 7805 power supply. I'm not certain about the current requirements - would I check by putting my multimeter in series with the coil while it's energized?

    The relay I'm using has the company name "takamisawa" embossed on the top. The package is a DIP14 footprint, with 8 pins. On the side it's labeled RZ-12W 8914B5. I plan on driving LEDs with the relay's contacts, so I don't think the current will exceed 1A (I'm not going to be putting 500 LEDs on this circuit). From the construction of the relay, I'm guessing that it's a safe margin.

    I'm going to put together the schematic later on - that software is on a different computer that the one I'm currently on.

    Just for interest's sake, I'll give you the list of the ICs that I have in my box:
    74HC240N
    LH1540
    KPC814
    MC14066
    74HC4066
    CD4066
    LM324N
    74HC139
    and one odd one (looks like an oversized transistor) KA2404 934

    I don't know if any of those have a schmitt trigger in them - probably not. I've also got boards from a defunct answering machine that might have something on them, but probably not (they're in the garage right now, so I can't get the numbers off 'em).

    Thanks for all your help. I've learned a lot, and enjoyed it too!
    jptrsn
     
  13. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,301
    2,738
    Jan 21, 2010
    Yep, that's exactly right.

    I think it's probably a 12V relay see http://www.excesssolutions.com/cgi-bin/item/ES3707

    The relay I linked to is 1.25A at 24V. If it looks similar, then maybe...

    In any case, you should be looking at having several LEDs in series, with each string running at (say) 20mA, so the total current is number of strings * LED current, not Number of LEDs * LED current.

    You could make some schmitt triggers with the LM324 -- in fact that would allow you to create a high gain stage for the photodiode.

    None of them are specifically schmitt trigger devices.

    No problems :)

    Make sure you store those ICs correctly. Most of them are static sensitive.

    The easiest way is to get a block of polystyrene and wrap it several times with aluminium foil. Stick the ICs into this. It will short all the leads together, and that will keep them safe from accidental static discharge. Try not to touch the pins when you are handling them and wear an anti-static wrist strap if you have one.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-