TEMPO - the Handy Timer Switch - Attiny85 & DS3231 RTC Based ** V. 1.7 More Features **
by Acmecorporation in Circuits > Arduino
14215 Views, 31 Favorites, 0 Comments
TEMPO - the Handy Timer Switch - Attiny85 & DS3231 RTC Based ** V. 1.7 More Features **
Very often we use timer switches to turn on/off our equipments. The one commonly used is the classic mechanical 24-hour timer .
Common issues of the cheapest ones are:
- mechanical fault
- EMF when switching on/off
- times get off track
- after a blackout it needs to be programmed
So i thought to build a digital timer, Attiny85 and DS3231 RTC based, for my low power DC devices. It doesn't need of a dedicated power supply, because drain current from device PS that you are powering with a few small adjustment. Once you add shutdown time and sleep duration into the sketch, Tempo will make its "dirty" work until the DS3231 button battery die.
I'm using it to drive modem and lan switches to create a "night mode" around my house.
** VERSION ** TEMPO V. 1.2
Now support automatic adjustment from summer to winter time and vice versa.
** NEW VERSION ** TEMPO V. 1.7
The new version introduces substantial changes.
Rather than to consider the shutdown time, now has been considered turn-on time. This allows to introduce SLEEP instruction that reduce TEMPO power consumption when no need. This can be done via interrupt Attiny85 PIN and DS3231 built-in alarm function (two alarm programs available). As a result i had to modify the sketch to prevent error in case of power failure. I'm using the latest version with Attiny85 running at 1Mhz.
How It Works
Attiny85 is in charge to get current time from RTC and send an on/off control signal .
The concept is simple, since we are talking to switch low power devices, i thought to replace a classic relay with a high current driving mosfet as IRF640. This part allow a maximum drain-source voltage of 200Volts but, usually, we'll needs no more than 12Volts. Another main feature is that maximum current from Drain is 18Ampere but, usually, we'll only need at most 2-3Ampere.
As said in the foreword, Tempo doesn't need of a power supply. There is a little voltage regulator circuit that allow input voltages from 7.5 to 35Volts so you can use power supply of the device to be controlled . A small current is drained by Tempo circuit, the remaining is for the device that you are feeding.
The modem that i used to test Tempo has a 12V 1A power supply. When testing i discovered
that 1Ampere was not enough to drive it and Tempo at the same time. Digging in my recycle box i've found a 12V 3A power supply that is more than enough for the use.
Parts Needed
Here electronic component list and approx price:
Attiny85 ..............................................euro 1.29
Mosfet N-channel IRF640...................euro 1.00
LM7805 voltage regulator....................euro 0.50
DS3231 RTC......................................euro 1.00
Socket 8P DIP.....................................euro 0.10
Capacitors/resistors...........................euro 0.40 (*)
Power(slide) switch............................euro 0.20
Coaxial DC power plug.......................euro 0.50
PCB....................................................euro 0.10
PCB mount DC power entry socket...euro 1.00
Screw terminals connector 2 pin........euro 0.20
Total.....................................................euro 6.29
(*) Resistors: 100Ohm, 1KOhm - Electrolitic capacitors: 10uF, 100uF
** NEW VERSION 1.5 **
1 x resistor 1KOhm
1 x resistor 10KOhm
Attiny85 Connections
Connect component to Attiny85 as follow:
Mosfet gate to Attiny85 PB4
LM7805 output to Attiny85 VCC
LM7805 GND to Attiny85 GND
DS3231 SCL to Attiny85 PB2
DS3231 SDA to Attiny85 PB0
Tempo sketch prevides for an Attiny85 serial output on PB1 pin (optional).
Complete PCB and breadboard schematic on Autodesk Circuit
A switch between 12V power supply positive cable and LM7805 input add a practical shutdown function.
** NEW VERSION 1.7 **
Connect DS3231 SQW PIN to Attiny85 PB1 via 1Khom resistor.
Connect 10KOhm resistor between DS3231 SQW and +5V.
Serial output is not more available in the new version
Updated PCB and breadboard schematic on Autodesk Circuit
The Sketch
The sketch is very minimal, it allow to shutdown device from 1 to N hours. Shutdown and duration time must be added into the sketch.
In my specific case, i need that modem is powered off from 3 am to 6 am, then my settings are:
sstime=shutdown start time (h24 format)
sleeptime=sleep time (number of hours format)
sstime=3
sleeptime=2 //(because minimum default sleep time is 1 hour)
Nothing stop to set more shutdown ranges, if needed.
Library adopted are:
Tutorial made assuming that DS3231 current time is already set and you already know Attiny85 programming using Arduino IDE.
Summertime/wintertime
set variable
boolean WTime=false; // in case you are setting during summer time change to FALSE
if, at the time of settings, you are during summer time. Settings during winter time requires a TRUE value.
Wintertime switch will be at 3.00 the last sunday of october, summertime at same hour of the last sunday of march.
** NEW VERSION 1.7 **
this last version introduces start hour and end hour. Wakeuptime is
deprecated.
So now we have:
int shtime; // turn-on start hour (0-24 format)
int smtime; // turn-on start minute (0-59 format)
int sttime; // turn-off hour (1-23 format)
for example:
- int shtime=6;
- int sttime=3;
- int smtime=0;
means that the device powered will be turned on from 6:00am to 2:59am. From 3:00am to 5:59am Attiny85 will goes in sleep mode.
In case of power failure during turn-on time or across it, at reboot TEMPO will not forget turn-on time duration.
new libraries to add (included into IDE):
avr/sleep.h
avr/interrupt.h
A Word About Mosfet
This project has been made thinking to power off a device at a predefined time.
For this purpose should be better use a P-Channel mosfet instead of the one (IRF640 N-Channel mosfet) that i used, because to let current flow between Drain and Source, its gate must be always powered. A P-channel mosfet reverse the operation because current flows between Drain and Source continuously, until that the Gate receive the voltage logic level that stop the flow (as a NC relay). A N-Channel mosfet is a more appropriate for powering up a device at a specific time (as a NO relay) .
A circuit with a P-Channel mosfet is a little bit different from this one. I undertake to publish a specific project next time.
Why Do This
I felt the need of this project for various reason. As said i've applied the circuit to my modem and lan switches because:
1) saving energy when i don't need internet connections
2) randomly, my internet connection goes down or goes wonky after several days of modem powering on
Nothing stop to use this project for any 12V low power device as, for example, Christmas tree lighting.
Thanks for reading.