Dusk light switch with timer - Page 1
Forum section: electronics / projects

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 07:07:11 am
content: I want some exterior lights to turn on at dusk but turn off after a set time and not stay on all night.Designing the light-sensing part is trivially simple but I would like to include a timer that is also very simple, nothing fancy. Maybe something which can turn the light off after 2 or 4 hours. No precision needed, just a rough approximation.I would think this is something which is a common need and would be readily available but I cannot find any circuits.Any circuit designs or ideas?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 18, 2023, 07:28:40 am
content: CMOS parts like HEF4541 and especially HEF4521 can do long timer operations, or you could chain some 4060 parts.Low voltage operation gives lowest power.

author: Zero999
author_rank: Super Contributor
timestamp: September 18, 2023, 07:42:00 am
content: A counter + oscillator is the only practical way to get such a long time delay.I would just use a microncontroller. An ADC or comparator input can be used to sense the voltage on the LDR and the timer can be implemented with an internal counter, connected to the clock. The whole thing can be run at 32768Hz using a watch crystal, to save power.

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 09:53:49 am
content: A microcontroller is out of the question. I am looking for something extremely simple which I can build using parts from my junk pile. It seems to me this is something for which there would be a demand and there would be simple circuits already out there.So I am thinking of a bistable (made with two gates) which would be set by a pulse at dusk. This would feed the light as well as a reset timer.I think I am going to start working on this idea if I cannot find anything already designed out there.

author: Ian.M
author_rank: Super Contributor
timestamp: September 18, 2023, 10:23:23 am
content: The problem is the Timer section of your block diagram. 10 Meg with 10uF gives a RC time constant of 100 seconds, two orders of magnitude less than the delay you want, and the component values are already fairly impractical - 10uF is about as large as you can go without ('wet' or polymer) electrolytic, or solid Tantalum capacitors, all of which tend to have significant temperature, age and usage history dependent leakage current. 10Meg gives a single digit uA level charging current for the capacitor. Add in the effects of input leakage of the timer chip (even if CMOS), board surface leakage etc. and you'll find that such long periods just cant be done reliably. Therefore your only hope is an oscillator and a digital divider chain.PCB.Wiz has already pointed you in the direction of 4060 (either CD4060 + equivalents or 74HC4060) which has an oscillator and a 14 stage binary divider chain. If you've got two of those (or one + a 4040) you are in with a chance to implement the timer. However you'll still have to add the SR flipflop, and come up with a circuit to change a slowly varying light level into a distinct 'dusk' event.However, *ALL* of that functionality can be handled in a cheap 8 pin MCU, at around the $1 price point, less than the cost of the extra protoboard area to build it out of junk pile parts.

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 10:34:54 am
content: Quote from: Ian.M on September 18, 2023, 10:23:23 amYes, the timer would be a divider and, in fact, I am already thinking I could use a 4020 which I had some decades ago in a watering timer.Quote from: Ian.M on September 18, 2023, 10:23:23 amI haven't the least notion of MCUs and it is not worth it for just this project. I am too old to learn new things now. If someone feels like doing it for me they can give me an estimate.

author: themadhippy
author_rank: Super Contributor
timestamp: September 18, 2023, 10:58:57 am
content: Quotesr latch is just 2 nand gates,and theres 4 of the buggers on the cd4093 which just happens to be a schmitt trigger jobby so the other 2 back to back wired as inverters should deal with those pesky slow changing light levels

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 12:31:01 pm
content: Quote from: themadhippy on September 18, 2023, 10:58:57 amI already have an LDR circuit with a couple transistors forming a Schmitt trigger. It is trivial. No problem.

author: Ian.M
author_rank: Super Contributor
timestamp: September 18, 2023, 12:42:51 pm
content: Fair enough. Learning Arduino, then how to program an ATtiny 8 pin MCU is rather OTT compared to simply soldering three or four chips on protoboard. MCUs aren't for everyone, but if you don't have that skill in the 21st century, you'll be limiting what types of project you can tackle and doing many of the rest the hard way. Also, ultra-low power consumption battery powered projects will be out of reach.PCB.Wiz and I specifically suggested the 4060 because its got an oscillator section built in. There are also a few tricks like using a diode from one of the 4060 outputs to its CLK in pin to inhibit its (RC) oscillator so the output latches high once it gets set, exiting that state by pulsing RESET, which could eliminate the need for a separate SR latch. However, add a dual OPAMP or comparator to the mix, and you could use one section as a RC relaxation oscillator and the other to provide an adjustable threshold for the dusk detector then use plain binary counters for the rest of the timer section.

author: Zero999
author_rank: Super Contributor
timestamp: September 18, 2023, 01:11:46 pm
content: If you want off the shelf parts, then both dawn/dusk switches and timer relays are widely available as pre-built modules. There's no need for even a soldering iron. They have screw terminals.If you want to build it from scratch, use the LM393, with one half configured as a comparator, for the dawn/dusk sensor and the other as an oscillator to drive the counter.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 18, 2023, 05:29:20 pm
content: There are also parts like 74hc5555 and CSS555 / CSS555C, oscillators with divider chains.

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 06:28:21 pm
content: I am somewhat surprised that this is not something quite common and available commercially.Searching I found this in the UK for £18.00https://www.ellumiere.co.uk/products/ellumiere-automatic-light-sensorWhich allows for 4 or 6 hour timer.At this point I think I will go with building a dusk darkness detector with an LDR and two or three discrete transistors, and repurpose a 4020 based timer I had for watering plants something like 45 years ago and which is so shoddily and dangerously built it's embarrassing. There's mains voltage mixed with low voltage everywhere. I had no sense of safety then. The sooner I dismantle it the better.

author: Zero999
author_rank: Super Contributor
timestamp: September 18, 2023, 06:43:05 pm
content: Quote from: soldar on September 18, 2023, 06:28:21 pmBecause it's so easy to make from pre-built modules.Example:Dawn to dusk lighting controller.https://uk.rs-online.com/web/p/lighting-controllers/4721486?gb=bTimer relay.https://uk.rs-online.com/web/p/timer-relays/8966822?gb=bConnect the above together and you have a light switch which will turn the light on for a pre-determined length of time, after dusk.Other, much cheaper suppliers than RS Components are available. I was just easy to find.

author: themadhippy
author_rank: Super Contributor
timestamp: September 18, 2023, 06:53:53 pm
content: QuotePlenty of the buggers to chose from in the uk,either as a stand-alone unit or the standard 3 pin tit model

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 07:31:53 pm
content: Quote from: Zero999 on September 18, 2023, 06:43:05 pmI do not consider those to be practical (or affordable) for a domestic setting. At all.OK, after some more searching I found this which is what I am after but it is sold in America and therefore for 120V.At under US$10 a piece and requiring no installation it is the kind of item directed at the domestic market.https://www.amazon.com/DEWENWILS-Sensor-Socket-Outdoor-Waterpoof/dp/B0BN32RR94/ref=sr_1_4_sspaI'll have to keep looking and see if I can find it for 230V.

author: John B
author_rank: Frequent Contributor
timestamp: September 18, 2023, 07:48:59 pm
content: In today's episode of "the microcontroller is lava".....

author: floobydust
author_rank: Super Contributor
timestamp: September 18, 2023, 07:49:26 pm
content: You can go sensorless, using a MCU. I know you do not want to do this. But... it is good for not having to mount anything outside, away from streetlights, bugs and rain etc. which was the hassle with an analog system I made decades ago.Using an ESP8266 with software that calculates Civil Twilight time, based on local NTP time and GPS coordinates which are hard-coded. So it uses WiFi only to get time/date and based on location calculates where the sun is, and the corresponding sunrise/sunset times.This is also called an "astronomical timer" and you can buy DIN-rail or plug in modules that trigger based on this.I had bought one off AliexpressGeya THC-15Bbut I could never get it to work properly. It just works as a timer, the on/off times never moved. Terribly translated instructions. But that is the keyword to search for.

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 08:38:52 pm
content: Quote from: floobydust on September 18, 2023, 07:49:26 pmSounds like a complicated Rube Goldberg machine which would yield worse performance than the more basic light sensor. But worth discussing!I used to do astro navigation long before GPS and I am quite familiar with astro calculations. For the purposes of exterior lights only low precision is needed and a very simple equation would suffice. We could say sunset is 6pm plus (minus) a sine function of the number of days into the cycle and that would be good enough. Maybe add some minutes to give it time to darken.But a light sensor takes into account the real light conditions while a pure timer does not and one day it can be bright and sunny at 5 pm and another day it can be overcast and very dark.For an exterior light I think a photocell makes more sense but for interior lights this type of timer would make a lot of sense. I have a few lights at home on timers and I have to keep reprogramming the timers along the time of year which is a PITA.A timer based on calculated sunset would be very simple to program. Input latitude or just select between low, middle and high latitude. And choose whether you want the lights on for a fixed period of time after they turn on or, more likely, whether you want to turn them off at a fixed time like midnight. As I say, the calculations are very simple.As for keeping time I would just set it manually and correct it once a year if necessary.If I could find this type of timer i would buy it because right now I have six different lights on timers around the house and they are a pin to keep resetting with the seasons.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 18, 2023, 08:38:55 pm
content: Quote from: soldar on September 18, 2023, 09:53:49 amMay I suggest you throw a few handfulls of microcontrollers onto your junkpileThose things are cheap, small and readily available.But if you want to go the old fashioned way. With a single RC based timer you can get upto a minute or so reliably, and maybe 10 minutes with a very low tolerance, but noise and leakage becomes a big problem. The most standard solution is extend an RC based timer with a bunch of flipflops, and the 4060 is exactly that. You can easily configure it from milli seconds to 10 hours or more, but do not use an electrolytic capacitor for the timing. These things leak and that makes the timing unreliable, and it may drift a lot over years.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 18, 2023, 08:41:41 pm
content: Quote from: soldar on September 18, 2023, 06:28:21 pmAliExpress has many twilight relays, but none at low prices with a timer included.Two components are usually needed anyway, so a separate sensor and time-relay ?Sensor:https://www.aliexpress.com/item/1005005829104800.htmland timer relays are commonhttps://www.aliexpress.com/item/1005004346965717.htmlthis one has useful unbox photos from someone in Poland - looks to have coin cell and 32Khz crystal.https://www.aliexpress.com/item/1005005193535757.htmlor these have 1 second precision option, slightly cleaner design ?https://www.aliexpress.com/item/4000423992078.html

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 08:41:58 pm
content: Quote from: themadhippy on September 18, 2023, 06:53:53 pmI am not sure what a "tit model" is but it sounds like something I might be interested in so links and pix would be welcome.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 18, 2023, 08:54:07 pm
content: Quote from: soldar on September 18, 2023, 08:38:52 pmThat is not so likely to work.Standard microcontroller crystals are not very accurate. You can expect an unadjusted deviation of a few minutes each day, and with a static calibration you can still expect 30 seconds of drift inaccuracy, and it' gets worse when the temperature changes. You can add clock IC's with more accurate crystals, and then you can get to a few minutes of drift per year, but those clocks are not the cheapest. As a result, if you want to use an astronomical clock, then synchronizing with NTP is probably the way to go. (And something like an ESP8266 already has WiFi).But I would probably keep it a lot simpler. A microcontroller, and a light sensor, And then the microcontroller just counts a few hours. As for the rest, you can add extra functions, for example keep a moving average of the time, and then only switch in a 20 minute window or so (allowing for drift). This way you can prevent switching in the middle of the day when the sensor is covered.Other things you can easily add is:Some alarm function if the sensor does not work in a few days (dirt, electronic failure, etc)Only switching when the light changes with a certain speed.Adjustable trigger levels in software (so no potentiometers needed).It's quite common for microcontrollers to have an on board ADC, and there are techniques to make a rudimentary ADC by various techniques. for example, if your sensor is an LDR, you can discharge a capacitor with a microcontroller pin, then switch the pin to an input, and measure how long it takes to charge the capacitor. With smart and fun software, the analog circuit can often be simplified.

author: soldar
author_rank: Super Contributor
timestamp: September 18, 2023, 08:58:26 pm
content: Quote from: Doctorandus_P on September 18, 2023, 08:38:55 pmI really wish I knew how to use them but I am just too old to invest any serious effort on learning. If it was something I was going to use a lot then it would make sense but not for a one time project.I found what I was looking for but in America and for 120V. You would think it would be easy to find the same in Europe for 230V but nooooooo...I don't understand it.When I lived in America I had another gadget that I liked and which I cannot find in Europe. it is a similar socket thing with a dusk switch. So far so good. But here's the clever thing:- with the circuit switch off the light is off (obviously)- turn the switch on and the light is controlled by the dusk switch in the socket. So far so good.But what if you want the light ON, not controlled by the dusk light switch? Very easy, you switch iton-off-onquickly and the light stays on permanently until you switch it off.I find this useful but cannot find it in Europe. Americans seem to be more practical for these things.

author: Zero999
author_rank: Super Contributor
timestamp: September 18, 2023, 09:04:32 pm
content: Quote from: soldar on September 18, 2023, 07:31:53 pmWhy not? It would certainly be cheaper than paying for someone to design it for you. The light switch comes in a suitably IP rated enclosure and that timer relay can be put inside a standard enclosure, with suitable glands. If it's still too expensive, it can all be bought from cheaper supplies than RS Components.Quote from: soldar on September 18, 2023, 10:34:54 am

author: themadhippy
author_rank: Super Contributor
timestamp: September 18, 2023, 09:40:10 pm
content: QuoteDont get to excitedthey use a standard plug and socket so mosttitsphotocells are interchangeable between different manufacturers.This the sorta thing your afterhttps://lowenergysupermarket.com/product/photocell-timer-light-switch/Quotesounds like a modern version of the old sangamo solar time clocks.

author: csaaa
author_rank: Newbie
timestamp: September 20, 2023, 03:12:49 am
content: 我绝对你们的讨论很有趣，但是我想如果是个人作品，你可以动手去制作，如果是商品就不必了。如果真的有这种需求，对于我们生产这个产品，每件产品的成本不会超过1美元。I'm sure your discussion is very interesting, but I think if it's a personal work, you can make it yourself. If it's a product, there's no need. If there is really such a demand, the cost per product for us to produce this product will not exceed $1.

author: soldar
author_rank: Super Contributor
timestamp: September 20, 2023, 08:17:34 am
content: I found this but it is only made for 120 V, for the North American market. I emailed the manufacturer in China and they responded very promptly that they do not make a 230 V version.DEWENWILS Dusk to Dawn Light Sensor Socket with Timerhttps://dewenwils.com/collections/light-sensor-socket/products/dewenwils-dusk-to-dawn-light-sensor-socket-with-timer-e26-bulb-light-sensor-socket-indoor-outdoor-for-porch-garage-garden-patio-waterpoof-lights-2-pack-black-etl-listed-shsls02fhttps://www.amazon.com/DEWENWILS-Sensor-Socket-Outdoor-Waterpoof/dp/B0BN32RR94/ref=sr_1_4_sspa

author: Zero999
author_rank: Super Contributor
timestamp: September 20, 2023, 10:32:18 am
content: These are cheaper.https://cpcireland.farnell.com/pro-elec/pell0052/10a-photocell-sensor/dp/LA08664https://cpcireland.farnell.com/finder/86-30-0-024-0000/timer-multifunction/dp/SW04017?ost=sw04017https://cpcireland.farnell.com/finder/90-03sma/socket-86-series/dp/SW04016?MER=sy-me-pd-mi-accehttps://cpcireland.farnell.com/hellermanntyton/ts35-0-5m-ts35-din-rail-0-5m/din-rail-top-hat-plain-0-5m/dp/EN83486?st=din%20rail

author: liaifat85
author_rank: Regular Contributor
timestamp: September 20, 2023, 10:34:39 am
content: Arduino and RTC looks like the simplest solution to me.

author: soldar
author_rank: Super Contributor
timestamp: September 20, 2023, 12:52:33 pm
content: I found on ebay .https://www.ebay.co.uk/itm/364266388644Dawn To Dusk Sensor UK 3 Pin Plug Winter/Summer Timer Switch Night Light Socket£10.59 each (+shipping)Not exactly what I am looking for but very close. Same basic idea. If I lived in the land of the electric plugs that can be used as boat anchors I would definitely buy it.Initially I was thinking of a design withdark switch -> timer (x hrs). the switch turns the light on at dusk and the timer turns it off x hrs later.But, here's the thing, I already have the lights on timers. The way I have it now I have to keep changing the programing of the turn on time because of the seasons. But I could just follow the timer with a darkness switch in series so that the light would be on from dusk until whatever the timer turns off which I generally set at midnight. I think I prefer this routine too.All I need for this now is either1- A dusk switch light socket,https://www.amazon.co.uk/Maclean-Automatic-Holder-Detection-Security/dp/B0196ELBOYor,2- A dusk switched lightbulb,https://www.amazon.co.uk/dp/B07F3513YN/or,3- a self-made photoswitch.