mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
178 lines
8.0 KiB
Plaintext
178 lines
8.0 KiB
Plaintext
/*
|
|
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
\file alarm-clock.dox
|
|
\page alarm_clock Alarm Clock
|
|
|
|
\section clock_features Features
|
|
|
|
The alarm clock described on this page is a large example application that
|
|
uses many of the classes in the provided libraries: LCD, Form,
|
|
Field, SoftI2C, DS1307RTC (or DS3232RTC), Melody and
|
|
\ref power_save "PowerSave". The clock has the following features:
|
|
|
|
\li Displays both the time and date.
|
|
\li 12 hour and 24 hour time display modes.
|
|
\li Up to 4 configurable alarm times, plus a snooze alarm.
|
|
\li Three alarm sounds to choose from.
|
|
\li Configurable alarm timeout between 2 and 10 seconds.
|
|
\li Single button to activate the back light and/or stop the alarm.
|
|
\li Up, down, left, and right buttons to change clock settings.
|
|
\li Relay that controls the power to a separate radio circuit.
|
|
|
|
\section clock_main_circuit Main circuit
|
|
|
|
The main clock circuit consists of an Arduino Uno compatible board, a 16x2
|
|
LCD module, a realtime clock chip, and a piezo buzzer for the alarm:
|
|
|
|
\image html alarm_circuit.png
|
|
|
|
Some of the components can be purchased ready-made as the
|
|
<a href="http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide">Freetronics
|
|
16x2 LCD Shield</a> and the <a href="http://www.sparkfun.com/products/99">SparkFun
|
|
Realtime Clock Module</a>. I used the ready-made realtime clock module,
|
|
but made my own equivalent to the LCD shield from parts to aid in spacing
|
|
out the LCD and pushbuttons on the exterior of the box. The value of the 33R
|
|
resistor may need to be adjusted for different types of back light LED's.
|
|
See \ref clock_ds3232 "below" for information on using a DS3232-based
|
|
clock module instead of a DS1307-based module.
|
|
|
|
The whole circuit is built on a prototyping shield, with ribbon cables
|
|
connecting to the LCD. The Stop Alarm button, piezo buzzer, and radio
|
|
relay are not shown in this picture and some of the components are
|
|
soldered to the bottom of the shield:
|
|
|
|
\image html clock_shield.jpg
|
|
|
|
The clock module is based on the DS1307 chip and has an on-board coin battery
|
|
to keep the time and date ticking over even if the main circuit loses power.
|
|
The chip is I2C-based and has an auxillary SQW output that can be configured
|
|
to provide a 1 Hz squarewave signal. This signal is used by the software
|
|
running on the Arduino to detect when a new time or date is available for
|
|
display on the LCD. The DS1307RTC class takes care of the details of
|
|
talking to the chip via I2C.
|
|
|
|
\section clock_arduino_board Arduino board
|
|
|
|
To keep power consumption low, say for being powered by batteries, we don't
|
|
need a full Arduino Uno or similar board. The USB interface is unnecessary,
|
|
as is the on-board power supply if there is an external source of 5 volt power.
|
|
We also don't want the power and D13 status LED's to be draining power.
|
|
Therefore, a cut-down version of the Arduino is recommended. We used the
|
|
<a href="http://www.freetronics.com/collections/arduino/products/kitten">KitTen</a>
|
|
kit from <a href="http://www.freetronics.com/">Freetronics</a>, and didn't
|
|
solder up anything that wasn't strictly necessary. A
|
|
<a href="http://www.freetronics.com/ftdi-cable">5v FTDI USB-to-Serial cable</a>
|
|
is necessary for programming. Similar minimalistic built-it-yourself
|
|
Arduino designs should also work.
|
|
|
|
\image html kitten_minimal.jpg
|
|
|
|
\section clock_radio Controlling a radio
|
|
|
|
The relay connected to D11 can be used to control the power to a separate
|
|
radio circuit so that the radio can be used as an alarm. The relay switch
|
|
should be inserted between the radio's power supply and the main radio circuit.
|
|
When the relay is off, no power is applied to the radio. If the radio is
|
|
powered off 5V, then the relay circuit can be altered as follows to power
|
|
the radio directly from the Arduino's power supply:
|
|
|
|
\image html relay_control.png
|
|
|
|
\section clock_ds3232 Using DS3232 instead of DS1307
|
|
|
|
For clock modules based on the DS3232 chip, such as the
|
|
<a href="http://www.freetronics.com/products/real-time-clock-rtc-module">Freetronics Real Time Clock Module</a>, change the \c Clock typedef
|
|
in <tt>Clock.h</tt> to the following:
|
|
|
|
\code
|
|
typedef DS3232RTC Clock;
|
|
\endcode
|
|
|
|
The pads on the Freetronics module should be connected to the Arduino
|
|
as follows:
|
|
|
|
\li VCC and GND connected to 5V and GND on the Arduino.
|
|
\li SQI connected to A3.
|
|
\li SDA connected to A4.
|
|
\li SCL connected to A5.
|
|
\li BAT, 32K, and RST left unconnected.
|
|
|
|
*/
|
|
|
|
/*
|
|
NOTE: The following has been commented out for now. More work is needed
|
|
on the wind-up power supply.
|
|
|
|
\section clock_power Power supply
|
|
|
|
This section describes the power supply for the wind-up alarm clock,
|
|
which consists of a hand-cranked dynamo, a 3.6 volt NiMH battery, and a
|
|
charge pump DC-to-DC converter to boost the voltage up to 5 volts.
|
|
Here is the circuit:
|
|
|
|
\image html dynamo_power_supply.png
|
|
|
|
The dynamo must be based on a DC motor rather than AC (bicycle light dynamos
|
|
are typically AC). If you are using an AC dynamo, then replace D1 with a
|
|
full 4-diode rectifier bridge to convert the AC into DC first.
|
|
In Australia, <a href="http://www.jaycar.com.au">Jaycar</a> sells a suitable
|
|
<a href="http://www.jaycar.com.au/productView.asp?ID=MD7000">DC dynamo</a>.
|
|
|
|
Diode D1 stops the voltage in the battery from flowing backwards into
|
|
the motor. If you hook things up the wrong way around, then the motor
|
|
will spin without being cranked! In this case, reverse the + and - leads
|
|
on the dynamo and try again.
|
|
|
|
After D1, the main energy storage for the circuit is the 3.6 volt NiMH
|
|
battery (at least 1000 mAh capacity). These are commonly used in
|
|
cordless phones and can be obtained from most consumer electronics stores:
|
|
|
|
\image html battery.jpg
|
|
|
|
The main part of the circuit is next, consisting of a MAX619 regulated 5 volt
|
|
charge pump DC-to-DC converter chip. This chip boosts an input voltage of
|
|
between 2 and 3.6 volts up to 5 volts and regulates it into a nice flat
|
|
supply for the rest of the alarm clock.
|
|
|
|
Note: the MAX619 has a maximum rating of 3.6 volts, but when the dynamo is
|
|
being cranked rapidly the voltage at the cathode of D1 can spike to 4 volts
|
|
or more. The battery is fine with this for short periods of time,
|
|
but the MAX619 won't be happy. Hence the forward voltage drop on D2
|
|
is used to drop the supply down by 0.7 volts which will keep it within
|
|
the MAX619's input range. If the dynamo is rated higher than 5VDC,
|
|
then add extra diodes at D1 to drop the voltage down before it
|
|
hits the battery.
|
|
|
|
For normal uncranked operation the battery will need to be between 2.7 and
|
|
3.6 volts. If it falls below 2.7, then the battery is considered "empty".
|
|
A diode with a smaller voltage drop can be substituted for D2 for longer
|
|
operation times as long as the maximum dynamo output minus the voltage
|
|
drop is less than or equal to 3.6 volts. The "Sense Battery Status" output
|
|
is hooked up to an analog input pin on the Arduino to let it monitor
|
|
the battery voltage and display the current status to the user (after
|
|
adding 0.7 to account for the voltage drop on D2).
|
|
|
|
If you don't have 1N4001 diodes to hand, then 1N4004 will work just as well.
|
|
*/
|