You are on page 1of 105

Smart Sensory Alarm Clock

Senior Project Final Design Report

Design Team #7 Brad Morse Karl Pilz Josh Runtas

Faculty Advisor: Dr. Nathan Ida

May 1, 2007

Table of Contents
List of Figures ..................................................................................................................... ii List of Tables ..................................................................................................................... iii List of Pseudo Code ........................................................................................................... iii Abstract ............................................................................................................................... 1 Introduction......................................................................................................................... 2 Statement of Need........................................................................................................... 2 Problem Definition.............................................................................................................. 2 Goal................................................................................................................................. 2 Objectives ....................................................................................................................... 2 Constraints ...................................................................................................................... 3 Design Requirements .......................................................................................................... 4 Pressure Sensors.......................................................................................................... 4 LCD Display ............................................................................................................... 4 Keypad Input............................................................................................................... 5 External Lamp............................................................................................................. 5 Coffee Maker .............................................................................................................. 5 Microcontroller ........................................................................................................... 5 Power Input and Battery Backup ................................................................................ 6 Wireless Disconnect Button........................................................................................ 6 Snooze Button............................................................................................................. 6 DC Motor Fan Mechanism ......................................................................................... 6 Overall Size Requirements ......................................................................................... 7 Accepted Technical Hardware Design................................................................................ 8 System Overview ............................................................................................................ 8 Keypad (BM) ............................................................................................................ 11 Force Sensing Resistors -FSRs (BM) ....................................................................... 14 Snooze (Shocking) Button (BM) .............................................................................. 22 DC Fan / Blower Mechanism (BM)......................................................................... 29 Wireless Remote Kill Switch (KP) ........................................................................... 32 Piezoelectric Buzzer (KP)......................................................................................... 38 Lighting Control (KP)............................................................................................... 42 Coffee Maker (KP) ................................................................................................... 47 Supply Power (KP) ................................................................................................... 50 Liquid Crystal Display and Controller (JR).............................................................. 52 Software Design................................................................................................................ 54 Testing Procedures............................................................................................................ 66 Wireless Remote Kill Switch (KP) ............................................................................... 66 Piezoelectric Buzzer (KP)............................................................................................. 67 Lighting Control (KP).................................................................................................. 67 Coffee Maker (KP) ...................................................................................................... 68 Keypad (BM) ................................................................................................................ 68 Force Sensing Resistors (BM) ...................................................................................... 69 Snooze Button (BM) ..................................................................................................... 69 DC Motor / Fan Mechanism (BM) ............................................................................... 70 Financial Budget ............................................................................................................... 71

Project Schedule................................................................................................................ 73 Design Team Information ................................................................................................. 76 Conclusions and Recommendations ................................................................................. 77 References......................................................................................................................... 79 Appendix A Software Coding........................................................................................ 80 DM2023 ........................................................................................................................ 81 loadCR .......................................................................................................................... 83 Main .............................................................................................................................. 84 printTime....................................................................................................................... 86 RTC............................................................................................................................... 91 usDelay ......................................................................................................................... 92 setTime.......................................................................................................................... 93 msDelay ........................................................................................................................ 96 GetKey .......................................................................................................................... 97 Appendix B Datasheets.................................................................................................. 99

List of Figures Figure 1 Detailed Block Diagram (BM) .......................................................................... 9 Figure 2 -Overall System Pspice Circuit Schematic (BM)............................................... 10 Figure 3 - Keypad Close-up.............................................................................................. 11 Figure 4 -Keypad Pspice Schematic (BM) ....................................................................... 12 Figure 5 - Force Sensing Resistor..................................................................................... 14 Figure 6 - Force Sensing Resistor Physical Setup (BM) .................................................. 15 Figure 7 - FSR Pspice Schematic (BM)............................................................................ 15 Figure 8 - FSR Plug and Sensitivity Knob Location ........................................................ 17 Figure 9 - FSR Plug and Sensitivity Knob Detail............................................................. 17 Figure 10 - Bed Test Rig................................................................................................... 18 Figure 11 - Bed Test Rig Detail........................................................................................ 19 Figure 12 - Bed Test Rig FSR Placement Detail .............................................................. 19 Figure 13 - FSR Force vs. Resistance graph (Photo courtesy of Trossen Robotics) ........ 20 Figure 14 - Snooze Button ................................................................................................ 22 Figure 15 Shocking Snooze Button Physical Setup (BM)............................................. 23 Figure 16 Shocking Snooze Button Pspice Schematic (BM) ........................................ 24 Figure 17 - Snooze Button ................................................................................................ 26 Figure 18 - Snooze Button Side View .............................................................................. 26 Figure 19 - Snooze Button Underside............................................................................... 27 Figure 20 - Snooze Button Connections ........................................................................... 27 Figure 21 - DC Motor / Fan Mechanism .......................................................................... 29 Figure 22 - DC Motor / Fan Mechanism .......................................................................... 30 Figure 23 - DC Motor / Fan Mechanism Pspice Schematic (BM) ................................... 31 Figure 24 - Wireless Kill Switch ...................................................................................... 32 Figure 25 - Wireless Kill Switch Internals ....................................................................... 33 Figure 26 - Wireless Receiver Circuit .............................................................................. 34

ii

Figure 27 Wireless Remote Kill Switch Transmitter Schematic (KP) .......................... 36 Figure 28 Wireless Kill Switch Receiver Schematic (KP) ............................................ 37 Figure 29 - Piezoelectric Buzzer....................................................................................... 38 Figure 30 - Buzzer Staging Pspice Schematic (KP) ......................................................... 39 Figure 31 - Backside of Alarm Clock, Lamp Outlet......................................................... 42 Figure 32 - Lamp Pspice Schematic (KP)......................................................................... 43 Figure 33 - Backside of Alarm Clock, Coffee Outlet ....................................................... 47 Figure 34 Coffee Maker Pspice Schematic (KP)........................................................... 48 Figure 35 - Lamp and Coffee Maker ................................................................................ 48 Figure 36 - Power Supply ................................................................................................. 50 Figure 37 - Power Supply and Battery Backup Pspice Schematic (KP)........................... 51 Figure 38 - LCD Display .................................................................................................. 52 Figure 39 - Custom Number Generation .......................................................................... 53 Figure 40 - Calibrating Screen Shot.................................................................................. 54 Figure 41 - Demo Choice Mode ....................................................................................... 55 Figure 42 - Initialed Screen............................................................................................... 56 Figure 43 - Enter Alarm Screenshot ................................................................................. 57 Figure 44 - Alarm Set Screenshot..................................................................................... 58 Figure 45 - Alarm Stage Set Screenshot ........................................................................... 59 Figure 46 - Alarm Stage 4 Monitoring ............................................................................. 60 Figure 47 - Program Flowchart......................................................................................... 61 Figure 48 - Alarm Clock Calibration Flowchart............................................................... 62 Figure 49 - Alarm Initialization Flowchart....................................................................... 63 Figure 50 Implementation Gantt Chart Breakdown....................................................... 74 Figure 51 Implementation Gantt Chart Timeline........................................................... 75

List of Tables Table 1 Estimated Labor Cost........................................................................................ 71 Table 2 Material Budget Sheet ...................................................................................... 72 Table 3 Design Team Information................................................................................. 76

List of Pseudo Code Pseudo Code 1 Keypad (BM) ........................................................................................ 13 Pseudo Code 2 Force Sensing Resistor (BM)................................................................ 21 Pseudo Code 3 Shocking Snooze Button (BM)............................................................. 28 Pseudo Code 4 DC Motor / Fan Mechanism (BM) ....................................................... 31 Pseudo Code 5 Wireless Remote Kill Switch (KP) ....................................................... 35 Pseudo Code 6 Piezoelectric Buzzer (KP)..................................................................... 41 Pseudo Code 7 Lighting Control (KP)........................................................................... 46 Pseudo Code 8 Coffee Maker (KP) ............................................................................... 49 Pseudo Code 9 PIC Pseudo Code for Initializing Alarm............................................... 65

iii

Abstract

The Smart Sensory Alarm clock stimulates the majority of the human senses to provide superior reliability in ensuring timely awakening. By gently tantalizing the user to arise with a simple coffee aroma, then low intensity alerts; heavy sleepers are given ample opportunities to gradually get out of bed. However if these polite gestures are ignored, extremely swaying measures will follow to promise success.

Key Design Features: Microprocessor controlled time and alarm keeping Keypad time and alarm input LCD display of time Three progressive alarm stages with variable light and sound Weight monitoring of human presence in bed Standard snooze button for alarm stage 1 and 2 disable Shocking snooze button upon alarm stage 3, without snooze alarm disable DC motorized fan mechanism forces air upon users face in alarm stage 3 Wireless alarm disconnect switch acts as only way fully disable alarm Unit includes 120V AC plugs for lamp and coffee maker Coffee maker initialization prior to first alarm stage

Introduction

Statement of Need

Current alarm clocks are inadequate due to the fact that they are too simple to disarm and use ineffective and out-dated audible stimulation methods to awake the user. A more effective device is needed to be designed that will progressively ease the customer from a deep slumber to a refreshing consciousness.

Problem Definition

Goal

To design an alarm clock that gradually awakens the customer using lights, sounds and aromas to entice the user to get out of bed before more violent and persuasive measures are taken.

Objectives Interact with weight sensors to monitor the beds occupancy, ensuring that the alarm will remain on if a user is still in bed. The system will include three alarm stages that progress from gentle and soothing -- using fresh coffee aromas and two chances to snooze, to forceful -- using a shocking snooze button, facial contact from a motorized fan, as well as intensifying lights and sounds.

Easily interact with exiting simple off-the-shelf lamps and coffee makers through the use of 120V outlets located on the back of the alarm clock unit.

Incorporate a wireless alarm disconnect switch located in a distant location, ensuring the occupant has to exit the bed.

Integrate an easy to use keypad for user alarm and time entry.

Constraints Operate off of a 120V A/C and 6V battery backup. Adhere to wireless range and power consumption of alarm disconnect switch. Accurately and quickly detect if an individual has exited the bed. Entire unit shall fit neatly on any standard nightstand.

Design Requirements

Pressure Sensors The pressure sensors must support up to 400 pounds in order to accommodate the weight of the bed as well as multiple individuals. Individual sensors must be able to detect a range of pressure up to 100 pounds. The sensors must be flat and durable to install between the bed frame and box spring. The sensors need to interface with 5 volts D/C and draw minimal current, roughly 25mA. The sensors must minimize I/O analog pins on the PIC18F452. The sensors must be adjustable and auto-calibrating for cases when one or two people are in bed.

LCD Display The display needs to be easy-to-read and display the time in standard AM/PM format. The display should also display if the alarm has been set. A minimum size display should be 2 inches tall by 5 inches wide. Custom messages should be displayed so that the user knows how to operate the alarm clock properly.

Keypad Input The unit must include 0 through 9 buttons as well as the following separate buttons: Alarm Set, Time Set, Enter, AM/PM and Cancel. The keypad must minimize input pins on the PIC18F452.

External Lamp Any standard off-the-shelf desk lamp with 120VAC power input. Should be relatively small to fit on nightstand. A minimum current draw is desired to be less than 2A, and 100W bulb.

Coffee Maker Any standard off-the-shelf coffee maker with 120VAC power input. Should be relatively small to fit on nightstand. Current draw is desired to be less than 10A.

Microcontroller The central microcontroller needs must include at least 30 I/O pins and 2 analog-to-digital converters, preferably a Microchip PIC18F452. The system only needs limited memory to store whether the alarm is set as well as the time the alarm is set for. The microcontroller will be a DIP package so that it can be removed from a soldered socket on the main PCB for repeated programming.

Power Input and Battery Backup The battery backup must be able to power the microcontroller, the LCD display, the buzzer and the input keypad for 48 hours.

Wireless Disconnect Button Desired range of operation is approximately 10-50 feet. Simple FM frequency can be used with encoding and decoding of a single bit transmitted signal. Transmitter needs to be battery powered for remote installations.

Snooze Button

Standard snooze button operation is required for first 2 stages. Electric shock circuit is applied to snooze button upon alarm stage 3 activation.

After alarm stage 3, snooze button will not affect alarm peripherals.

DC Motor Fan Mechanism A DC motor will spin fan blades, which force air into ducting which aims at the user lying in bed. Can run off of up to 12V DC.

Overall Size Requirements The complete system should fit comfortably on a 2 feet wide by 2 feet long nightstand, including the coffee maker, lamp, and alarm. The footprint of the alarm should be approximately 10 inches wide by 8 inches long, and the components should be enclosed in a box. Height should be less than 4 inches tall.

Accepted Technical Hardware Design

System Overview

The Smart Sensory Alarm Clock utilizes a myriad of peripheral devices, all coming together to produce a superior automated wake up design. Each of the hardware components is centrally incorporated into a PIC18F452 microcontroller where software then takes over to control operations. Upon completion, the system will be compact, sleek, and contain a multitude of functionality. See the Figure 1 for a visual representation of the block diagram, which includes details of I/O pin configurations on the PIC18F452. Figure 2 shows a detailed final circuit schematic.

Figure 1 Detailed Block Diagram (BM)

Figure 2 -Overall System Pspice Circuit Schematic (BM)

10

Keypad (BM)

Figure 3 - Keypad Close-up

Using a keypad for programming the timekeeper of the clock as well as the alarm time setting is fundamental in an alarm clock. Transferring data from the user into the microcontroller is step number one in using this device, thus the keypad plays a crucial role. The keypad is to be a 4 row x 4 column (16 key) matrix keypad, GH5015-ND made by Grayhill. The original idea was to include a supplemental IC for multiplexing the 8bit (8-wire) digital signal down to a 4-bit (4-wire) digital input signal to the microcontroller. However, upon final review budget and of I/O controller pin availability, it was decided to take each individual row and column of the keypad directly 11

into the PIC as 8 separate inputs. Key press contact de-bouncing and EMI noise were not considered a threat upon final testing.

The entire key press detection cycle takes approximately 50mS. Once a key is pressed, contact bounces subside within a few microseconds and are ignored, since the only input signal seen at the microcontroller is a TTL switching from 0 to +5V. PIC inputs to the keypad rows are connected through 270k Ohm resistors to prevent any shorts during the scan cycle if more than one key is being held at a time. See Figure 4 Keypad Schematic for more hardware detail.

Figure 4 -Keypad Pspice Schematic (BM)

12

Since the inputs from the keypad are all digital, no A/D conversion is necessary, and all 8 data input pins on the PIC18F452 are on PORTB. The necessary buttons to be implemented will be the digits 0-9, Enter, Clear, AM/PM, Alarm Enable, Time Set and Alarm Set. The corresponding pseudo code for the proper sequence of time set and alarm set coding into the microcontroller can be seen below, in Pseudo Code 1

Case 0: PIC sees no Input from keypad Option 1 Display Time Option 2 - Custom message, please set time or no alarm set Case 1: PIC detects Alarm_set button pressed PIC expects 5 following key presses to store in memory: = X4 X3 : X2 X1 Then AM or PM button Case 1: 3 numeric keys pressed, No AM or PM pressed Time format only uses 3 digits, X4 = null, assume AM Result = Alarm_set = X3 : X2 X1 AM Case 2: 3 numeric keys pressed, AM or PM pressed Time format only uses 3 digits, X4 = null, Result = Alarm_set = X3 : X2 X1 PM Case 3: 4 numeric keys pressed, No AM or PM pressed Time format uses 4 digits Result = Alarm_set = X4 X3 : X2 X1 AM Case 4: 4 numeric keys pressed, AM or PM pressed Result1 = Alarm_set = X4 X3 : X2 X1 AM Result2 = Alarm_set = X4 X3 : X2 X1 PM Case 2: PIC detects Time_set button pressed PIC expects 5 following key presses to store in memory: = X4 X3 : X2 X1 Then AM or PM button Case 1: 3 numeric keys pressed, No AM or PM pressed Time format only uses 3 digits, X4 = null, assume AM Result = Time_set = X3 : X2 X1 AM Case 2: 4 numeric keys pressed, No AM or PM pressed Time format uses 4 digits Result = Time_set = X4 X3 : X2 X1 AM Case 3: 4 numeric keys pressed, AM or PM pressed Result1 = Time_set = X4 X3 : X2 X1 AM Result2 = Time_set = X4 X3 : X2 X1 PM
Pseudo Code 1 Keypad (BM)

13

Force Sensing Resistors -FSRs (BM)

0.75

2.375

Figure 5 - Force Sensing Resistor

To ensure fast and accurate detection of a bodys presence in bed, the idea of using both thermal and force sensing resistors was scrapped. This is simply because both sensors provide redundant feedback to the system. Upon final review of the project design, force (weight) sensing will ensure that all necessary detection criteria are met in all cases of the alarm sequencing. Using four analog Force Sensing Resistors from Phigets USA placed on each corner of the bed between the box spring and the frame will accurately monitor the bed. These thin, flat, inexpensive sensors are perfect for this application. Being only 0.008 inches thick and 0.75 inches wide, they provide unparalleled placement abilities. A long shielded 2-wire cable will provide remote placement options. See Figure 6, 7, 8, and 9 for details.

14

Figure 6 - Force Sensing Resistor Physical Setup (BM)

These variable resistors will be all connected in parallel and constantly kept with +5V across them. As the force increases on the resistor, the resistance goes down, decreasing the output voltage of the circuit, as shown in Figure 14.

Figure 7 - FSR Pspice Schematic (BM)

15

The position of the weight distribution over the bed will not matter because of the way weight is distributed over the bed frame. Depending on where the person is physically located in bed, either one or all of the sensors will yield a change in force. A 5k Ohm potentiometer was added to the side of the alarm clock unit so that the sensitivity of the sensors could be adjusted. Upon power up, the alarm clock will automatically calibrate the sensors according to the individual users weight (see software section for more detail). This is beneficial for multiple users in bed, or people with variable weight, so that the sensors can most accurately determine whether or not the person is in bed. The idea of keeping the sensors at +5V continuously is to eliminate the possibility of simply unplugging the detachable FSR cable from the alarm clock. This may be thought of as a way to trick the clock into thinking the person is not in bed when they really are. Simply put, the higher the voltage read into the PIC, the less probable it is that someone is in bed. When the cord is detached, the voltage will be as high as possible, signifying someone is still in bed. One has to be careful to ensure that this FSR cable is physically plugged in to make sure that their body presence will be seen as not in bed during the appropriate alarm stage. If this is not the case, the alarm clock will NOT shut off, even when the disconnect button is pressed because the clock will think the user is still in bed! Figure 8 and Figure 9 depict the FSR detachable cable location as well as the sensitivity adjustment knob.

16

Figure 8 - FSR Plug and Sensitivity Knob Location

Figure 9 - FSR Plug and Sensitivity Knob Detail

17

The idea of bringing in a full size queen bed for testing was preposterous, so a smaller scaled version was constructed out of pine wood and some small pieces of custom fabricated angle iron. The basic structure intended to recreate the wooden box spring with a 2 long 2x10 flat piece of wood, which was set into the metal frame constructed of angle irons. The final test rig is strong enough to support a 200 pound person standing on top of it. A challenge was to make the box spring flush with the angle irons. The angle irons are affixed to the system with wood screws, whose head protrude up into the region where the box spring is to rest. For this reason, 8 concave areas were sanded out of the underside of the box spring and meticulously tested for flaws. As for the attachment of the sensors themselves, a preliminary electrical tape job to the angle iron stood the testing throughout the semester and was left in place. Wiring for the sensors was tied down using staples into the soft pine. These details can be viewed in Figure 10, Figure 11, and Figure 12.

Figure 10 - Bed Test Rig

18

Figure 11 - Bed Test Rig Detail

Figure 12 - Bed Test Rig FSR Placement Detail

19

It can be extrapolated from Figure 13 that a resistance of approximately 100k ohms corresponds to a preliminary force reading of approximately 25g (about 0.5lbs). At a resistance of 2k ohms, the force reading is approximately 10kg (about 22 pounds). When included in the overall picture of operation, 4*22=88lbs of maximum detection distributed over the 4 equal points of contact sensing. This is the initial tested range of values; however, after the sensitivity knob is added, the system will auto calibrate this value. This is ideal for detecting a change in body weight of a human being. It is understood that the mattress is designed to evenly distribute weight for comfort, and thus will reduce the accuracy of the sensors. However, since it is desired to take a weight difference, everything is in order.

Figure 13 - FSR Force vs. Resistance graph (Photo courtesy of Trossen Robotics)

The force sensing resistors output will be interpreted by the PIC18F452 as an analog input signal, and will therefore need to undergo A/D conversion inside the PIC, as

20

interpreted through pin RA1. The pseudo code for implementing the force sensing resistors is shown in Pseudo code 2.

Case 1: Voltage below Threshold, Body detected in bed If (Alarm Stage 3 = On) All Alarms remain on until Remote Disconnect = On Case 2: Voltage above Threshold, Body NOT detected in bed NO alarms activate, even if Alarm time = Time of day Timer monitors bed for 30 min (ensures no cheating) Reset for next alarm setting
Pseudo Code 2 Force Sensing Resistor (BM)

21

Snooze (Shocking) Button (BM)

Figure 14 - Snooze Button

The snooze button particular to this alarm clock will also serve a temporary special purpose. In standard operation of any normal alarm clock, the snooze button serves as a quick method for disarming the annoying buzzer during alarm stages. The Smart Sensory Alarm Clocks snooze button will also serve this purpose, but only during the first two alarm stages, allowing the user two separate opportunities to get out of bed. Upon alarm stage 3 activation, the snooze button will cease to terminate the horrific effects of alarm stage 3. Instead, it acts as another stimulus to entice the user to get out of bed. As soon as the user makes contact with the snooze button, a small voltage will be applied. This will in turn cause a slight electric shock to be felt, using the human hand as a resistor completing the ground connection, and the path of current will be safe, through the hand only. Figure 15 illustrates the physical setup of the theory of operation.

22

Figure 15 Shocking Snooze Button Physical Setup (BM)

The final circuit to be implemented can be seen in Figure 16. The heart of the current driver is the 555 timer, which simulates a PWM signal to pulse the primary coil of a small 1k : 200k audio transformer. Every time there is a pulse, a sharp spike in current flows through the secondary coil of the transformer, which is directly connected to the snooze button. The frequency of pulses is determined by R2, R3, and C1. The output signal from the 555 timer then goes through a TIP31 transistor, which can handle the current sent through the primary coil. An additional 100 Ohm resistor is placed in series with the primary to limit the output current to a safe level of under 1mA. It should also be noted that the 555 Timer IC operates on 5V DC.

23

Figure 16 Shocking Snooze Button Pspice Schematic (BM)

Detection of when the snooze button is pressed will be fed into the PIC via pin RA1, and when necessary, pin RC3 will activate a relay, which gives power to the circuit and in turn electrify the snooze button. The switching mechanism that is the heart of the snooze button will have to provide two electrically isolated pin connections upon depression. First, the snooze button operation will need to be insulated from the shocking circuit, so to not send unnecessary current back into the PIC. This is accomplished via two small single pole single throw push button type switches, which automatically retract after depression. The switches themselves operate by having +5V applied to them, being normally open. Upon depression, 5V will be closed across a 4.6k Ohm pull down resistor to ground. A probing pin from the PIC will be constantly monitoring this switching effectively detecting a snooze button press. By gluing the underside of the snooze buttons flat protoboard surface to the tops of both pushbutton switches, we have effectively isolated the shock circuit from the snooze button circuit.

24

The second pin connection will tie the metallic snooze button into the shock circuitry. In order to insure the total current flows from the positive terminal of the secondary to the negative terminal, copper tracking of a protoboard is used. One end of the tracking is soldered to the positive, where the other is soldered to the negative. The rows of copper tracking are soldered together in a zigzagging pattern of every other row. This way, there is not yet a connection between the positive and negative terminals. The connection between the terminals (i.e. shocking current) comes when a resistance (human finger) is placed across two adjacent copper tracks.

Mechanically, the snooze button arrangement is mounted to the underside of the top half of the alarm clock enclosure with 4 retaining bolts. A 1.75 x 0.75 hole is cut in the top of the unit to allow the button to be recessed. The associated control circuitry is located directly next door to the switch on the underside as well. All the data, control, and power wires are tied to an internal 6 pin connector plug, which can be detached for easy maintenance. Figure 17, Figure 18, Figure 19, and Figure 20 detail the physical design.

25

Figure 17 - Snooze Button

Figure 18 - Snooze Button Side View

26

Figure 19 - Snooze Button Underside

Figure 20 - Snooze Button Connections

27

The method of operation behind the snooze button is shown below in Pseudo Code 3. Alarm Stage = off; Buzzer = off; Light = off; When (Time = Alarm set and Alarm Stage = off) Alarm Stage = low; Buzzer = low; Light = low; While (Snooze pressed = no) Buzzer = low; Light = low; While (Snooze pressed = yes) Buzzer = off; Light = 1; Alarm Timer = 5 min; Decrement Alarm Timer until it reaches zero; When (Alarm Timer reaches 0 and Alarm Stage = low) Alarm Stage = med Buzzer = med; Light = med; While (Snooze pressed = no) Buzzer = low; Light = low; While (Snooze pressed = yes) Buzzer = off; Light = med; Alarm Timer = 5 min; Decrement Alarm Timer until it reaches zero; When (Alarm Timer reaches 0 and Alarm Stage = med) Alarm Stage = high Buzzer = high; Light = high; Shock Activation: While (Alarm Stage = high) Output signal to close relay or bjt = Closed; //armed Else Output signal to close relay or bjt = Open; //disarmed While (Snooze pressed = yes) Buzzer = 3; Light = 3; While (Snooze pressed = no) Buzzer = 3; Light = 3;
Pseudo Code 3 Shocking Snooze Button (BM)

28

DC Fan / Blower Mechanism (BM)

Figure 21 - DC Motor / Fan Mechanism

The last device to initiate force in waking the subject up will be in the form of contact, in particular, facial air contact. Initially, a simple water gun was to be electronically controlled to pump several quick blasts of water at the heavy sleeper. However, due to safety issues, an air blasting mechanism was desired.

A 12V DC motor and fan mechanism was taken out of a small hair dryer. The diameter of the fan is 2.5 and is 1 long, which was slightly bigger than the height of the enclosure. In order to fit properly, the enclosure had to be sanded down slightly. A flexible metal strap was wrapped around the fan and bolted to the bottom of the fixture to keep the fan in place. In order to direct the air from the fan to a central focused stream, an automotive oil filter was affixed to the front of the fan. A hole was cut in the front

29

face of the enclosure to allow the rapidly rushing air to escape. The end diameter of the focused air is 0.5.

For best results, the fan will be aimed directly at the pillow to ensure that the most annoying body part is hit, the head. In order to accomplish this, the output from the fan is placed in the same plane as the LCD, where the thinking is that if someone is looking directly at the LCD, the fan will also be aimed at the face.

Figure 22 - DC Motor / Fan Mechanism

30

The circuit of Figure 23 shows the control circuitry for powering the fan.

Figure 23 - DC Motor / Fan Mechanism Pspice Schematic (BM)

Upon activation of PIC pin RC7, a TIP31 transistor will switch on a power relay that in turn supplies a 12V DC motor from a small hair dryer with 12V DC. The maximum tested turn on current and running current is just under 1A. Power draw is not an issue due to the power supply being fed from the 120V AC wall plug. The fan generates enough air to be felt up to a distance of approximately 3 feet away, but if that doesnt entice the user to get out of bed, the sound of the motor running sure will!

The corresponding logic can be seen in Pseudo code 4.

While (Alarm Stage = high) Output signal to close relay or bjt = Closed; Else Output signal to close relay or bjt = Open;
Pseudo Code 4 DC Motor / Fan Mechanism (BM)

//armed //disarmed

31

Wireless Remote Kill Switch (KP)

Figure 24 - Wireless Kill Switch

One feature that was thought to be helpful to our design is a wireless remote kill switch. This switch, if pressed, overrides all other actions in the alarm clock. This switch is mounted in a room far away from the bedroom of the user. This is to ensure that the sleeper to get out of bed and travel a good distance to press the remote kill switch uses significant effort. The farther away the sleeper must travel to hit the switch, the less likely they are to return to bed. The goal of this feature is the wireless kill switch must be small in size so that it can be mounted or placed in any room far away from the bedroom. It must also have considerable range (a range that would cover the length of a typical house.) One final design constraint is that it must be battery operated. This is so that the user does not have to worry about needing an outlet in the vicinity of the device.

32

Figure 25 - Wireless Kill Switch Internals

As can be seen from the two pictures above, the wireless kill switch is a handheld device which can be placed virtually anywhere in the house, it is operated with 3 AAA batteries, and has been tested from a range of approximately 50 feet without loss of signal. These characteristics cause the device to fall well into the constraints of the project.

The Wireless Remote Kill Switch operates on the principle of Radio Frequency (RF) communication. The signal that is transmitted is sent using a frequency of 433.92 MHz. This is an unregulated frequency and therefore does not interfere with TV and Internet signals, which use a regulated frequency.

33

Figure 26 - Wireless Receiver Circuit

The figure above shows the placement of the receiver circuit (circled in yellow) inside the alarm clock itself. The circuits employ the use of a basic TWS 434A FM transmitter and a basic RWS 434 FM receiver. This transmitter/receiver pair is able to transmit over a distance of 400 feet (outdoors) and 200 feet (indoors). This allows the remote switch to be placed up to 200 feet away from the alarm clock unit and still be able to function properly. 200

34

feet is an acceptable distance for the design since few houses are 200 feet on one dimension. The transmitter and receiver circuits employ the use of an encoder and decoder, respectively. The encoder (HT-12E) translates the signal going into the transmitter (from the user pushing the remote kill switch) into a four bit digital signal. This makes the signal less susceptible to interference. The decoder (HT12D in the receiver circuit) then translates this signal back to a simple on/off signal that can be interpreted easily by the PIC. The pseudo code for the Wireless Remote Kill Switch is given below in Pseudo Code 5.

When Time = Alarm and Snooze = On or Off, or Remote Kill = On 1. Lamp = Off (output 0 V to all lamp relays) 2. Buzzer = Off (drive Buzzer output to 0 mA) 3. Start Timer2 for 15 min to monitor bed for heat on current alarm setting 4. Reset system for monitoring

Pseudo Code 5 Wireless Remote Kill Switch (KP)

The circuits used for the Transmitter and Receiver design are given in Figure 27 and Figure 28, respectively. These circuits were found at http://www.rentron.com/rf_remote_control.htm as typical circuits for common RF communications. 35

Figure 27 Wireless Remote Kill Switch Transmitter Schematic (KP)

The transmitter circuit provided by Renton was used as it is above. Pins 1 through eight are address pins used to identify each transmitter that may be using the same frequency. Since the goal of this device is only to communicate one momentary button push, D0 is the only input pin used. In order for the device to only consume power while the button is pushed, pins D0 and TE (transmit enable) are tied together. Otherwise, the transmitter would continue to use power even when the button is not pushed. This is an undesirable effect because the battery would not last very long.

The receiver circuit (below, also found at rentron.com) is utilized slightly differently than intended by this diagram. In the circuit below, the output used is D0. However, the output pins on the decoder have a latching mechanism, which was not desirable for our application. The decoder does, however, have a Valid Transmission pin (VT pin 17.) This pin is typically used to light an LED or some other indicator to signify that the receiver has received the transmission in a format understandable. This pin provides a 5 VDC high signal only when the input to the transmitter is present (in our case, the remote kill button is pushed.) This pin provides the PIC with a simple 5 VDC 36

high signal to signify that the remote kill switch has been pushed, and the user is out of bed.

Figure 28 Wireless Kill Switch Receiver Schematic (KP)

37

Piezoelectric Buzzer (KP)

Figure 29 - Piezoelectric Buzzer

One way the Smart Alarm Clock wakes the sleeper is with the use of a piezoelectric buzzer. The uniqueness of this design is that this buzzer is turned on to 3 levels of loudness corresponding to the different stages of the alarm. When the alarm clock first reaches the preset alarm time, the unit enters Alarm Stage zero. This corresponds to a low-level buzzer and low-level lighting. If the snooze button is pressed, the Alarm Stage is incremented by one, and after a snooze period, the alarm begins to wake the user with a medium level buzzer and medium level lighting. If the snooze button is pressed again, the Alarm Stage is increments by one again. After another

38

snooze period, the alarm attempts to wake the user with a high intensity buzzer and high intensity lighting.

These three stages of the alarm make it necessary to have a buzzer that has three levels of intensity. This is accomplished by having 3 separate outputs from the PIC going to the buzzer. At each level of Alarm Stage, a different output pin is energized. Each of these pins has a different voltage divider circuit before reaching the buzzer. The pin corresponding to the third Alarm Stage does not have a voltage divider circuit at all. The circuit below is a diagram of the buzzer voltage divider network.

Figure 30 - Buzzer Staging Pspice Schematic (KP)

The pin corresponding to the second Alarm Stage has a voltage divider circuit, which drops the voltage to the buzzer to 75% of the full voltage. The pin corresponding to the first Alarm Stage has a voltage divider circuit, which reduces the voltage going to the buzzer to 50% of the full output voltage of the PIC. These different levels of voltage

39

going to the buzzer give different levels of loudness. The purpose of the diodes in the voltage divider network is to isolate each voltage divider from each other since they are all tied to the same input point on the buzzer itself. If the diodes are not in place as shown, resistances in the other legs of the network will influence the resistance to ground seen by the buzzer.

40

Pseudo code for the piezoelectric buzzer is given below in Pseudo Code 6.

When Time = Alarm setting and Heat sensor < X 1. Quick Buzzer and Lamp When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = Off 2. Buzzer = Low (drive Buzzer output to 12.5 mA) When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = On 1. Buzzer = Off (drive Buzzer output to 0 mA) When Time = Alarm setting and Heat sensor > X and Snooze = On 1. Buzzer = Off (drive Buzzer output to 0 mA) 2. Timer1 = t seconds, Then Goto iii When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = Off 3. Buzzer = Medium (drive Buzzer output to 18.75 mA) When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = On 1. Buzzer = Off (drive Buzzer output to 0 mA) When Time = Alarm setting and Heat sensor > X and Snooze = On 1. Buzzer = Off (drive Buzzer output to 0 mA) Timer1 = t seconds, Then Goto iv When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = Off 1. Buzzer = High (drive Buzzer output to 25 mA) When Time = Alarm setting and Heat sensor > X and Snooze = Off and Remote Kill = On 1. Buzzer = Off (drive Buzzer output to 0 mA) Snooze = On When Time = Alarm setting and Heat sensor > X and 1. Buzzer = High (drive Buzzer output to 25 mA) 2. Alternative Designs?? (sound system, shocker, etc) When Time = Alarm setting and Heat sensor < X and Snooze = On or Off, or Remote Kill = On 5. Buzzer = Off (drive Buzzer output to 0 mA) 6. Start Timer2 for 15 min to monitor bed for heat on current alarm setting 7. Reset system for monitoring

Pseudo Code 6 Piezoelectric Buzzer (KP)

41

Lighting Control (KP)

Figure 31 - Backside of Alarm Clock, Lamp Outlet

Another means of waking the user that the Smart Alarm Cock uses is controlled lighting. As can be seen from Figure 47 Program Flowchart, when the alarm clock first reaches the preset alarm time, the unit enters Alarm Stage zero. This corresponds to a low level lighting. If the snooze button is pressed, the Alarm Stage is incremented by one, and after a snooze period, the alarm begins to wake the user with medium level lighting. If the snooze button is pressed again, the Alarm Stage is increments by one again. After another snooze period, the alarm attempts to wake the user with high intensity lighting.

42

These three stages of the alarm make it necessary to have a lighting that has three levels of intensity. This is accomplished by using a dimmer circuit found in many household touch lamps. The triac in the circuit is used as a switch to open and close the path to the lamp. A 555 timer controls this switch. This circuit works by chopping the incoming voltage waveform. The triac closes the circuit to the lamp until the 555 timer switches it open. If a lower intensity light is desired, the incoming waveform is chopped early (lets say between 0 and 90 degrees.) If a higher (but not full strength) light intensity is desired, the incoming waveform is chopped later (say between 90 degrees and 180 degrees.) If a full intensity light is desired, the waveform is not chopped at all and the full waveform is allowed to pass to the lamp.

Figure 32 - Lamp Pspice Schematic (KP)

In household touch lamps, the signal to change intensities of the light is a simple touch of the lamp chassis. The lamp chassis is connected electrically to the dimmer circuit. Each time the lamp is touched, the circuit notices a small change in the

43

capacitance seen to ground. The circuit then knows to increment to the next stage of light intensity. This signal has to be simulated in order to use this principle for our design. Instead of the capacitance change being caused by a person touching the lamp, a relay is connected to the dimmer circuit. This relay is connected to the input that is normally connected to the chassis of the lamp, and to ground. When the level of light is wanted to be incremented, this capacitance signal relay is closed and the circuit notices a slight change in the capacitance seen to ground (the capacitance of the wire going to ground was enough of a capacitance change for the circuit to notice) and the light intensity is incremented. The other relay in the circuit is simply a power relay to control when 120 VAC can be available to the outlet. This power relay has a coil, which is operated by 5VDC. However, the relay uses approximately 500 mA of current when energized. This means that the power relay cannot be driven by the PIC itself since the PIC can only source 25 mA. So the power relay was switch by using a TIP31 transistor in which the base is biased by the PIC, and the 5VDC rail instead of the PIC sourced the 500 mA. The same is done with the relay used for the fan motor and the coffee maker relay. The capacitance relay used to increment the intensity of light is a considerably smaller relay and could be driven straight from the PIC.

There are two outlets mounted in the alarm clock unit. These outlets are controlled by the electromechanical relays described above. One is for the lamp, and one is for the coffee maker (described in the next section.) One of the design parameters is that any off the shelf lamp and coffee maker can be plugged into the alarm clock and the functionality of the system would be the same.

44

Pseudo code for Lighting Control is given below in Pseudo Code 7.

Alarm Stage = 0 When Alarm Stage = 0, Time = Alarm setting and FSR sensor < X 1. No Alarm reset for next day When Alarm Stage = 0, Time = Alarm setting, FSR sensor > X, Snooze = Off, & Remote Kill = Off 1. Lamp = Low (output 5 VDC to power relay and close capacitance relay once) When Alarm Stage = 0, Time = Alarm setting, FSR sensor > X, Snooze = Off, and Remote Kill = On 1. Lamp = Off (output 0 V to all lamp relays) 2. Timer 2 = timing for 30 minutes (see Figure 2) When Alarm Stage = 0, Time = Alarm setting, FSR sensor > X, and Snooze = On 1. Lamp = Low 2. Timer 1 =timing for snooze interval, then next stage 3. Alarm Stage = Alarm Stage + 1 When Alarm Stage = 1, Time = Alarm setting, FSR sensor > X, Snooze = Off, and Remote Kill = Off 1. Lamp = Medium (momentary output 5 VDC to capacitance relay) When Alarm Stage = 1, Time = Alarm setting, FSR sensor > X, Snooze = Off, and Remote Kill = On 1. Lamp = Off 2. Timer 2 = timing for 30 minutes (see Figure 2) When Alarm Stage = 1, Time = Alarm setting,FSR sensor > X, and Snooze = On 1. Lamp = Medium 2. Timer 1 =timing for snooze interval, then next stage 3. Alarm Stage = Alarm Stage + 1 When Alarm Stage = 2, Time = Alarm setting, FSR sensor > X, Snooze = Off, and Remote Kill = Off 1. Lamp = High (momentary output 5 VDC to capacitance relay) When Alarm Stage = 2, Time = Alarm setting, FSR sensor > X, Snooze = Off, and Remote Kill = On 1. Lamp = Off 2. Timer 2 = timing for 30 minutes (see Figure 2) When Alarm Stage = 2, Time = Alarm setting, FSR sensor > X, Snooze = On 45

1. Lamp = High
Pseudo Code 7 Lighting Control (KP)

46

Coffee Maker (KP)

Figure 33 - Backside of Alarm Clock, Coffee Outlet

Another means of waking the user is through the users sense of smell. The unit has another outlet mounted on it where the user can plug in a coffee maker. Any generic coffee maker can be connected. All the user has to do is plug in their coffee maker and switch the on switch (on the coffee maker itself to the on position. The outlet is controlled by the PIC so it will only be energized when the timing sequence is ready for it to be on. As can be seen from Figure 47 Program Flowchart, 5 minutes before the alarm first goes off, the unit energizes the Coffee Maker relay coil. A schematic of the Coffee Maker Operation is given below in Figure 34.

47

Figure 34 Coffee Maker Pspice Schematic (KP)

As can be seen from above, the relay for the coffee maker draws a larger amount of current than the PIC can source, so the use of a TIP31 to switch the relay on is employed (similar to the lamp power relay.)

Figure 35 - Lamp and Coffee Maker

48

5 minutes before the alarm goes off, the Coffee Maker Relay is energized and begins the brewing process. The coffee maker is turned on 5 minutes before the alarm goes off to ensure that at the time of the alarm, the aroma of coffee is in the air and is smelled by the user. This, in theory, brings the user out of sleep in a better attitude because the aroma of coffee is soothing. The Coffee Maker Relay is energized and kept energized for 10 minutes. After 10 minutes the Coffee Maker Relay is de-energized because the brewing process should be over by this time. Pseudo code for the Coffee Maker is given below in Pseudo Code 8. When Time = Alarm setting and FSR sensor > X, Snooze = Off, and Remote Kill = Off 1. Coffee = On (output 5 VDC to Coffee Relay) When Time = Alarm setting and FSR sensor > X, Snooze = Off, and Remote Kill = On 1. Coffee = On (output 5 VDC to Coffee Relay)

Pseudo Code 8 Coffee Maker (KP)

49

Supply Power (KP)

Figure 36 - Power Supply

The input power to the Smart Alarm Clock is accomplished using a standard power supply for a computer. This supply is plugged straight into a wall outlet and provides an output of 5 VDC, and 12 VDC. 5 VDC is needed to power the PIC, buzzer, receiver, and other peripherals. 12 VDC is needed to power the DC fan motor. 120 VAC is supplied by tapping off the 120 VAC soldering joints on the computer power supply. This is needed for the lamp and coffee maker.

50

Figure 37 - Power Supply and Battery Backup Pspice Schematic (KP)

Fusing In order to address safety issues, the circuits involving 120 VAC are fused. The coffee maker circuit is fused using a 10 A fuse and the lamp is fused using a 1 A fuse. The coffee maker circuit is also protected in that the outlet into which the coffee maker is plugged is a GFCI. The National Electric Code (NEC) requires GFCIs wherever water is present. Since the coffee maker is going to be near the alarm, and water is poured into the coffee maker, the use of a GFCI seemed to be warranted.

51

Liquid Crystal Display and Controller (JR)

The design specifications for the Smart Sensory Alarm Clock states that the display must be larger than five inches by two inches, easy to read, able to display the time in an AM/PM format and finally display custom messages. In order to do this it was determined that a graphic LCD is needed since a character LCD does not meet the size requirements. However, due to some unforeseen circumstances we in fact decided to use an alphanumeric display. The display we ended up using is a four line alphanumeric display with an adjustable contrast and brightness made by Optrex. In order to adjust both the contrast and brightness we used two separate adjustable pots that we used to fine tune the display. We were able to make this display work better than we thought by custom designing all of the numbers so that they were in fact three lines rather than one line which made the display very easy to read. See Figure 38 below for a physical example of this unit. Each of the custom numbers was made from one of eight custom characters that were stored in the LCD memory upon initialization. Figure 39 shows how each of the numbers were created as well as the individual characters that were created.

Figure 38 - LCD Display

52

Figure 39 - Custom Number Generation

In order for the PIC microcontroller to communicate with the alphanumeric LCD a separate controller is needed. This particular LCD uses the HD44780U controller. This controller is interfaced with the microcontroller with the following sixteen connections; eight data lines, VSS, VDD, RS, R/W, E, Vo and power and ground to control the backlight. With this controller the graphic LCD will satisfy all of the design requirements.

53

Software Design The main component of the smart alarm clock is the microcontroller. Every piece of hardware interacts and is controlled by the microcontroller. Figure 47 shows the complete program flowchart. As one can see when power is first supplied the first thing that is done is that the alarm clock must be calibrated with the sensors. Figure 48 is a logical flowchart of the steps taken to complete the calibration. First off, the alphanumeric display needs to be initialized. This is done by calling the initLCD command which is a function that consists of the correct commands and delays needed to be sent to the LCD controller in order to make the LCD work. Once the screen is initialized the user must set the sensitivity all the way to the right and then press enter as indicated in the following screenshot; Figure 40. The value shown is then stored in memory as the threshold for whether or not someone is occupying the bed.

Figure 40 - Calibrating Screen Shot

After the sensor is calibrated, the control is returned from the Calibration Flow Chart back to the Program Flowchart. The next set of code that is ran is a check to see if the user would like to run a simple demo program in order to test all of the components of

54

the alarm clock. Figure 41 shows the two options the user may choose. If in fact the demo program is selected, pressing the wireless kill switch tests each piece of hardware. After each press of the kill switch the next piece of hardware is turned on or the intensity level is changed. Once all of the hardware has been tested the control is returned back to the main alarm clock program is indicated in the Program Flowchart.

Figure 41 - Demo Choice Mode

The next step in the Program Flowchart is the actual initialization of the alarm clock itself. This simply requires the user to enter in a valid time before anything else can take place. Figure 47 is a flowchart of the code used to initialize the alarm clock time and Pseudo Code 9 was developed from this flowchart. Figure 42 shows the initialized screen, which actually blinks when in operation.

55

Figure 42 - Initialed Screen

Now that the time has been correctly set the most important role of the microprocessor, the actual clock operation, has now begun. In order to do this the microcontroller will simply use an interrupt service routine with a timer that is synchronized with the 4MHz crystal that drives the internal clock. For our particular program timer1 has been set up to trigger an interrupt every 50 milliseconds. The interrupt service routine simply keeps track of the time by incrementing variables that hold the milliseconds, seconds, minutes and hours at the appropriate times. After each second code must be executed so that the time is displayed correctly. Also, at this time the alarm is running in what is known as alarm stage 0.

Continuing on in the Program Flowchart now that the time has been set up correctly the user may now either enter an alarm time or change the time if it was entered incorrectly. The following Figure 43 is a screenshot of the LCD when the alarm is being set.

56

Figure 43 - Enter Alarm Screenshot

After the alarm has been set the program must determine at what time to turn on the coffee maker as well as when to disable the ability the change either the current time or the time the alarm has been set for. As a group we decided that the coffee maker should turn on ten minutes prior to the alarm going off. However, if no on is in bed at that time the coffee maker will not turn on. Another choice we made was that once the current time has reached one hour before the alarm is set to go off the user can no longer change the current time or disable the alarm. This eliminates the user from simply waking up a few minutes early and simply turning off the alarm or trying to change the time so that the alarm will not go off. The following Figure 44 is a screenshot of the LCD when the alarm has been set. One added feature we were able to add was the ability to display the time the alarm has been set for as well as the current time.

57

Figure 44 - Alarm Set Screenshot

Continuing on in the Program Flowchart when the current time reaches the time that the alarm has been set for the analog to digital conversion subroutine is called to determine whether or not the bed is currently occupied. If the bed is not occupied the alarm automatically goes to stage 4 where a 30 minute timer is started in which the bed is continuously monitored. If the bed is in fact occupied the code jumps into alarm stage 1. Here the light is turned on low as well as the buzzer. Also, a seven-minute timer has been activated and when it has expired the alarm will move onto stage 2. The use of the snooze button is allowed and if pressed it will simply disable the buzzer for the rest of the remaining time during stage 1. In order to turn off the alarm clock the user MUST press the wireless kill switch. If at any time during stages one through three the kill switch is pressed, the alarm will go to stage 4 where all the components are turned off and a 30 minute timers starts as stated before. Once the timer has expired the alarm code will continue on to stage 2 where another timer is set for 7 minutes, the light is turned on to medium and the buzzer gets slightly louder. The snooze button and wireless kill switch work exactly the same as in stage one. Again when the timer expires the alarm stage will

58

increment again this time to alarm stage 3. When alarm stage 3 has been reached the fan is now turned on, the buzzer and light are now on in their brightest and loudest mode and the snooze button no longer works as it did before. Now if the user tries to push the snooze button they will receive a slight shock and none of the peripheral components will be affected. The following Figure 45 is a screenshot of the LCD during the first stage after the snooze button has been pressed. As one can see all of this information is displayed to the user so that they know exactly what state the alarm is in. The 7 after the word SNOOZE is the time left on the timer until the alarm increments to the next stage.

Figure 45 - Alarm Stage Set Screenshot

As stated previously, once the wireless kill switch is pressed the alarm will go to stage 4 in which a 30-minute timer is started. During this time the bed is continuously checked to determine if the user has returned to occupy the bed. If someone has in fact returned to bed the alarm will automatically go to stage 3 with all the components turning back on. With the program control we are certain there is no way to defeat our alarm clock short of unplugging it and also unscrewing the case and removing the battery. The following Figure 46 is a picture of the LCD once the alarm is in stage 4. The message at

59

the bottom simply shows how much longer the alarm will stay at that stage before resetting for the next day.

Figure 46 - Alarm Stage 4 Monitoring

60

ALARM CLOCK CALIBRATION

ALARM CLOCK INITIALIZATIO

Input ? NO

YES

Set Alarm or Time

YES

DEMO ?

NO

NO

1 Hr before Alarm YES

DEMO PROGRA

Alarm = Time

10 mins before turn on Coffee maker

STAGE = 1

NO

Body Present

YES

STAGE = 4

Stage 0 Stage 1
Timer = 7 Min Light = Low SNOOZE NO Timer Expired YES STAGE = YES Buzze r = off NO Kill Switch YES STAGE = NO

Alarm Stage Switch Stage 2

Stage 4
Timer = 30 Min Light = Off Buzzer = Off SHOCK = Off YES STAGE =

Stage 3

NO

Body Present
NO Timer Expired

YES STAGE =

Timer = 7 Min Light = Med Buzze r = off NO YES

SNOOZE NO

Timer = 7 Min Light = High Buzzer = High

WAIT FOR KILL SWITCH

Kill Switch YES STAGE =

NO

Timer Expired YES STAGE =

STAGE =

Figure 47 - Program Flowchart

61

Alarm Clock Calibration

Power Supplied

Initialize Display

Clear Variables

Prompt User to calibrate Wait for Input

YES

ENTER ?

NO

Update memory

Alarm Clock PROGRAM Figure 48 - Alarm Clock Calibration Flowchart

62

Clear Variables

Prompt User

Wait for Input

SWITCH STRUCTURE DEFAULT AM/PM NUMBER ENTER CANCEL

Toggle AM/PM Wait( 2 seconds) Update memory and display

Show Error MSG

YES

Valid time ?

NO

Set Time and enable interrupts

Code to handle Alarm stages, timing as well as any device I/O.


Figure 49 - Alarm Initialization Flowchart

63

* Start of main program initDisplay() // see figure 1 // Alarm clock is powered up, either for first time or after power outage and no/dead battery. // Clock either flashes 12:00 am or displays a message stating that the time needs to be set. while ( freshStart = TRUE) { freshStart = FALSE; // used to control cancel button clearAllVariables(); // reset all variables enterTimeMSG() // Prompt user to enter time while( wait4Input() ) ; // wait until a key is pressed

while ( exitTimeset == FALSE ) { switch ( keyInput){ case CANCEL: freshStart = TRUE; // reset and start over break; case AMPM: toggle(); break;

// toggle AM / PM of the time being set

case NUMBER: // accept number input and shift all numbers left digit3 = digit2; digit2 = digit1; digit1 = digit0; digit0 = keypadInput; // update display break; case ENTER: // determine if the time entered is valid if ( validateTime() = TRUE ){ // set the time; exitTimeset = TRUE; // exit the timesetting loop // enable interrupts; } else { // print an error message; freshStart = TRUE; // reset and start over } break; default:

64

// ignore alarm set and time set buttons break; } // end of switch structure } // end of TimeSet Loop } // end of freshStart while loop
Pseudo Code 9 PIC Pseudo Code for Initializing Alarm

65

Testing Procedures

Hardware testing were completed first to ensure that the components themselves were functioning correctly independently (without the PIC.) The components were powered manually to ensure that the basic operation of the components is as specified by the manufacturer. The second method of testing was the testing of the components when integrated with the PIC. If the components are functioning correctly independent of the PIC, then malfunction when integrated with the PIC, the problem can be located in the software rather than in the hardware.

Wireless Remote Kill Switch (KP)

The remote kill switch was tested independently of the system by applying power to the transmitter and receiver, pushing the kill switch button (see Figure 27 Wireless Remote Kill Switch Transmitter Circuit) and monitoring the voltage of pin VT (see Figure 28 Wireless Remote Kill Switch Receiver Circuit.) If for each time the kill switch button is pressed, a voltage is measured at pin VT, then the wireless system is functioning properly. The remote kill switch was then tested while integrated with the system by pushing the kill switch button during every possible moment during the alarm cycle and seeing if the buzzer and lighting turn off. If this is the case, the Wireless Remote Kill Switch is functioning properly. After the remote kill switch is pressed, the sensors monitoring the bed are monitoring the bed for 30 minutes. If during this time, the sensors detect the presence of a body, the lamp and buzzer should come back on at full strength.

66

Piezoelectric Buzzer (KP)

The buzzer was tested independently of the system by simply applying different DC voltages to the buzzer. Since the different stages of the alarm system will be applying 5 volts, 3.75 volts, and 2.5 volts, these are the voltages were used. If the volume of the buzzer differs when different voltages are applied, the buzzer is functioning correctly.

Lighting Control (KP)

Lighting control was tested independently by setting up the dimmer circuit with the capacitance lead attached to the capacitance relay. If the capacitance relay is momentarily closed and the light intensity increases for each momentary closure, the dimmer circuit is functioning properly. The dimmer circuit was then connected to the GFCI and the power relay and capacitance relay were integrated with the PIC. When the signal was sent from the PIC to trigger the appropriate relays, the light level increased for each momentary closure of the capacitance relay. This meant that the dimmer circuit was functioning properly.

67

Coffee Maker (KP)

The coffee maker was tested independently by simply plugging it into the wall. If the coffee maker begins to brew when switched on, it is functioning properly. The coffee maker was then tested while integrated with the system by plugging it into the outlets mounted on the alarm clock unit. The control relay was connected to the PIC through the TIP31 transistor, and the output was made high by means of software code. If the coffee maker begins to brew 5 minutes before the alarm is set to go off, it is functioning properly. The outlet should also be de-energized 10 minutes after being energized.

Keypad (BM)

Powering up the encoder circuit and integrated keypad with 5V DC while probing the 4 individual output pins for high and low voltages occurred first. Each of the buttons were tested for their corresponding digital number assignments and displayed on the digital oscilloscope channels 1-4. This determined the exact expected digital inputs to the PIC. Multiple key press schemes were also introduced to view how shorts are interpreted, and the corresponding row currents were found to be minimal, unaffecting system power performance. Software interpretation of the keys was fairly straightforward.

68

Force Sensing Resistors (BM)

Changes in the output voltage of the parallel resistor network correspond to changes in weight distributed across the bed. Simple laboratory measurements were done including placing various objects of known weight on the force sensing resistors while measuring the corresponding change in output voltage. The system was calibrated for a standard 190-pound person as a test subject. Software code was then programmed with the calculated threshold value at 190 pounds. Testing included two people standing on test frame rig, as well as one person. The tests were all run with the sensors at various ranges to ensure that the bodys presence was interpreted correctly.

Snooze Button (BM)

Starting with small voltages applied to the shock circuit via potentiometers and a breadboard, output currents were measured to ensure hazardous conditions are not met (i.e. currents of no more than 1mA). Once the circuit was operating according to reasonable output currents, (i.e. enough of a level of pain was determined as suitable), the mechanical snooze button was mounted and soldered up.

69

DC Motor / Fan Mechanism (BM)

The DC motor operations will be the first design to test. Verification of maximum output voltage applied to the motor will be necessary to make sure overloads do not burn the motor. The output of the PIC driver voltage needs to be simulated by applying 12V DC to the motor driver circuit, which is again the TIP31A switched to a 16A relay. It was found that 1A was the tested start up and running current drawn by the motor at 12V DC. This was deemed acceptable for the components, and not much to cause concern for overheating. Conditions were verified to ensure the system didnt generated high torques, and precautions were taken to avoid contact of the fan blades with any part of the electrical circuitry. Testing of air strength at target distances of 3 feet proved feasible by skin sensation.

70

Financial Budget

The Electrical Engineering Department set the team financial budget. The hourly rate per team member is $10.00 and the total cost is determined for a 15-week semester. The final cost for labor can be seen in Table 1. The Electrical and Engineering Department also set a budget for the materials for this project, which is $100 per team member.

Design Team Member Brad Morse Karl Pilz Josh Runtas

Hourly Rate $10.00 $10.00 $10.00

Hours/Week

Weeks/Semester

Estimated Cost $1500 $1500 $1500 $4,500

10 10 10 Total Labor Cost:


Table 1 Estimated Labor Cost

15 15 15

The final budget changed from the initial budget estimate as changes were made along the way. Upon review of the actual part purchased, it was determined that if more generic parts were purchased, the overall system cost could be reduced to around $120. The final budget detail sheet and parts list can be seen in Table 2.

71

Table 2 Material Budget Sheet

72

Project Schedule

The Smart Sensory Alarm Clock design team constructed a timeline that was to keep them on task to reach their ultimate goal of completing this project. The implementation taken place during the Spring 2006 semester anticipated for 10 hours per week for 15 weeks. This estimate proved very close to the actual timeline. The following figures, Figure 50 and Figure 51, are detailed Gantt Charts of how this project was accomplished.

73

Figure 50 Implementation Gantt Chart Breakdown

74

Figure 51 Implementation Gantt Chart Timeline

75

Design Team Information

Name Brad Morse Karl Pilz Josh Runtas

Address 406 Sumner St Apt A3 4391 Cottage Grove Rd PO box 934 Akron OH 44309

Phone 330-212-3327 330-268-4876 330-219-2134

Email Bam12@uakron.edu Kjp9@uakron.edu Jdr8@uakron.edu

Major Electrical Engineer Electrical Engineer Computer Engineer

Table 3 Design Team Information

76

Conclusions and Recommendations

The overall design of the Smart Alarm Clock System contains numerous peripheral devices that all came together to stimulate cognitive learning for the user. Design recommendations for future alarm clock projects would include choosing fewer elements to implement. The amount of time required for each individual part is limited due to focusing on other areas of interest. Also, when problems arise with a particular part, that part is usually put on hold to work on another component, making it difficult to focus on the overall design.

In the end, it was also decided not to go with some redundant and electrically unsafe devices. This reduced the overall complexity and cost, and saved the team some much needed construction time. The largest problem that the Smart Alarm Clock team faced was keeping our grounds insulated. There was an instance in testing where a ground shorted across the +5V DC bus, frying a small portion of the main PCB. Steps were taken to ensure that all grounds were away from 5V DC busses, and insulated properly.

In conclusion, the final product will replace out-dated alarm clocks by stimulating the senses in an automated fashion. Depending on whether the user still occupies the bed or not determines the reaction from the alarm clock. Gentle stages will entice the user to wake up promptly, where the later stages will make them think twice the next day. The team is confident in the concepts and designs described in this report, and proudly stand behind our completely tested product.

77

Senior Design Team 7 Smart Alarm Clock

78

References

1. Peatman, John B. Embedded Design with the PIC18F452 Microcontroller. Prentice Hall. (2003)

79

Appendix A Software Coding

80

DM2023
// DM2023.c FILE #include <pic18.h> #include <conio.h> extern void msDelay(unsigned int); extern void usDelay(unsigned int); void LCDcmd(unsigned char cmd){ RE0=0; //enter command mode RE2=0; //write mode PORTD=cmd; //write high nibble RE1=1; asm("nop"); asm("nop"); RE1=0; //pulse enable if(cmd > 4) { usDelay(40); //wait > 37 microseconds most commands } else msDelay(2); //wait > 2 milliseconds for return home // BFwait(); RE0=1; //return to charcater mode return; } void LCDchar(unsigned char datum){ RE0=1; //enter character mode RE2=0; //write mode asm("nop"); asm("nop"); PORTD=datum; //write character RE1=1;asm("nop");asm("nop");RE1=0; //pulse enable usDelay(37); //wait > 37 microseconds for all characters return; }

void LCDinit(unsigned char configADC ){ // ADCON1=configADC; //configure ADC PORTD=0b00000000; //clear PORTD TRISD=0b00000000; //D7 to D0 as output PORTE=0b11111000; //Read, Command, E low TRISE=0b11101000; //General Purpose I/O Mode, E2 to E0 as output msDelay(100); //wait for more than 15 msecond for LCD controller to reset on power up LCDcmd(0b00111000); //set in 8-bit mode msDelay(6); //wait for more than 4.1 msec LCDcmd(0b00111000); //set in 8-bit mode usDelay(150); //wait for more than 100 usec LCDcmd(0b00111000); //set in 8-bit mode LCDcmd(0b00111000); //set two lines, 5x8 characters LCDcmd(0b00001000); //set display off, cursor off, blink off LCDcmd(0b00000001); //clear diplay

81

LCDcmd(0b00001111); LCDcmd(0b00000110); LCDcmd(0b00001100); return; }

//set display on, cursor on, blink on //enter increment and move cursor mode // turn off cursur and blink

void putch(char ch){ static char lineNumber=1; asm("nop"); if(ch == '\r'){ if(lineNumber==1){ LCDcmd(0x80); return; } else { LCDcmd(0xC0); return; } } if(ch == '\n'){ if(lineNumber==1){ lineNumber=2; LCDcmd(0xC0); return; } else { lineNumber=1; LCDcmd(0x80); return; } } LCDchar(ch); }

//Deal with carriage return //Start of line 1

//Start of line 2

//Deal with newline //Shift lines //Start of line 2

//Shift lines //Start of line 1

82

loadCR
//loadCR.c FILE #include <pic18.h> extern void LCDcmd(unsigned char); extern void LCDchar(unsigned char);

const char CG_ROM1[8][8] = {{ //User Character 0 0B11111, 0B11111, 0B11111, 0B11111}, { //User Character 1 0B11111, 0B11111, 0B11111, 0B00000}, { //User Character 2 0B00000, 0B00000, 0B11111, 0B11111}, { //User Character 3 0B00000, 0B00000, 0B11111, 0B00000}, { //User Character 4 0B00000, 0B00000, 0B00000, 0B11111}, { //User Character 5 0B11111, 0B11111, 0B11111, 0B00000}, { //User Character 6 0B11111, 0B11111, 0B00000, 0B11111}, { //User Character 7 0B00000, 0B00000, 0B00000, 0B00000}};

0B11111, 0B11111, 0B11111, 0B11111,

0B11111, 0B00000, 0B00000, 0B00000,

0B11111, 0B11111, 0B11111, 0B11111,

0B11111, 0B11111, 0B11111, 0B00000,

0B00000, 0B11111, 0B11111, 0B11111,

0B11111, 0B11111, 0B11111, 0B00000,

0B00000, 0B00000, 0B00000, 0B11111,

0B00000, 0B00000, 0B00000, 0B00000,

void loadCGRAM1(void){ char row1; char character1; for(character1 = 0; character1 < 8; character1++) for(row1 = 0;row1 < 8;row1++){ LCDcmd(0x40+row1+8*character1); //set CG address LCDchar(CG_ROM1[character1][row1]); } }

83

Main
//main.h FILE #ifndef MAIN_H #define MAIN_H #define #define #define #define THIRTY 30 SEVEN 7 ONE 1 TWO 2

char snoozeChoice; char timer30Choice; void demoProgram(void); extern void msDelay(unsigned int); extern void usDelay(unsigned int); extern char getkey(void); extern char setTime(char); extern extern extern extern void void void void LCDcmd(unsigned char); LCDchar(unsigned char); LCDinit(unsigned char); putch(char);

extern void loadCGRAM1(void); extern extern extern extern extern extern extern extern extern extern extern extern void char void void void void void void void char void void void void void void void void void void void void printOne(char); printTwo(char); printThree(char); printFour(char); printFive(char); printSix(char); printSeven(char); printEight(char); printNine(char); printZero(char); printColon(char); printTime(char, char);

printUpdateTime(void); enterTimePressed(char); enterAlarmPressed(void); enableAlarmPressed(void); stageZero(void); stageOne(void); stageTwo(void); stageThree(void); stageFour(void); bedStatus(void);

void calibrateSensors(void); char sensorThreshold; char KEY;

84

char char char char char char char char char void

exitStart = FALSE; alarmSet = FALSE; alarmEnabled = FALSE; SNOOZEtmp = FALSE; coffeeON = FALSE; minsCoffee; hoursCoffee; ampmCoffee; jumpCoffeeTime; jumpCoffee(void);

char char void void char char char char

milHoursRTC; milHoursAlarm; inputDisable(void); setDisableTime(void); disableInput; minsDisable; hoursDisable; ampmDisable;

char stageVar; char lightStage = 0; int ADCnew = 0; int r = 0; #endif

85

printTime
//printTime.c FILE #include <pic18.h> extern void LCDcmd(unsigned char); extern void putch(char); void printOne(char start1){ LCDcmd((0x80 | start1)); putch((char)1); putch((char)0); putch((char)7); LCDcmd((0x80 | (0x040 + start1))); putch((char)7); putch((char)0); putch((char)7); LCDcmd((0x80 | (0x14 + start1))); putch((char)4); putch((char)0); putch((char)4); } void printTwo(char start2){ LCDcmd((0x80 | start2)); putch((char)5); putch((char)5); putch((char)0); LCDcmd((0x80 | (0x40 + start2))); putch((char)2); putch((char)3); putch((char)5); LCDcmd((0x80 | (0x014 + start2))); putch((char)0); putch((char)2); putch((char)2); } void printThree(char start3){ LCDcmd((0x80 | start3)); putch((char)5); putch((char)5); putch((char)0); LCDcmd((0x80 | (0x40 + start3))); putch((char)7); putch((char)3); putch((char)0);

86

LCDcmd((0x80 | (0x014 + start3))); putch((char)2); putch((char)2); putch((char)0); } void printFour(char start4){ LCDcmd((0x80 | start4)); putch((char)0); putch((char)7); putch((char)0); LCDcmd((0x80 | (0x40 + start4))); putch((char)0); putch((char)0); putch((char)0); LCDcmd((0x80 | (0x014 + start4))); putch((char)7); putch((char)7); putch((char)0); } void printFive(char start5){ LCDcmd((0x80 | start5)); putch((char)0); putch((char)5); putch((char)5); LCDcmd((0x80 | (0x40 + start5))); putch((char)5); putch((char)3); putch((char)2); LCDcmd((0x80 | (0x014 + start5))); putch((char)2); putch((char)2); putch((char)0); } void printSix(char start6){ LCDcmd((0x80 | start6)); putch((char)0); putch((char)7); putch((char)7); LCDcmd((0x80 | (0x40 + start6))); putch((char)0); putch((char)1); putch((char)0); LCDcmd((0x80 | (0x014 + start6))); putch((char)0);

87

putch((char)4); putch((char)0); } void printSeven(char start7){ LCDcmd((0x80 | start7)); putch((char)0); putch((char)0); putch((char)0); LCDcmd((0x80 | (0x40 + start7))); putch((char)7); putch((char)7); putch((char)0); LCDcmd((0x80 | (0x014 + start7))); putch((char)7); putch((char)7); putch((char)0); } void printEight(char start8){ LCDcmd((0x80 | start8)); putch((char)0); putch((char)1); putch((char)0); LCDcmd((0x80 | (0x40 + start8))); putch((char)0); putch((char)3); putch((char)0); LCDcmd((0x80 | (0x014 + start8))); putch((char)0); putch((char)4); putch((char)0); } void printNine(char start9){ LCDcmd((0x80 | start9)); putch((char)0); putch((char)1); putch((char)0); LCDcmd((0x80 | (0x40 + start9))); putch((char)0); putch((char)4); putch((char)0); LCDcmd((0x80 | (0x014 + start9))); putch((char)7); putch((char)7); putch((char)0); }

88

void printZero(char start0){ LCDcmd((0x80 | start0)); putch((char)0); putch((char)1); putch((char)0); LCDcmd((0x80 | (0x40 + start0))); putch((char)0); putch((char)7); putch((char)0); LCDcmd((0x80 | (0x014 + start0))); putch((char)0); putch((char)4); putch((char)0); } void printColon(char startColon){ LCDcmd((0x80 | startColon)); putch((char)7); putch((char)4); putch((char)7); LCDcmd((0x80 | (0x40 + startColon))); putch((char)7); putch((char)6); putch((char)7); LCDcmd((0x80 | (0x014 + startColon))); putch((char)7); putch((char)1); putch((char)7); }

void printTime(char num, char pos){ switch (num){ case 0: // print 0 printZero(pos); break; case 1: // print 1 printOne(pos); break; case 2: // print 2 printTwo(pos); break; case 3: // print 3 printThree(pos); break; case 4: // print 4 printFour(pos); break; case 5: // print 5

89

printFive(pos); break; case 6: // print 6 printSix(pos); break; case 7: // print 7 printSeven(pos); break; case 8: // print 8 printEight(pos); break; case 9: // print 9 printNine(pos); break; default: // do nothing break; } return; }

90

RTC
//RTC.h FILE #ifndef RTC_H #define RTC_H #define #define #define #define #define TRUE 0xFF FALSE 0x00 AM 0x00 PM 0xFF NOBUTTON 0xFF unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned char secsRTC; char minsRTC; char hoursRTC; int daysRTC; char semaphoreRTC; char millsecsRTC; char ampmRTC; char updateTime;

extern extern extern extern extern extern extern extern

extern unsigned char SNOOZE; extern unsigned char snoozeTime; extern unsigned char snoozeElapsed; extern unsigned char timer30; extern unsigned char timer30Time; extern unsigned char timer30Elapsed; extern unsigned char hoursAlarm; extern unsigned char minsAlarm; extern unsigned char ampmAlarm; void initRTC(void); void interrupt isrRTC(void); #endif

91

usDelay
//usDelay.c FILE #include <pic18.h> void usDelay(unsigned int count){ unsigned int outer; for(outer=0; outer < count/32; outer++){ }

92

setTime
//setTime.c FILE #include <pic18.h> #include <stdio.h> #include "RTC.h" extern extern extern extern extern extern extern void void void void char void void msDelay(unsigned int); usDelay(unsigned int); LCDcmd(unsigned int); putch(char); getkey(void); printTime(char, char); printColon(char);

char checkTime(void); void printInput(void); char AMPM; char digits[4]; char value; char setTime(char choice){ LCDcmd(0b10100110); printf(" "); if (choice == 2){ digits[3] = digits[2] = digits[1] = digits[0] = AMPM = AM; }else{ digits[3] = }

hoursAlarm / 10; hoursAlarm % 10; minsAlarm / 10; hoursAlarm %10;

digits[2] = digits[1]=digits[0]=0;

printInput(); while(1){ value = NOBUTTON; while ( value == NOBUTTON ) value = getkey(); if ( value < 10 ) { digits[3] = digits[2]; digits[2] = digits[1]; digits[1] = digits[0]; digits[0] = value; printInput(); } else { switch (value){ case 10: // AM/PM if ( AMPM == AM)

93

AMPM = PM; else AMPM = AM; printInput(); break; case 11: //Cancel digits[3] = 0; digits[2] = 0; digits[1] = 0; digits[0] = 0; AMPM = AM; return FALSE; case 15: // ENTER // check valid time if (checkTime() == FALSE ) { LCDcmd(0b11010100); printf("ERROR! RE-ENTER TIME"); LCDcmd((unsigned char)0xC0); //Turn off cursor break; } // if valid set appropriate variables and return if (choice == 1){ // set the time hoursRTC = digits[3]*10 + digits[2]; minsRTC = digits[1]*10 + digits[0]; ampmRTC = AMPM; secsRTC = 0; return TRUE; } else { // set the alarm hoursAlarm = digits[3]*10 + digits[2]; minsAlarm = digits[1]*10 + digits[0]; ampmAlarm = AMPM; return TRUE; } default: // do nothing break; } } } return FALSE; } // SHOULDN'T REACH HERE

void printInput(void){ printTime(digits[3],0); printTime(digits[2],4); printColon(7); printTime(digits[1],10); printTime(digits[0],14); if ( AMPM == AM){

94

LCDcmd(0b11010010); printf("AM"); LCDcmd(0b10010010); printf(" "); }else{ LCDcmd(0b10010010); printf("PM"); LCDcmd(0b11010010); printf(" "); } LCDcmd((unsigned char)0xC0); } char checkTime(void){ if ( ( digits[3] > 1 ) || ( digits[1] > 5 ) ) return FALSE; if ( ( digits[3] == 1 ) && ( digits[2] > 2 ) ) return FALSE; if ( ( digits[3] == 0 ) && ( digits[2] == 0 ) ) return FALSE; return TRUE; } //Turn off cursor

95

msDelay
//msDelay.c FILE #include <pic18.h> #define IMAX 165 void msDelay(unsigned int count){ unsigned int outer; unsigned char inner; for(outer=0; outer < count; outer++){ for(inner=0;inner<IMAX;inner++) asm("nop"); }

96

GetKey
//getkey.c FILE #include <pic18.h> #include <stdio.h> extern extern extern extern extern void void void void void msDelay(unsigned int); usDelay(unsigned int); InitLCD(void); cmdLCD(unsigned int); putch(unsigned char);

char retKey; char col; char row; char getkey(void){ /* Configure PORTB */ TRISB = 0b11110000; PORTB = 0b00000000; RBPU = 0; col = 0x0F; /*Scan all four rows */ for ( row = 0; row < 4; row++ ) { switch ( row ) { case 0: PORTB = 0b11111110; break; case 1: PORTB = 0b11111101; break; case 2: PORTB = 0b11111011; break; default: PORTB = 0b11110111; break; } // msDelay(10); col = PORTB >> 4; if ( col!= 0x0F) break; } // End of for loop

// Columns Inputs, Rows Outputs // clear PORTB // Enable weak pull-ups

/* check if a key was pressed */ if (col == 0x0F) return 0xFF; /* Determine which key was pressed and return */ msDelay(2); col = col & 0x0F; switch ( col ) { case 0x0E:

97

retKey break; case 0x0D: retKey break; case 0x0B: retKey break; default: retKey break; }

= 0;

= 1;

= 2;

= 3;

retKey = retKey + row*4; /* wait for key release */ while( ( PORTB & 0xF0 ) != 0xF0 ); msDelay(10); return (retKey);

98

Appendix B Datasheets

The following are the datasheets used in the design of the Smart Sensory Alarm Clock. The following datasheets were used and included in the design:

Microchip PIC18F8525 Microprocessor Data Sheet (selected pages) Philips Semiconductor SE555 Timer Phidgets USA Force Sensing Resistor Reynolds Electronics TWS-434/RWS-434 Wireless transceiver combo pack Piezoelectronic Products Buzzer Panasonic JS Power Relay Panasonic HY Relay Optrex DMC2048 LCD

99

101

You might also like