Help me simplify this circuit - Page 1
Forum section: electronics / beginners

author: CountChocula
author_rank: Unknown
timestamp: December 18, 2022, 01:38:36 am
content: Hello! I have recently installed a set of lights inside one of my closets that uses a magnetic switch to turn on and off when the door is opened or closed. Unfortunately, the door doesn't always close properly, and I worry that the lights will stay on and prematurely deplete the 4 AA batteries that power the circuit.Of course, Icouldfix the door, but that seems way too easy, and so instead I thought I would reach into my junk bin and make a little circuit that automatically turns off the lights after a set period of time even if the door remains open. For obvious reasons, I wanted a solution that would draw no power when the door is closed, and as little as possible additional power when the door is open, especially when the timeout turns off the lights.I came up with the circuit below; when the door is locked and SW1 is open, R3 pulls up the gate of Q2, and no power flows through the circuit. When the door is ajar and SW1 is closed, current flows through R1, turning on Q1, which, in turn, grounds the gate of Q2, turning it on and allowing current to flow. In the meantime, current also begins to charge C1 through R4; when the voltage if the RC network is high enough to switch on Q3, the circuit goes into timeout mode, the gate of Q1 is grounded, and Q2 turns off again, taking the lights with it. While SW1 is closed, Q5 is also turned on, thus preventing R5 from pulling up the gate of Q4; as soon as SW1 opens again, Q5 turns off, allowing Q4 to turn on, discharging C1 through R6 and resetting the timeout period (that way, one can close and reopen the door to turn on the lights again if they so desire).The circuit works pretty well: when the door is closed, it draws essentially no power; when the lights are on, it uses around 1mA of additional current, and, in timeout mode, the whole system only uses about 500µA total.This is good for my needs, but, as a learning opportunity, I wonder whether I could have come up with something simpler. I am particularly annoyed at the fact that I needed two additional transistors just to discharge the timeout capacitor… surely there must be a smarter way? I would love if someone with more knowledge could suggest some ideas (and if you spot any mistakes, please let me know!).The load, incidentally, is about 200mA's worth of LEDs (I bought two cheapo camping lights that, in what I can only assume was an ill-fated attempt to create a death ray, were designed to draw 500mA from 3 poor AAA batteries, and McGivered a simple current limiter into them so that they only draw 100mA each; I figure that we probably only use the closet for a couple minutes a day, so the batteries should last… long enough).Thanks!—CC

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: December 18, 2022, 07:50:45 am
content: Thinking outside the square a little bit, how about a PIR sensor instead of the door switch?https://components101.com/sensors/hc-sr505-pir-sensor-pinout-datasheet

author: CountChocula
author_rank: Unknown
timestamp: December 18, 2022, 06:32:24 pm
content: Intriguing idea, and very lower power! I don't think it would work in my case, however—the closet is full of clothes and I suspect that it would be hard to find the right place to position the sensor so that it could easily detect humans… though, worth a thought! You'd still need some kind of timeout circuit so that the light wouldn't go on and off continuously…Thanks!

author: BeBuLamar
author_rank: Super Contributor
timestamp: December 18, 2022, 08:44:45 pm
content: I would change the magnetic switch to something much more reliable. I really dislike using an addtional circuit because the original circuit simply no reliable enough.

author: themadhippy
author_rank: Super Contributor
timestamp: December 18, 2022, 08:54:08 pm
content: surley the only answer worth considering is a £27.63 microprocessor and £362 worth of programming software.Or maybe just a lowly 555

author: CountChocula
author_rank: Unknown
timestamp: December 18, 2022, 09:23:46 pm
content: Quote from: themadhippy on December 18, 2022, 08:54:08 pmWell, I have already discarded the possibility of hiring someone to turn the lights on and off for us, so the micro seems overkill…Now that we've both had our daily dose of sarcasm——I considered the 555 (though I don't have one on hand, which is why I didn't use it), but it wouldn't reduce the complexity of the circuit, just hide it away in a chip and shorten the BOM. Thanks for the suggestion, though!

author: Zero999
author_rank: Super Contributor
timestamp: December 18, 2022, 09:29:37 pm
content: Quote from: CountChocula on December 18, 2022, 09:23:46 pmDoes it matter how complex the chip is? A 555 might be a more complicated piece of silicon, but it's a much simpler circuit to make. The only issue with the 555 is it has a relatively high power consumption and will drain the battery. Heck, I'd just use a small microcontroller.

author: CountChocula
author_rank: Unknown
timestamp: December 18, 2022, 09:43:18 pm
content: Quote from: Zero999 on December 18, 2022, 09:29:37 pmWell, it matters insofar as I was trying to figure out whether there were any parts of the circuit that were redundant, and not whether I could just use a more integrated solution—perhaps I should have been clearer. Thanks!

author: ledtester
author_rank: Super Contributor
timestamp: December 19, 2022, 01:48:50 am
content: Here's a version of the schematic which might make clearer how things work:Note that Q5+R5 in the original schematic is represented as a digital NOT gate.Also, I changed R4/C1 to 10M/22u. It has the same time constant but it might be easier and cheaper to find low-leakage caps with the smaller value. Maybe not a big concern for a one-off project but something to keep in mind.Update: R6 added.

author: BillyO
author_rank: Super Contributor
timestamp: December 19, 2022, 01:59:34 am
content: I guess you could eliminate Q5 and make Q4 PMOS. I'd also limit the current through it though. Maybe 470R.

author: ledtester
author_rank: Super Contributor
timestamp: December 19, 2022, 02:09:11 am
content: Quote from: BillyO on December 19, 2022, 01:59:34 amThis prompted me to look over the circuit again and I noticed that I missed R6. Schematic updated!

author: coromonadalix
author_rank: Super Contributor
timestamp: December 19, 2022, 02:36:16 am
content: Way to get things over complicated lollRepare the damn door loll and you have mechanical door snap locks, IE: if your door is not properly pushed, nothing works ??or the famous motion sensor leds light publicity on tv who have physical presence detectors ??You have some modules for 12vdc or 120 vac with 3 wiresand they dont cost a fortuneor tons of motion detector lights on amazon between 10 to 35$ CAD battery operated

author: CountChocula
author_rank: Unknown
timestamp: December 19, 2022, 03:29:41 am
content: Quote from: ledtester on December 19, 2022, 01:48:50 amThank you! What ECAD software did you use?

author: CountChocula
author_rank: Unknown
timestamp: December 19, 2022, 03:34:20 am
content: Quote from: BillyO on December 19, 2022, 01:59:34 amYes, that makes sense—but it wouldn't completely discharge C1, though, right? As the charge is drained, the voltage at the source of Q4 will eventually fall below the Vgs threshold of the transistor and cause it to stop conducting. Or do I misunderstand how p-channel MOSFETs work? Thanks!

author: Peabody
author_rank: Super Contributor
timestamp: December 19, 2022, 05:29:48 am
content: How about this?

author: ledtester
author_rank: Super Contributor
timestamp: December 19, 2022, 06:01:01 am
content: Quote from: Peabody on December 19, 2022, 05:29:48 amThe cap will charge up through R2 so perhaps R2 should be the 1Meg.In any case the other problem is that when SW1 opens the cap will discharge through the series combination of the 1Meg+R2 -- hence it will discharge even more slowly than it charges up.But here's a variation: use two magnetic switches. When the door is closed not only is SW1 opened but also a second switch is closed which discharges the cap.

author: Circlotron
author_rank: Super Contributor
timestamp: December 19, 2022, 06:15:31 am
content: What about a microswitch located close to the hinge side of the door and set so that it switches on only when the door is more than half open.

author: Peabody
author_rank: Super Contributor
timestamp: December 19, 2022, 03:17:43 pm
content: Quote from: ledtester on December 19, 2022, 06:01:01 amThe choice of R2 is a time constant question - how long do you want the mosfet to stay on. But if the switch is stuck closed, you'll be wasting current through the 1Meg, which is why I picked a high value (in his original circuit, I think that was 100K, or I guess 110K since the pulldown was in the wrong place). But of course the 1Meg could be anything as long as you're happy with the resulting current sink.

author: CountChocula
author_rank: Unknown
timestamp: December 19, 2022, 03:36:45 pm
content: Quote from: ledtester on December 19, 2022, 06:01:01 amThank you! Incidentally, the magnetic switch that I used is SPDT, so at the very least I could save one transistor by using the NC side of the switch to turn Q4 on and discharge the cap. That's 20% of the circuit gone

author: ledtester
author_rank: Super Contributor
timestamp: December 19, 2022, 04:41:14 pm
content: Quote from: CountChocula on December 19, 2022, 03:36:45 pmIn that case, what about this variation of Peabody's idea:Arrange it so when the door is pulled closed the magnetic switch is activated and shorts the cap.

author: Zero999
author_rank: Super Contributor
timestamp: December 19, 2022, 04:52:06 pm
content: Add a diode and another resistor so it discharges the capacitor.

author: BillyO
author_rank: Super Contributor
timestamp: December 19, 2022, 04:59:22 pm
content: Quote from: CountChocula on December 19, 2022, 03:34:20 amThat should only be a problem if you are going back to the closet right away and even then it will be mostly discharged in a second or two. If you look at ledtester's schematic, the cap will continue to discharge through R4, R1 and R2.I think you could really simplify the circuit using a PNP transistor and a n-channel MOSFET. I have to prepare for a concert today, but I could have a look at that tomorrow.EDIT: On second thought, ledtester's latest circuit looks like a winner!

author: Terry Bites
author_rank: Super Contributor
timestamp: December 19, 2022, 06:08:43 pm
content: Draw out a timing diagram. That will make it easier to understand and get simpler solutions.

author: Zero999
author_rank: Super Contributor
timestamp: December 19, 2022, 06:58:39 pm
content: Quote from: ledtester on December 19, 2022, 04:41:14 pmI'd strongly advise adding a series resistor to the capacitor, otherwise it can damage the switch, especially if it's a large capacitor and small reed switch.

author: Peabody
author_rank: Super Contributor
timestamp: December 19, 2022, 10:32:12 pm
content: Quote from: Zero999 on December 19, 2022, 06:58:39 pmYeah, I think we're about at the definitive school-approved solution. And with the SPDT switch, there can really be zero current if the door is left open.But I didn't understand your circuit in reply #20 at all.

author: CountChocula
author_rank: Unknown
timestamp: December 20, 2022, 04:00:42 am
content: Brilliant—thank you all so much for your suggestions! The final answer is really nice and so simple (and very humbling—glad I asked this question).Just for fun, I added a little bit back in to give the circuit a soft start so that the light turns on gradually. Cheers!

author: Zero999
author_rank: Super Contributor
timestamp: December 20, 2022, 08:38:46 am
content: Quote from: Peabody on December 19, 2022, 10:32:12 pmAs the the capacitor is charged, the voltage across the gate-source resistor falls, so the MOSFET turns off, after the delay has elapsed.When the power is disconnected. The capacitor discharges via the diode and the 1M resistor across the power supply rails.

author: Peabody
author_rank: Super Contributor
timestamp: December 20, 2022, 06:09:57 pm
content: Ok. I was trying to figure out what turned on the mosfet in the first place, but its the discharged capacitor. P-channel. Instead of lowering the gate, you're raising the source, but it's the same result.