Telephone Remote System - EECS Senior Design Project
Transcription
Telephone Remote System - EECS Senior Design Project
Telephone Remote System Control Your Home Appliances Miles Away Senior Design Project Documentation Winter 2007 EECS 129B Professor Raymond Klefstad By Shao-Lin Chen Mingruey Lee Sam Lee ABSTRACT This documentation is a comprehensive guideline of Telephone Remote System, a home automation device. It provides information of how to build, test and use the system. The system consists of two devices; one being the master device and the other being the slave device. The master device takes commands through DTMF signals from incoming telephone. If the command is valid, master then issues command to slave device through wireless communication protocol to turn on/off appliances attached to the slave device. TABLE OF CONTENTS Figure 1 – Overview 3....................................................................................................................2 Figure 2 – CM8870 Conversion Table 4.......................................................................................2 Figure 3 – Master front and power 6...........................................................................................2 Figure 4 – Master zigbee and phone jack 6.................................................................................2 Figure 5 – Slave front and power 7..............................................................................................2 Figure 6 – Slave 4 relay outputs 7................................................................................................2 Figure 7 – Slave device on top of master device 7.......................................................................2 Figure 8 – Master device system level diagram 8........................................................................2 Figure 9 – Actual master device circuits 8...................................................................................2 Figure 10 – Slave device system level diagram 9.........................................................................2 Figure 11 – Actual slave device circuits 9....................................................................................2 Figure 12 – Ring Detection Circuit (M1) 10................................................................................3 Figure 13 – Pick Up circuit (M2) 10.............................................................................................3 Figure 14 – DTMF Decoder circuit (M3) 11................................................................................3 Figure 15 – ZigBee Wireless circuit (M4 & S1) 11......................................................................3 Figure 16 – Relay Control circuit (S2) 12....................................................................................3 Figure 17 – Master flow chart 13.................................................................................................3 Figure 18 – Slave float chart 14....................................................................................................3 TABLE OF FIGURES Figure 1 – Overview.......................................................................................................................4 Figure 2 – CM8870 Conversion Table..........................................................................................5 Figure 3 – Master front and power..............................................................................................6 Figure 4 – Master zigbee and phone jack....................................................................................6 Figure 5 – Slave front and power.................................................................................................7 Figure 6 – Slave 4 relay outputs...................................................................................................7 Figure 7 – Slave device on top of master device..........................................................................7 Figure 8 – Master device system level diagram...........................................................................8 Figure 9 – Actual master device circuits......................................................................................8 Figure 10 – Slave device system level diagram............................................................................9 Figure 11 – Actual slave device circuits.......................................................................................9 EECS129B Telephone Remote System Page 2 Figure 12 – Ring Detection Circuit (M1)...................................................................................10 Figure 13 – Pick Up circuit (M2)................................................................................................10 Figure 14 – DTMF Decoder circuit (M3)...................................................................................11 Figure 15 – ZigBee Wireless circuit (M4 & S1).........................................................................11 Figure 16 – Relay Control circuit (S2).......................................................................................12 Figure 17 – Master flow chart....................................................................................................13 Figure 18 – Slave float chart.......................................................................................................14 PURPOSE Our senior design project is inspired by a simple, yet convenient idea of using telephone as remote control to switch on/off electronic devices. With such intention in mind, we are to design and implement a dynamic central command unit, which decodes the DFMF signals from incoming telephone calls, and uses the decoded information to remote control on/off stage of electronic devices. EECS129B Telephone Remote System Page 3 Figure 1 – Overview FEATURES A master device that picks up user’s phone call and allows user to enter commands wherever and whenever, as long as a phone call is picked up successfully. With a valid command, master device can signal slave device to turn on/off up to four electronic devices. The slave device is wireless connected to the master device via ZigBee, which allows a more versatile positioning of our master and slave devices. After hanging up the call, the system is reset and ready for the next incoming call. BACKGROUND The most essential part of our system is the audio DTMF decoder (CM8870). Without it, our design will not be able to detect commands from telephone calls. First of all, what is a DTMF signal? Dual-tone multi-frequency (DTMF) is a tone signal used for telephone signaling over the line in the voice-frequency band. The version of DTMF used for telephone tone dialing is known by the trademarked term “Touch-Tone” and is a EECS129B Telephone Remote System Page 4 standardized telecommunication median. As a result, any functional “Touch-Tone” phone should generate the identical DTMF tones specified for all 12 buttons on a standard touch-tone phone. The DTMF decoder, as suggested by its name, is used to detect and decode received touch in a telephone call, i.e. when you press a number button while you are on a phone, you can hear the sound of the button you press, the DTMF decoder will detect such valid tone and decodes it into a unique4-bit binary number (Figure 2). This 4-bit binary number will be output to the master, and the program will verify the sequence of numbers to determine if the input is a valid command. KEY 1 2 3 4 5 6 7 8 9 0 * # TOW H H H H H H H H H H H H Q4 0 0 0 0 0 0 0 1 1 1 1 1 Q3 0 0 0 1 1 1 1 0 0 0 0 1 Q2 0 1 1 0 0 1 1 0 0 1 1 0 Q1 1 0 1 0 1 0 1 0 1 0 1 0 Figure 2 – CM8870 Conversion Table Another important component in the telephone remote control system is ZigBee. ZigBee uses low-power digital radios based on IEEE 802.15.4 standard for wireless personal area networks (WPANs), and it allows wireless connection between the master and slave devices. As a result, slave device can be placed anywhere within the range of ZigBee connection, therefore create a more user friendly and convenient infrastructure of our system. SYSTEM CONFIGURATION The whole system is separated into two devices: master device and slave device, each with its own power source and indicators. 1. Master Configuration The master device contains the circuits to detect and pick up an incoming phone call and a DTMF decoder to decode commands. In a way, the master device is very similar to an EECS129B Telephone Remote System Page 5 answering machine. The master device automatically picks up a phone call after 3 rings. After the phone is picked up, the user will be able to enter command to the master device. The commands are to be decoded and send to slave device through ZigBee if valid. When master device is powered up, the StandBy LED (red) indicates that the device is in standby mode and is ready to accept any incoming call. When there is an incoming call, the Ring LED (green) provides feedback on whether or not the phone is ringing. After the call is picked up, then the Connected LED (green) is on. If the entered command is valid, the Command LED (yellow) will flash. Input: 9V power Output: ZigBee signal RJ-11 phone jack Figure 3 – Master front and power 2. Figure 4 – Master zigbee and phone jack Slave Configuration The slave device consists of ZigBee to accept commands. If a command is valid, then the slave device can turn either device 1, 2, 3, 4 or all on/off using on board circuit to control relays. When slave device is powered up, the StandBy LED (red) indicates that the device is in standby mode and is ready to accept any signals from master device. The four LEDs numbered 1, 2, 3 and 4 are used to indicate whether or not the corresponding relays are on. EECS129B Telephone Remote System Page 6 Input: 9V power Output: 4 relay outputs ZigBee signals Figure 5 – Slave front and power Figure 6 – Slave 4 relay outputs Figure 7 – Slave device on top of master device SYSTEM LEVEL DIAGRAMS 1. Master System Level EECS129B Telephone Remote System Page 7 Figure 8 – Master device system level diagram When there is an incoming call, the Ring Detect Module (M1) detects rings and provides feedback to Arduino. Once 3 rings are detected, Arduino tells Hook on/off Module (M2) answers the call. Once the call is connected, DTMF Decoder Module (M3) decodes any DTMF signal from the call. Once a valid input is detected, Arduino sends the action signal to slave device with ZigBee Module (M4). Figure 9 – Actual master device circuits 2. Slave System Level EECS129B Telephone Remote System Page 8 Figure 10 – Slave device system level diagram Once the slave device receives the action signal from the master device, it will respond to it by turning on/off either device 1, 2, 3, 4 or all. The output devices’ on and off states are indicated by their own LED lights. Figure 11 – Actual slave device circuits CIRCUIT LEVEL DIAGRAMS EECS129B Telephone Remote System Page 9 1. Ring Detection Circuit (M1) Figure 12 – Ring Detection Circuit (M1) Ring Detect Circuit (M1): When the circuit is in idle state, the voltage between collector and emitter is 5V. Once the phone rings, the voltage will drop to 3.7V. Measurement of this voltage change can be used to detect how many rings occur on the phone before the system activates Switch Hook Module. The LED indicates ringing. 2. Pick Up Circuit (M2) Figure 13 – Pick Up circuit (M2) Pick Up Circuit (M2): This module is used to pick up an incoming call. When a phone is not in use, the voltage across the phone line is 50V; when this voltage drops to around 36V, the phone picks up. This circuit is used to provide such load to the phone line causing it to pick up, and is controlled by the Arduino’s digital pin2. By default, pin2 is set to High, and when it switches to Low, it activates the load circuit, causing the voltage to drop to 36V and the phone picks up. 3. DTMF Decoder Circuit (M3) EECS129B Telephone Remote System Page 10 Figure 14 – DTMF Decoder circuit (M3) DTMF Decoder Circuit (M3): This circuit contains an essential chip for our project. The CM8870 chip is capable of decoding analog DTMF signal into binary signal for numeric recognition. The output of this chip is the combination of Q1 – Q4, and the combination can be defined by the Arduino program to indicate numbers for the corresponding phone keys. 4. ZigBee Wireless Circuit (M4 & S1) Figure 15 – ZigBee Wireless circuit (M4 & S1) EECS129B Telephone Remote System Page 11 ZigBee Wireless Circuit (M4 & S1): This module is adapted from one of 129A lab assignment last quarter, and is a very convenient component for wireless data transmission. By adding ZigBee Module to both our master and slave device, the two can communicate with each other in wireless connection, which improves the versatility of our project. 5. Relay Control Circuit (S2) Figure 16 – Relay Control circuit (S2) Relay Control Circuit (S2): This component basically reacts to the input from the master device and switch on the appliances that are connected to it. By default, all relays are open and the appliances are turned off. By responding to the input, the relay will close the switch to turn on the connected appliances. SOFTWARE DESCRIPTION EECS129B Telephone Remote System Page 12 1. Master Software Figure 17 – Master flow chart The software of master device follows the above simple flow chart. When the power is on, the device is in Ready stage. Whenever there is an incoming call, the device picks up and enters Pick Up stage. During Pick Up stage, the device is ready for decoding commands. If the command is valid, a signal is send to slave device. Otherwise, it will go back to Pick Up stage. If user hangs up the call, the device will go back to Ready stage. The full source code of master device is included in Appendix A in page 19. 2. Slave Software EECS129B Telephone Remote System Page 13 Figure 18 – Slave float chart The software of slave device follows the above simple flow chart. When the power is on, the device is in Ready stage. Whenever there is a valid signal from Zigbee, the slave turns on /off either device 1, 2, 3, 4, or all. After performing an action, the slave device goes back to Ready stage. The full source code of master device is included in Appendix B in page 24. TESTING PLAN 1. System test plan: EECS129B Telephone Remote System Page 14 1. Plug in power for both master and slave devices. 2. Connect the master device to a working phone jack. It is preferable using a splitter to connect a working phone with it. 3. Call the number of that phone. 4. After 3 rings, the master device will pick up the call. 5. When the call is connected, one can enter command from his or her touchtone phone pad. 6. Dial 10 to turn on, 11 to turn off slave device 1. 7. Dial 20 to turn on, 22 to turn off slave device 2. 8. Dial 30 to turn on, 31 to turn off slave device 3. 9. Dial 40 to turn on, 41 to turn off slave device 4. 10. Dial 00 to turn on, 01 to turn off slave device 1, 2, 3 and 4. 11. Dial any other numbers will result in an invalid command. 12. Dial ## to tell the master device to hang up the phone. 13. If no key is pressed, the master should hang up by itself after 35 seconds of idling. 2. Individual module testing: Master: 1. Ring Detect Circuit (M1): Connect this module to a working phone jack. Measure the voltage between the collector node and emitter node. This module is function properly if we can see the voltage drop from 5V to 3.7V each time a ring occurs. 2. Pick Up Circuit (M2): Connect this module to a working phone jack. Short pin2 of LCA110 and call the number. If the phone is picked up automatically then this device is functioning correctly. 3. DTMF Decoder Circuit (M3): Connect this module to a working phone jack and to the Arduino board. When a phone call is picked up, test the decoder by pressing each number key as well as the # and * key to see if the input is decoded correctly. 4. ZigBee wireless Circuit (M4): To test ZigBee’s wireless connection, we must configure the master Arduino to send test signal through it to the slave Arduino. If a signal is sent EECS129B Telephone Remote System Page 15 and successfully received by the slave Zigbee, the signal should be read by the slave Arduino and output on the PC programmer. Slave: 1. ZigBee wireless Circuit (S1): This can be tested together with the master Zigbee module. 2. Relay Control Circuit (S2): Use Arduino digital pin2 to pin5 to send the device control signals to the relays. If the signals are High, relays will switch from NC to NO, and the circuits are connected, indicating by the LED lights. Once the signal becomes Low, the relays will switch back to NC, and the circuits are disconnected. COST ANALYSIS MASTER Resistors 1/4W Carbon Film 56 100 Quantity 1 1 EECS129B Telephone Remote System Total Price $0.05 $0.05 Part Number 56-1/4 100-1/4 Vendor All Electronics All Electronics Page 16 820 2.2k 10k 22k 47k 100k 300k Capacitors .1uf ceramic 10nf metallized polyester 120nf metallized polyester 330nf polyester film 1uf electrolytic 4.7uf electrolytic IC Chips CM8870 (DTMF decoder) 4N25 LCA110 74HC245 74LVC245 Zigbee crystal oscillator 3.5795mHz Semiconductor W02M (bridge rectifier) MPSA42 MJE340 1N4004 (diode) Others 150LA10 (MOV) phone jack RJ-11 power regulator 5V-3.3V Coupling transformer 600:600 LED Programmer Arduino USB Atmega8 1 1 2 1 4 2 1 $0.05 $0.05 $0.10 $0.05 $0.20 $0.10 $0.05 820-1/4 2.2K-1/4 10K-1/4 22K-1/4 47K-1/4 100K-1/4 300K-1/4 All Electronics All Electronics All Electronics All Electronics All Electronics All Electronics All Electronics 2 2 1 1 2 1 $0.16 $0.34 $0.22 $0.40 $1.00 $0.50 1109PHCT-ND 495-1097-ND 478-2250-ND BC1782-ND 4062PHCT-ND 4065PHCT-ND Digi-Key Digi-Key Digi-Key Digi-Key Digi-Key Digi-Key 1 1 1 1 1 1 1 $1.30 $0.50 $2.30 $0.58 $0.60 $23.20 $3.00 M-8870-01-ND 4N25MFS-ND CLA101-ND 568-1423-5-ND 296-8503-5-ND XB24-AWI-001-ND 300-7007-1-ND Digi-Key Digi-Key Digi-Key Digi-Key Digi-Key Digi-Key Digi-Key 1 1 1 1 $0.61 $0.29 $0.72 $0.26 W02G/1GI-ND MPSA42FS-ND 497-2624-5-ND 1N4004DICT-ND Digi-Key Digi-Key Digi-Key Digi-Key 1 1 1 1 4 $0.22 $0.65 $0.77 $1.00 $0.60 150LA10 MT-64 497-1491-5-ND TCX-2 LED-2 Digi-Key All Electronics Digi-Key All Electronics All Electronics 1 $31.95 Arduino-USB Sparkfun Sum of Master 1 $71.27 Quantity 7 1 Total Price $0.35 $0.05 Part Number 1K-1/4 10K-1/4 Vendor All Electronics All Electronics 1 1 1 $0.58 $0.60 $23.20 568-1423-5-ND 296-8503-5-ND XB24-AWI-001-ND Digi-Key Digi-Key Digi-Key SLAVE Resistors 0.25W Carbon Film 1k 10k IC Chips 74HC245 74LVC245 Zigbee EECS129B Telephone Remote System Page 17 ULN2003A Others relay LED Programmer Arduino USB Atmega168 1 $0.95 97-2344-5-ND Digi-Key 4 5 $6.52 $0.75 PB892-ND LED-2 Digi-Key All Electronics 1 $31.95 Arduino-USB Sparkfun Sum of Slave 1 $64.95 Master + Slave Sum 1 $136.82 SUMMARY Overall we accomplished our project with success and gained a lot of experiences in circuit design as well as telecommunication technology. In the beginning, we had no prior knowledge of how telephone worked. It was through an extensive research and study before we understood the concept behind it and to begin the schematic design, purchasing parts and actually implementing the circuits. Throughout the project development process, we encountered one technical issue. The first issue was to connect an auto reset circuit to our master device. The circuit was designed to detect the voltage change when users hanged up the call and used it to reset the master device. However, when we implemented the circuit into the master device, it somehow altered the standby voltage of the phone line, causing it to pick up even without any incoming call. Worse, the circuit redirected currents into the Arduino board, causing it to constantly overheat and finally broke the Arduino board. In the end, we abandoned the idea and programmed the microcontroller using software reset to solve this issue. Nevertheless, the development process was smooth and we accomplished most of our goal, that our system could pick up a phone call and allow the caller to control up to four different appliances with few touches on the keypad, which was pretty interesting experience when we tested it. APPENDIX A – Master Software Source Code //--------PIN DECLARE---------// int ringDetectPin = 0; int q1 = 1; int q2 = 2; int q3 = 3; int q4 = 4; int TOW = 5; EECS129B Telephone Remote System Page 18 int hook = 2; int redled = 3; int greenled = 4; int yellowed = 5; //////////////////////////////// //---------VARIABLES----------// int ringDetectVal = 0; int q1val = 0; int q2val = 0; int q3val = 0; int q4val = 0; int TOWval = 0; int key = 0; int ringConstant = 0; int timeStamp = 100000; int hangUpVal = 0; int command = 0; int commandLength = 2; //////////////////////////////// void setup() { Serial.begin(9600); pinMode(greenled, OUTPUT); pinMode(redled, OUTPUT); pinMode(yellowled, OUTPUT); pinMode(hook, OUTPUT); digitalWrite(hook, HIGH); Serial.print("+++"); delay(1100); //hook is set to off (hangs up) //Zigbee setup begins if (returnedOK() == 'T'){} else{ setup();} Serial.println("ATID1234,CN"); if (returnedOK() == 'T'){} else{ setup();} digitalWrite(greenled, LOW); digitalWrite(yellowled, LOW); digitalWrite(redled, HIGH); void loop() { ringDetectVal = 1024 - analogRead(ringDetectPin); if (ringDetectVal > 100) { ringConstant = ringConstant + 1; } EECS129B Telephone Remote System //Detect ring Page 19 while (ringDetectVal > 100) //Wait here until next ring { ringDetectVal = 1024 - analogRead(ringDetectPin); } if (ringConstant > 117) //If rings for 3 times, picks up the phone { pickUp(); digitalWrite(greenled, LOW); digitalWrite(redled, HIGH); digitalWrite(hook, HIGH); ringConstant = 0; } } //-----------PICKUP-----------// void pickUp() { digitalWrite(greenled, HIGH); digitalWrite(redled, LOW); digitalWrite(hook, LOW); hangUpVal = 1; //hangUpVal = 0 will hangs up the phone while(hangUpVal == 1) { TOWval = getDigital(analogRead(TOW)); if (TOWval == 1) //Read TOW, if TOW=1, a tone is detected { timeStamp = 100000; // q1val q2val q3val q4val = = = = getDigital(analogRead(q1)); getDigital(analogRead(q2)); getDigital(analogRead(q3)); getDigital(analogRead(q4)); key = q1val + 2 * q2val + 4 * q3val + 8 * q4val; if (key key = if (key key = == 11) 13; == 10) 0; command = command * 10; command = command + key; commandLength = commandLength - 1; if (commandLength == 0) //A command is entered { if (command == 10) { Serial.println("10"); digitalWrite(yellowled, HIGH); delay(200); digitalWrite(yellowled, LOW); EECS129B Telephone Remote System Page 20 } else if (command == 11) { Serial.println("11"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 20) { Serial.println("20"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 21) { Serial.println("21"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 30) { Serial.println("30"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 31) { Serial.println("31"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 40) { Serial.println("40"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 41) { Serial.println("41"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, } else if (command == 0) { Serial.println("0"); digitalWrite(yellowled, delay(200); digitalWrite(yellowled, EECS129B HIGH); LOW); HIGH); LOW); HIGH); LOW); HIGH); LOW); HIGH); LOW); HIGH); LOW); HIGH); LOW); HIGH); LOW); Telephone Remote System Page 21 } else if (command == 1) { Serial.println("1"); digitalWrite(yellowled, HIGH); delay(200); digitalWrite(yellowled, LOW); } else if (command == 132) //command = ## { hangUpVal = 0; } else //command is invalid { digitalWrite(redled, HIGH); delay(200); digitalWrite(redled, LOW); } } } commandLength = 2; command = 0; while (TOWval == 1) //Wait here until next dialing tone { TOWval = getDigital(analogRead(TOW)); } timeStamp = timeStamp - 1; if (timeStamp == 0) //If idle for more than 35 seconds, hangs up { timeStamp = 100000; hangUpVal = 0; } } } //////////////////////////////// //--------AtoDConvert---------// int getDigital(int analog) { if (analog > 1000) return 1; else return 0; } //////////////////////////////// //--------ZigBee helper--------// char returnedOK () { // this function checks the response on the serial port to see if it was an "OK" or not char incomingChar[3]; EECS129B Telephone Remote System Page 22 char okString[] = "OK"; char result = 'n'; int startTime = millis(); while (millis() - startTime < 2000 && result == 'n') { // use a timeout of 10 seconds if (Serial.available() > 1) { // read three incoming bytes which should be "O", "K", and a linefeed: for (int i=0; i<3; i++) { incomingChar[i] = Serial.read(); } if ( strstr(incomingChar, okString) != NULL ) { // check to see if the respose is "OK" //if (incomingChar[0] == 'O' && incomingChar[1] == 'K') { // check to see if the first two characters are "OK" result = 'T'; // return T if "OK" was the response } else { result = 'F'; // otherwise return F } } } return result; } //////////////////////////////// APPENDIX B – Slave Software Source Code //---------Pin Declare--------// int ledPin = 13; int device1 = 5; int device2 = 4; int device3 = 3; int device4 = 2; int led1 = 6; int led2 = 7; int led3 = 8; EECS129B Telephone Remote System Page 23 int led4 = 9; //////////////////////////////// //----------Variables---------// byte inByte = 0; byte names[] ={'0', '1', '2', '3', '4', '5', '6', '7'}; int tones[] = {0, 1, 2, 3, 4, 5, 6, 7}; int val = 0; int count = 0; int command = 0; //////////////////////////////// void setup() { pinMode(ledPin, OUTPUT); pinMode(device1, OUTPUT); pinMode(device2, OUTPUT); pinMode(device3, OUTPUT); pinMode(device4, OUTPUT); pinMode(led1, pinMode(led2, pinMode(led3, pinMode(led4, OUTPUT); OUTPUT); OUTPUT); OUTPUT); digitalWrite(device1, digitalWrite(device2, digitalWrite(device3, digitalWrite(device4, digitalWrite(led1, digitalWrite(led2, digitalWrite(led3, digitalWrite(led4, LOW); LOW); LOW); LOW); LOW); LOW); LOW); LOW); Serial.begin(9600); Serial.print("+++"); delay(1100); //ZigBee setup if (returnedOK() == 'T'){} else{ setup();} Serial.println("ATID1234,CN"); if (returnedOK() == 'T'){} else{ setup();} digitalWrite(ledPin, HIGH); //Device is ready } void loop() { if (Serial.available() > 1) { EECS129B Telephone Remote System Page 24 inByte = Serial.read(); int end = inByte; if (end != 13) //End of line is not met { for (count=0;count<=8;count++) { if (names[count] == inByte) { command = command * 10; command = command + tones[count]; } } } else { if (command == 11) { digitalWrite(device1, HIGH); digitalWrite(led1, HIGH); } else if (command == 10) { digitalWrite(device1, LOW); digitalWrite(led1, LOW); } else if (command == 21) { digitalWrite(device2, HIGH); digitalWrite(led2, HIGH); } else if (command == 20) { digitalWrite(device2, LOW); digitalWrite(led2, LOW); } else if (command == 31) { digitalWrite(device3, HIGH); digitalWrite(led3, HIGH); } else if (command == 30) { digitalWrite(device3, LOW); digitalWrite(led3, LOW); } else if (command == 41) { digitalWrite(device4, HIGH); digitalWrite(led4, HIGH); } else if (command == 40) { digitalWrite(device4, LOW); digitalWrite(led4, LOW); } EECS129B Telephone Remote System Page 25 else if (command == 1) { digitalWrite(device1, digitalWrite(device2, digitalWrite(device3, digitalWrite(device4, digitalWrite(led1, digitalWrite(led2, digitalWrite(led3, digitalWrite(led4, HIGH); HIGH); HIGH); HIGH); } else if (command == 0) { digitalWrite(device1, digitalWrite(device2, digitalWrite(device3, digitalWrite(device4, digitalWrite(led1, digitalWrite(led2, digitalWrite(led3, digitalWrite(led4, } } } command = 0; HIGH); HIGH); HIGH); HIGH); LOW); LOW); LOW); LOW); LOW); LOW); LOW); LOW); } //--------ZigBee helper--------// char returnedOK () { // this function checks the response on the serial port to see if it was an "OK" or not char incomingChar[3]; char okString[] = "OK"; char result = 'n'; int startTime = millis(); while (millis() - startTime < 2000 && result == 'n') { // use a timeout of 10 seconds if (Serial.available() > 1) { // read three incoming bytes which should be "O", "K", and a linefeed: for (int i=0; i<3; i++) { incomingChar[i] = Serial.read(); } if ( strstr(incomingChar, okString) != NULL ) { // check to see if the respose is "OK" //if (incomingChar[0] == 'O' && incomingChar[1] == 'K') { // check to see if the first two characters are "OK" result = 'T'; // return T if "OK" was the response } else { result = 'F'; // otherwise return F } } } return result; EECS129B Telephone Remote System Page 26 } //////////////////////////////// EECS129B Telephone Remote System Page 27 APPENDIX C – Full Size Diagrams EECS129B Telephone Remote System Page 28 EECS129B Telephone Remote System Page 29 EECS129B Telephone Remote System Page 30 EECS129B Telephone Remote System Page 31 EECS129B Telephone Remote System Page 32 Master EECS129B Slave Telephone Remote System Page 33