Create Project Need help?
Show more (1)
robvh

Timer for remote sockets

Status: Proposal
5315
21
votes
January 6, 2020 , Latest update: March 20, 2020
thumb-20200331144448.png
Timer for control of lights
For the control of the lighting around my home (and inside if I'm on hollyday) I used to rely on 4 mechanical timers. A replacement was needed.
The lights must be on from sunset until 23:00, something for which a mechanical timer alone is in fact not suitable. Settings of 4 timers must be changed regularly and if you forget it the lights are on too early or too late. And there were more problems: after a power failure of a few hours, my lights were on in the early morning and I had to set 4 separate timers on 4 separate positions. It has become time for a more comfortable solution.

Demands
  1. no do-it-yourself for mains circuits (as with the mechanical timers)
  2. no additional wiring from a central unit to swiches/relais (but there are 4 different lights)
  3. real-time clock must keep running in case of power failure
  4. simple and available platform for hard- and software, but a little bit d.i.y. is ok
  5. nice appearance (must be acceptable for my wife!)
The first 2 demands were realized by using readily available power-switches with wireless control (433 MHz). In my home-country these are sold under the brand "klikaanklikuit" (kaku). I bought a set of three switches and a hand transmitter for less than 20 euro (pictures timer01 and timer02).
The central unit will be based on Arduino (demand 4) using available libraries for rtc and wireless control.
To keep the unit simple no keyboard is build in; the unit is operated by an IR remote control of an obsolete video recorder (timer03). This make the realization of demand 5 a lot simpler.

Hardware
The circuit is build on a left-over PCB from another project, so no PCB design is available. The central unit is an Arduino Nano, but other types, like Arduino Uno, will also do the job. Pictures timer06 and timer07 show my setup.
For the transmitter a simple unit from Banggood is used (type number SKU075671). This is a set of receiver and transmitter. I used the receiver (timer08) to obtain the address of my hand transmitter, so I could use it together with the timer. Stricly this is not necessary, because the switches can be programmed to use more than one address.
The rtc is also From Banggood (type number SKUC98329). Normally this circuit uses a rechargeable lithium battery (LIR2032), but by removing the resistor in the charging circuit a standard CR2032 can be used, which should last a couple of years. And if you are modifying the pcb, also remove the resistor of the power indication LED. There is no use for this LED. See picture DS3231_hack.png
The display is a standard 2x16 character LCD-display.
A simple Hammond box is used as housing. The only holes needed are for the LCD and the power supply. A separate hole for the IR-receiver is not necessary; the plastic is transparent (enough) for IR. And be carefull if you use a knife (see the scratch on the title-picture ;-)

Software
The timer must switch on the lights if it becomes dark and switch them on at a fixed time (in the evening) or switch them on at a fixed time and off it becomes light (in the morning). Eventually one light stays on during the night.
To detect light and dark an LDR (light dependant resistor) can be used, but that would not be according to demand 2! Therefore the software must know about the time of sunrise and sunset. This is realised by an Arduino library.
The result is a simple box with has only one connection: the mini-USB power supply for the Arduino Nano. If you want to use (some or all) direct outputs of the Arduino to control your own circuit instead of the remote sockets, this is also possible: just define "HWout" and put the pins to be used in the array outarr[]. As an example I use channel A0 in the
program for this purpose.
The Fuzzilogic-433mhz library contains an example program for detection of the address of the hand transmitter: ShowReceivedCode.ino. As an alternative the zip-file contains a program which shows the address on the LCD: Light_code.ino.

Because in winter the dusk period is longer than in summer I tried to find some compensation for this. The lights inside are switched on earlier than the outside lighting. In summer there is no difference. In the program the factor myFact is included, which defines the duration of dusk during the winter. This will depend on your position on earth, which also has to be defined in the program to be able to calculate sunrise and sunset. Google maps can help you to find your coordinates. If you don't have problems connecting something external, an LDR might be the better solution.

In the Netherlands we still have summertime from the end of march until the end of october. By a simple routine, using a table for the date of start and end summertime (daylight saving) is determined. I know, there are libraries which can determine the time for any timezone on earth, but I like this simple approach. If you don't live in western Europe, you have to fill the tables Dayarr1[] and Dayarr2[] for your own situation. The tables covers 2020 to 2025. Because the situation may change after 2023, a longer table would be useless for me.

Items to be filled in the program for your own situation:
  • KakuAddr: address of kaku units (not in EEPROM yet)
  • MaxChan:  number of devices (one RF channel can eventually control more sockets)
  • HWout:    do you want some channels to be digital outputs of Arduino?
  • myNB:     Latitude
  • myEL:     Longitude
  • myGMT:    Hrs to GMT
  • myFact:   Dusk duration in winter 25 minutes (tried for my location, depends on myNB
  • Dayarr1:  startdate of summertime in Europe (march from 2020..2025)
  • Dayarr2:  enddate of summertime in Europe (october from 2020..2025)
  • outarr:   if HWout is set, you have to define the hardware outputs
Read the full post
Show less
Other

Loading comments...