Alarm Clock, Timer and Stopwatch are common time-keeping features. These functions are so frequently used that it is difficult to imagine modern life without a time-keeping application nowadays. Whether it is a scheduled wake up alarm, a stopwatch to track the time one has jogged or a timer and alarm to schedule office tasks, time-keeping is part and parcel of day-to-day life. This is an Arduino project demonstrating a complete time-keeping application. The project is a real-time clock and allows setting alarms, timers and running stopwatch.
It also displays real-time weather conditions with temperature and humidity indications as add-ons
The project has utilized RTC DS1307 for time-keeping and DHT11 sensor for fetching weather information. It is built on Arduino UNO and RTC used is internally powered through a button cell, so the project keeps track of real time and perform user-defined functions irrespective of the continuity of power supply to the circuit. The time and date, temperature and humidity values are displayed on a 16X2 LCD which also provides human interface to set alarm, timer and stopwatch. The users can feed inputs through a 4-switch keypad with switches for the following functions - Mode Selection, ENTER, Increment and SAVE buttons. A buzzer is connected to the Arduino board for realizing alarm and timer alerts.
The project runs under four modes of operations - :
1) Default Mode: By default, the project is set to display time, date, temperature and humidity information on the 16X2 LCD screen.
2) Alarm Mode: Here, user can set an alarm. The user enters this mode by pressing Mode selection button once and pressing the ENTER Button thereafter. He can first increase "Hours" value by pressing Increment button and skip to increase "Minutes" value by pressing the ENTER button again. After setting "Hours" and "Minutes" value the user can invoke alarm by pressing the SAVE button. To exit the alarm mode, Increment and mode selection buttons have to be pressed together.
3) Timer Mode: A timer setting mode can be entered by pressing the Mode selection button twice and pressing the ENTER button thereafter. The process for setting and saving time for timer is same as in alarm mode except that "Seconds" value can also be set in this mode. The user can exit the timer mode after setting time by just pressing the mode selection button once again.
4) Stopwatch Mode: To enter stopwatch mode, pressing mode selection button thrice and pressing the ENTER button thereafter works. Here pressing the SAVE button starts the stopwatch, pressing increment button pauses the stopwatch and pressing ENTER button again resets the stop watch. To exit the stopwatch mode, ENTER and Mode Selection buttons have to be pressed together.
• Arduino UNO
• RTC module-DC1307
• 16x2 LCD
• 5v Buzzer
• BC 547 transistor
• 1K ohm resisters -7pcs
• Push to ON switch-4pcs
• Voltage regulator -7805
• LED -5mm RED- 2pcs
• DHT11 sensor
• 10K POT for LCD contrast
The major blocks of the circuit are as follow
1) Power Supply Circuit
2) RTC DS1307 Module
3) DHT11 Temperature and Humidity sensor
4) LCD Display
5) 4-switch keypad
7) Arduino Board
The Arduino UNO programmatically controls all the time-keeping functions of the application. All the components are interfaced to the Arduino board for the circuit to run. The circuit is connected in the following manner -:
1) Power Supply - The entire circuit runs on a 5V DC supply. A 12V battery is used to source power to the circuit. The 12V supply is stepped down to 5V by a 7805 voltage regulator. The pin 1 of 7805 receives 12V supply from anode and pin 2 is grounded. The output 5V is generated at pin 3 of the regulator. An LED is also connected in parallel to the output as a visual indicator of power supply.
2) RTC DS1307 Interfacing - The RTC DS1307 has a built in button cell that allows keeping track of real-time irrespective of the power supply. For interfacing with the Arduino board, SDA and SCL pins of the RTC are connected to the SDA and SCL pins of the Arduino UNO.
Learn more about interfacing and programming RTC with Arduino here
3) DHT11 Temperature and Humidity Sensor - This is a digital sensor with inbuilt capacitive humidity sensor and Thermistor. It relays a real-time temperature and humidity reading every 2 seconds as a digital output. The pin 1 and 4 of DHT11 are VCC and Ground respectively. The output is received from pin 2 of the sensor which is feed to A0 pin of the Arduino board through a 10K ohm pull up resistor.
4) LCD Display - The 16X2 LCD display is connected to the Arduino board by connecting its data pins to pins 2 to 5 of the Arduino board. The RS and RW pin of LCD is connected to pins 12 and 11 of the Arduino UNO respectively. The E pin of the LCD is grounded.
The standard code library for interfacing Arduino UNO and Arduino Pro Mini are used in the project to program LCD with the board. The code library works as expected. Learn more about LCD interfacing with the Arduino UNO.
5) 4-switch Keypad - The keypad here is a set of four push-to-on switches which are connected to 10, 9, 8 and 7 pins of the Arduino UNO through 1K ohm pull-up resistors. The switches connected at 10, 9, 8 and 7 pins works as SAVE, Increment, Enter and Mode selection buttons respectively. In the circuit diagram, SAVE, Increment, Enter and Mode selection buttons are designated by FIRST, SECOND, THIRD and MODE labels.
6) Buzzer - The buzzer is connected to pin 6 of the Arduino board. A common emitter NPN BC547 transistor circuit is used to relay signal from Arduino pin to the buzzer.
How the Circuit Works
As the circuit is powered up, Arduino runs initial code thereof preparing LCD screen for display output and fetches signals from RTC and temperature sensor. The project enters default mode. Some initial messages are flashed on the display screen. The readings from RTC and temperature sensor are digitally read at pins SDA-SCL and A0 respectively. The readings are saved to internal EEPROM and time, date, temperature and humidity values are displayed on the 16X2 LCD.
The user inputs are read through the 4-switch keypad. On pressing any switch, a LOW signal is detected at the respective pin connected through the switch. A detection of LOW signal from the switches prompts the code to run respective functions to enter other modes and setting or resetting time values.
The project enters alarm mode on detecting a single LOW signal at mode selection button followed by a LOW signal at ENTER button. The setting and resetting of time values is done by detecting LOW signals at increment and SAVE buttons in a pre-defined sequence. The time entered by the user is saved to internal EEPROM and compared to the real-time fetched from the RTC in a loop. When the user entered time matches the current time, a LOW signal is output at pin 6 of the Arduino board. This prompts to light up the LED connected in parallel to the buzzer circuit as visual indicator of alarm alert. In the buzzer circuit, on receiving a LOW signal at pin 6, the common emitter configured BC547 transistor gets short circuited allowing a flow of current from collector to emitter. The buzzer gets a ground at the collector end of the transistor and starts buzzing the alert. The alarm mode is terminated after the buzzer alert and LED signal. The program code allows to exit from the alarm mode on detection of LOW signals from increment and mode selection buttons simultaneously.
The timer mode is activated on detection of two continuous LOW signals at mode selection button and followed by a LOW signal at ENTER button. The setting and resetting of time values is again done by detecting LOW signals at increment and SAVE buttons in a pre-defined sequence. In timer mode, user is allowed to set the "Seconds" value as well. The user entered time is counted down by keeping a track of current time from the RTC. The countdown time is displayed on the LCD screen with the help of loop logic. When the countdown reaches zero value, again a LOW signal is activated on pin 6 of Arduino thereby running the buzzer and lighting up LED as explained above. Thereafter, the mode is terminated and resumes to the default mode.
The stopwatch mode is invoked on detection of three back to back LOW signals at mode selection switch followed by a LOW signal at ENTER button. The display at the LCD is reset to show zero time values. On detection of a LOW signal at SAVE button, stopwatch starts. The time user starts stopwatch is fetched from RTC and saved to the internal memory. In a loop the current time is fetched from the RTC and saved to internal memory. The current time is compared to start time and a time update is displayed accordingly on the LCD screen. If a LOW signal is detected at the increment button, the loop is stopped for until a start signal is received thereof stopping any time updates. Once the stopwatch has started, on detection of a LOW signal at ENTER button resets the time to zero and prompts to wait for a start signal. The mode is terminated on receiving LOW signals at ENTER and Mode selection buttons simultaneously. The termination of the mode resumes the default mode.
The time and date updates in any mode remain unaltered even if the power supply is interrupted because RTC DS1307 has an in-built button cell to keep RTC in sync. The temperature and humidity readings are updated every 2 seconds as DHT11 relays the digital readings out in that interval.
The code uses standard open-source libraries of Arduino UNO. When the circuit is powered on, the Arduino loads standard libraries of LCD, EEPROM and RTC and import the functions used from the libraries.
The Arduino board is initialized through a setup() function to start fetching real-time from RTC module, prepare LCD for display and activating input/output mode and HIGH/LOW signals at the pins interfaced with the keypad and buzzer circuit. Some initial messages are flashed through the LCD screen using print function of the LCD class. The RTC is checked and configured to relay current time and date.
The RTC and DHT11 readings are saved to the internal EEPROM.
The readings are displayed on the LCD screen. With this project enters the default mode.
The other modes are activated on detection of LOW signals from keypad switches in a pre-defined pattern. A checkTime() function is used to keep track of current time and updating it to the internal EEPROM. The same function is utilized to return time and date values to local variables in different mode specific functions where values are compared in specific loops and accordingly either alarm time is updated to be matched with current time or timer value is counted down from the start time onwards or stopwatch date and time value is counted up from the start time onwards.
In alarm mode user entered time is compared to match the current time and a LOW signal is output at pin 6 for activating the buzzer. In timer mode, current time is compared to start time for counting down and as the counter variable matches zero value, a LOW signal is passed to buzzer circuit. In stopwatch mode current time is compared to start time and a counter variable is updated in ascending order and accordingly real-time values are displayed to the LCD screen.
The detection of LOW signals from keypad switches in a pre-defined pattern controls activation, setting and resetting of user entered time and date values, pausing or resuming and terminating the current mode. The alarm, timer and stopwatch modes on termination resumes to the default mode.