My home is in a nice neighborhood. The front yards are well
kept, it is quiet, and people wave when you go down the street. The
park nearby is kept clean and green and children there play nicely with
each other. Behind this idillic appearance the neighborhood harbors a
dark side. Door-to-door solicitors, who ring the doorbell several times
a week selling everything from insurance to religion. This isn't a real
big problem for me, but because of my wife's schedule, she frequently
sleeps until late in the morning. After being startled awake by a
doorbell, she can't go back to sleep and suffers because of it the rest
of the day. Our first solution was a politely worded note on the door
asking people to kindly go away, but that didn't work at all.
Disconnecting the door bell wire at the transformer helped some, but
that meant that we didn't know when someone we wanted
to see was at the door, or when the UPS delivery person dropped
something off, leaving switching the bell circuit on and off as the
only practical solution.
Mounting a toggle switch on the doorbell would be a simple enough
solution, but with the availability of suitable microcontrollers, why
not automate the switching? That would eliminate the problems
associated with forgetting to switch the bell off before going to bed
or back on after waking up.
After a couple of days of turning the problem over in my mind, I
decided to modify the ATtiny12 real time clock-calendar firmware I had
written previously, to make a resettable timer that would switch the
doorbell off on a
24 hour cycle. The device described here does just that. The circuit
connects to the doorbell circuit - taking power from the 18 VAC
from the doorbell transformer and switching power to the doorbell
circuit most of the day. The user interface is a pushbutton, a toggle
switch, and two LEDs. One LED - the green one -blinks at 1 Hz, just to
give me some comfort that the circuit is working. The amber LED glows
whenever the doorbell is disabled.
To set the timer, you just push the button momentarily, and when its
released, the amber LED will come on and the doorbell circuit is
disabled (the door bell button doesn't work) for a 10 hour
period. At the end of
the 10 hour period, the amber LED goes off and the doorbell is
enabled. 24 Hours after the button was last pushed, the amber LED comes
back on and the door chime circuit is disabled again. this cycle
repeats every 24 hours, and because its timing is set by a crystal
oscillator, it should be able to go for months or years without needing
to be reset.
The toggle switch allows the timer to be bypassed in case we want to
have the doorbell operating
24 hours a day or in the unlikely event of a circuit failure.
Simple as it is, I have to say that this is one of the more useful
projects for the home that I've built.
The Circuit
The heart of the circuit is the ATtiny12
programmed to time 24 hour cycles.
The circuit consists of
a power supply, a capacitor back-up circuit, a Atmel ATtiny12
microcontroller
as a timer, and solid state realy circuit to switch the AC voltage in
the
doorbell circuit. The simple user interface is comprised of a resync
button
to synchronize the timer, a bypass switch to bypass the timer if
desired,
and two status indicator LEDs. It is designed to be used by people who
are
not technically inclined.
The bell transformer, the doorbell button, and
the doorbell are not in the enclosure - they are built into
the house. The bypass switch and resync (or reset) button are
mounted on the enclosure.
Power for the circuit is derived from a half wave rectifier. One end of
the bell transformer (the one with the orange wire, marked "ORN"
connected to it) connects to circuit common
each half cycle through one of the diodes in the diode bridge.
During the same half cycle, the 1N4002 conducts, charging the
330 uf capacitor up to a maximum of 11 volts. The filtered
voltage powers the 78L05 5 volt regulator.
The current is limited with the 728 Ohm dropping resistor to a maximum
of 30 milliamps in order to minimize the maximum load on the bell
transformer, and to limit the amount of power that could be dissipated
by any component on the board in the event of a component failure. The
use of eight 1/4 watt resistors connected in series makes me feel a
little more comfortable than using a single 750 Ohm 2 Watt resistor
since the power dissipated will be spread over a large area of the
phenolic
circuit -pheonlic tends to discolor from heat more easily than
fiberglass
board, and even if a few of the resistors shorted, the others would
be able to handle the increased dissipation -giving a little extra
safety.
As a rule, I don't use resistors beyond 50% of their rated power. In
this case, the resistor string runs at 35% of rated power.
A .033 farad (not microfarad) capacitor is connected to the 2SA1020Y
and the 2N4401 to provide backup power to keep the timer running
in the event of a power failure. The 2N4401 is there to connect the
output of the 5 volt regulator to the ATtiny12 microcontroller when AC
voltage is present, and more importantly, to disconnect the
controller's power supply from the LEDs when AC voltage is not present.
Disconnecting the ATtiny12 from the LEDs keeps the LEDs from
discharging the .033 farad capacitor. The 2N4401 is there to turn on
the 2SA1020Y when power is first applied to the circuit, then to
quickly disconnect itself from the circuit when the +5 volts starts to
dip. The .033 farad capacitor supplies
voltage to the ATtiny12 through the 1k resistor. By the way, you can
use an 2N2907 in place of the 2SA1020Y.
I figure the .033 farad (not microfarad) capacitor should hold keep the
controller running for nearly two hours. If the capacitor charges up to
4.6 volts (allowing for some drop across the 2SA1020Y and the 78L05
regulator being on the low end of its voltage tolerance) and the
microcontroller runs down to 2.7 volts, that is a voltage change of 2
volts. According to the Atmel data sheet, the average current over the
range of 2.7 volts to 4.7 volts is 10 microamps. The time it takes the
capacitor to discharge will be (2 volts x .033 farads )/10 microamps =
6600 seconds = 1 hour and 50 minutes; long enough to sustain operation
over most small power outages. This analysis ignores leakage of the
capacitor and the reverse leakage of the 2SA1020Y.
The controller is an Atmel ATtiny12 using a 32768 Hz crystal for its
clock source. Its ideal for this project because it can run directly
from a 32768 Hz crystal without the need for other components, takes
very little power, and is inexpensive.
The reset pin on the microcontroller is pulled low by the "resync"
button. The button reset line
is pulled up to + volts with a 100k resistor and the button is
isolated from the reset pin with a 10k resistor to limit the energy
absorbed by the ATtiny12 in case of an ESD discharge to the reset
button. When the microcontroller comes out of reset, the timing cycle
begins. The reset pin is decoupled with a .001 uf capacitor.
Without this capacitor, noise from arcing in the doorbell button
contacts (The doorbell itself is inductive.) would reset the
microcontroller the first time the button was pressed after the end of
the "off"
part of the timing cycle. The 1 cycle per minute test signal was a
great help while discovering and debugging this. Even with the 1 cycle
per minute signal, it took dozens for trips between the doorbell button
and inside the garage where the timer is connected to work out what
was happening and test the solution.
There are three outputs from the ATtny12: A 1 Hz square wave that
drives an LED to show that the controller is running, the timing pulse
that is logic low for the first 10 hours of each 24 hour period, and a
test signal that is logic low for the first 30 seconds of each minute.
A SPDT slide switch on the board selects between the two signals. The 1
cycle per minute signal was very useful while testing and debugging the
circuit.
The output selected by the SPDT switch drives both the amber LED and
the gate of the AC switch MOSFET. When the output is low, the output
sinks current thorough the amber LED and its associated dropping
resistor, and it also holds the MOSFET in the off state. The gate of
the MOSFET has a 1k resistor in series with it so that if any high
frequency signals are capacitively coupled from the drain of the FET to
the gate, the current resulting from these signals would be limited.
AC power connection between the bell transformer and the doorbell
is interrupted by a diode bridge, made
with four 1N4007 diodes. If this were to be a production design,
I would have used a molded bridge rectifier rather than four separate
rectifiers. The AC connections on the bridge connect to the doorbell
transformer and to the doorbell itself. The negative output of
the bridge connects to circuit common and the positive output of the
bridge connects the drain of the MOSFET, which in turn has its source
connected to circuit common. When the MOSFET is driven into conduction,
it basically shorts the output of the bridge, allowing AC current to
flow through the AC circuit. While the MOSFET conducts, the doorbell
can be rung by pressing the doorbell button. While the MOSFET is not
in conduction, the doorbell cannot be rung.
A .015 uf capacitor reduces the rate of voltage change across the FET's
drain and sorce so as to reduce the chances of damage from what is
sometimes referred to as "dv/dt turn-on" in which a fast edge on the
drain capacitively couples into the gate circuit and cause the FET to
conduct. The possibility of dv/dt turn-on is increased by the presence
of the 1k resistor in series with the gate. My concern here is voltages
induced in the bell circuit by nearby lightning strikes. Also to
protect against transients, are a pair of 14 volt metal oxide varistors
(MOVs). A single 28 volt MOV would offer slightly better protection
because it would have a lower impedance
and it would also be less expensive. I used two 14 volt MOVs because I
have thousands of them and not 28 volt MOVs at all.
A bypass switch shorts the AC input terminals of the diode bridge
together, allowing the doorbell to operate regarless of the state of
the ATtiny12 timer, when we want to disable the timer function.
I am out of town 75% of the time for months on end, and the last thing
I want to receive is an overseas telephone call telling me that this
thing is acting up. For that reason, and my desire to not have to
repair this once built and installed, I designed for relaibility, and
this need is reflected throughout the design. Thats' one reason
the ATtiny12's low current consumption is important, and why the
current through the LEDs is only about 2 milliamps, and a MOSFET that
does not require drive current like a bipolar does -I wanted to keep
power requirements low. That made it easier to make a series dropping
resistor that would run at under 50% of its rated power under the worst
expected combination of input line voltage and load. The power supply
filter
capacitor is a mamoth 330 uf rated at 40 volts so that it would be
operated
wll below its voltage and ripple current ratings, and can even loose a
large percentage of its inital capacitance because of aging without
affecting
circuit operation. This desire for reliability is also seen in the
transient
voltage protection in the solid state relay section of circuit and in
the wiring of the board directly to the off-board switch and pushbutton
rather than using connectors. I suspect the IC socket is the weakest
point
in the design as far as reliabilty is concerned, and a socket was only
used because this was a hand-wired prototype and changing the chip if
it
had been soldered directly into the board would have been a nightmare,
and
posed some electrostatic discharge challenges. While on the subject of
electrostatic
discharge and reliability, this is a good point to mention that the
BUZ-73
MOSFFET needs to be handled carefully in order to avoid damaging it or
reducing
its reliability through electrostatic discharge. I dealt with this by
shorting
the gate, drain, and source leads with a small copper wire that
remained
in place until the part was completely mounted on the board.
Firmware
Please see the firmware for this controller at the end of this
document. The current version is bt040409D and the source listing is at
the end of this document.
95% Of the processor's time is spent sleeping
between interrupts.
The foreground loop that drives the 1 cycle per minute and the 1 cycle
per day output pin then puts the controller to sleep. Two times per
second, the microcontroller is awakened and interrupted by on-chip
timer. During the interrupt routine, the 1 Hz output is toggled, and on
even numbered interrupts,
a 255 year real time clock is updated. After the chip returns from the
interrupt, the program goes to the top of the foreground loop and
executes it again, then goes back to sleep. The cycle is repeated over
and over, and the processor spends about 95% of its time in the sleep
mode, which saves power considerably.
The routine that determines how long the doorbell is kept off is
straightforward and easily modified. Here is the snippet of the code
that does it. This code runs two times per second
;Set state of bellpin according to number of hours elapsed within current day.
mov temp,uhour
cpi temp,10
brpl havebell
cbi PORTB,bellpin ;Come here if test pin is to be off (low). Set test lamp low.
rjmp nobell
havebell:
The line "mov tmep,uhour" loads the register that contains the
hour as kept by the 24 hour real time clock-calendar.
The line "cpi temp,10" tests whether the number of hours that have
elapsed is equal to or greater than 10 (decimal). This could easily be
changed to a different number of hours, or to test the number of days
per month (uday), number of months each year (umonth), or the number of
years in each 255 year cycle (uyear) if you think you will be patient
enough to test that one. A more complex user interface would
allow more complicated programming using this real time clock-calendar
function. The realtime clock knows how many days should be in each
month and takes care of leap years, but since there is no way to set
the year, the resync button always sets the all the registers back to
"00".
The routine that operates the 1 cycle per minute test signal on pin 7
is the same as the routine above, except that it compares
the value in usecond with 30, so the output is low for the first 30
seconds of each minute and high for the last 30 seconds of each minute.
By the way, I tested the firmware by running the controller with its
internal RC oscillator since this was about 35 times faster than the
32768 Hz watch crystal. When
the code seemed to be working correctly, I set the fuse bits to
use a low frequency crystal.
The 2 Hz interrupt toggles the 1 Hz LED and updates
the clock-calendar registers.
The assembly language source file is on
this
page.
Construction
I am not one for fancy enclosures and would not
have bothered with one for this circuit, but it is going to be mounted
on the wall of my garage from many years of unattended operation, so I
was concerned about protecting it and of course, that it is powered
from the AC mains and fastened to the wall of my garage means that it
will be in a
metal box.
The resync button and bypass switch are mounted on
the top of the box and the blue category-5 cable
exits through a bushing in the bottom of the box. The bushing is a 1/4"
headphone plug.
The entire circuit was built on a piece of prepunched phenolic circuit
board. This board has holes on
0.1 inch (2.54 mm) centers and has one copper pad per hold on
the circuit side. Point-to-point wiring works fine -in many cases, I
just bent the component leads over to their destinations as jumper
wires are less reliable. For point-to-point jumpers I used #30 Kynar
covered wire-wrapping wire, and #30 tinned buswire for the ground bus.
Care was taken to keep the 18 to 24 VAC away from the rest of the
circuit; that's another reason for using a long string of 1/4 watt
resistors in the power supply - it
provides extra physical isolation between the AC, which could easily
destroy the microcontroller, and the microcontroller itself. Even
though the clock frequency is only 32768 Hz, the circuit is sensitive
to fast transients (especially on the reset input, as I found out
during initial testing after installation), so keep the connection as
short as practical, and this is especially true for the power supply
and reset decoupling capacitors.
The box I chose was a small unfinished minibox. Since this is supposed
to run for years without being fiddled with, there are not connectors
used in the circuit. All connections to the board are hard wired,
including the 2 meter length of category-5 cable that connects to the
bell transformer circuit. I drilled a couple of peep-holes in the front
of the box (the piece that was removed for the picture) so I could see
the LEDs.
A piece of fiberglass vector board was used as an insulator and placed
between the bottom of the metal box and the underside of the circuit
board. A single screw holds the vector board to the circuit board, and
another screw holds the vectorboard and minibox to the sheet rock wall
with a wall anchor.
The SPDT slide switch is only used to test the circuit, and so it is
not accessible from the outside of the box.
The minibox is conveniently mounted in my
garage next to the door into the house. This makes it
easy to change the timer's cycle at any time by merely
reaching up
and pressing the button on the top of the box (cover removed for the
photograph). The blue cat-5 cable leads up to the
doorbell
transformer, where it is connected with the two screw
terminalson
the transformer and to a wire leading to the doorbell button
with a wire nut. I really should staple the wire down someday.
The box is not grounded. Neither does it electrically connect to any of
the circuitry, and the circuitry is isolated from the AC line by the
bell transformer, so anyone touching the box is isolated from the AC
mains by two independent isolation systems. Still, I may run a ground
wire over to the water heater's cold water inlet
pipe just to be extra safe.
As of this writing, the timer has been in service for about five
months, and there is nothing to report. It is working as intended,
silently blinking its green LED in the darkness of the garage. A
battery backed-up real time clock-calendar based on the ATtiny12, using
the same
basic clock-caldendar code as this project has been running
continuously for two years without missing a beat. Based on that, I
expect this application to work queitly for years without my needing to
think about either it
nor will my wife be awakened by someone offering to sell her soap and
perfume early in the morning.
HOME
Contents © 2004 Richard Cappels All Rights Reserved. http://www.projects.cappels.org/
First posted in September, 2004.
You can send email to me at projects(at)cappels.org. Replace
"(at)" with "@" before mailing.
Liability Disclaimer and intellectual property
notice
(Summary: No warranties, use these pages at your own risk. You may use
the information provided here for personal and educational purposes but
you may not republish or use this information for any commercial
purpose without explicit permission.) I neither express nor imply
any warranty for the quality, fitness for any particular purpose
or user, or freedom from patents or other restrictions on the
rights of use of any software, firmware, hardware, design,
service,information, or advice provided, mentioned,or made reference to
in these pages. By utilizing or relying on software, firmware,
hardware, design, service,information, or advice
provided, mentioned, or made reference to in these pages, the user
takes responsibility to assume all risk and associated with said
activity and hold Richard Cappels harmless in the event of any loss or
expense associated with said activity. The contents of this web site,
unless otherwise noted, is copyrighted by Richard Cappels. Use of
information presented on this site for personal,
nonprofit educational and noncommercial use is encouraged, but
unless explicitly stated with respect to particular material, the
material itself may not be republished or used directly for commercial
purposes. For the purposes of this notice, copying binary
data resulting from program files, including assembly source code and
object (hex) files into semiconductor memories for personal, nonprofit
educational or other noncommercial use is not considered republishing.
Entities desiring to use any material published in this pages for
commercial purposes should contact the respective copyright holder(s).