microcontroller remote controlling project

40
DTMF BASED REMOTE CONTROLLING OF HOME APPLIANCES USING MOBILE PHONE A project for the partial fulfillment of requirements for the B.Sc.(Honors) degree. Project Supervisor Farhana Binte Sufi Lecturer Department of Applied Physics & Electronic Engineering University of Rajshahi Submitted by Roll no.-09034939 Registration no.-1701 Session 2008-2009

Upload: bipro-roy

Post on 06-May-2015

5.721 views

Category:

Education


6 download

DESCRIPTION

Microcontroller based remote controlling project using mobile phone. with implementing this u can remotely control ur home appliances like fan, light, tv even industrial machines through a mobile phone being in a long distance.

TRANSCRIPT

Page 1: Microcontroller  remote controlling project

DTMF BASED REMOTE CONTROLLING OF HOME APPLIANCES USING MOBILE

PHONE

A project for the partial fulfillment of requirements for the B.Sc.(Honors) degree.

Project SupervisorFarhana Binte Sufi

LecturerDepartment of Applied Physics & Electronic Engineering

University of Rajshahi

Submitted byRoll no.-09034939

Registration no.-1701Session 2008-2009

Page 2: Microcontroller  remote controlling project

CERTIFICATION

This is to certify that the project “DTMF BASED REMOTE CONTROLLING OF

HOME APPLIANCES USING MOBILE PHONE” has been carried out by examinee Roll: 09034939, Session: 2008-09 under my supervision for the B.Sc. (Hons.) Part-IV Examination-2012.

The examinee has completed the project in due time and successfully.

FARHANA BINTE SUFI

LecturerDept. Of Applied Physics and

Electronic EngineeringUniversity of Rajshahi

Rajshai-6205

Page 3: Microcontroller  remote controlling project

ACKNOWLADGEMENT I would like to take this opportunity to express my deepest sense of gratitude and respect to my honorable teacher & project supervisor “ Farhana Binte Sufi “ , Lecturer , Department of Applied Physics & Electronic Engineering, University of Rajshahi, who guided me in this project and help me in every stage where any difficulty comes. And she has given me valuable suggestions on the development of my project and suggested me to prepare this project paper.

I am also thankful to Professor A.B. Md. Ismail, Chairman, Department of Applied Physics & Electronic Engineering, University of Rajshahi, for his kindness in providing me access to the seminar library, internet connections and lab facilities. My heartiest thank to all my respectable teachers, and my classmates for providing moral support and encouragement to enhance my knowledge on Microcontroller.

Foremost and finally, it is generosity and guidance of Almighty God to honor me with power and persistence to get this work done.

Bipro Roy Chanchal

Date: 17/11/2012 The Author

Page 4: Microcontroller  remote controlling project

CONTENTS

page

1. Introduction…………………………………………………………. 012. DTMF Basics……………………………………………………….. 023. Decoder Description………………………………………………… 054. ATMega 16 Microcontroller……………………………………....... 075. Design Basics…………………………………………………………116. Implementation & Discussion………………………………………..157. Conclusion………………………………………………………........168. Appendix……………………………………………………………..179. Reference…………………………………………………………….. 23

Page 5: Microcontroller  remote controlling project

ABSTRACT

The project demonstrates a novel method which enables users to control their home appliances and systems for remotely using a cell phone-based interface. To access the control unit, the user should send an authentication code Dual Tone Multi Frequency along with the required function to his/her home control system via Global System for Mobile communication (GSM) . Upon being properly authenticated, the cell phone-based interface at home (control unit) would relay the commands to a microcontroller that would perform the required function.

Four mobile keypad buttons generate four different DTMF signals at input which is sent to the mobile at output section via GSM. Then the signal is transferred to a Microcontroller. Microcontroller output is used to make active or inactive two magnetic relays for four different state (i.e. keypad button 2 is used make two relays idle. Keypad button 4 is used to make one relay one and so on.)

Page 6: Microcontroller  remote controlling project

DEDICATED

TO

MY

PARENTS

Page 7: Microcontroller  remote controlling project

INTRODUCTION

The remote control technologies have been used in the fields like factory automation, space exploration, in places where human access is difficult. As this has been achieved in the domestic systems partially, many corporations and laboratories are researching the methods which enable human to control and monitor efficiently and easily in the house or outdoor. Controlling the domestic system regardless of time and space is an important challenge. As the mobile phone enables us to connect with the outside devices via mobile communication network regardless of time and space, the mobile phone is a suitable device to control domestic systems. [1]

This project proposes a method to control a domestic system using a mobile phone, irrespective of the phone model and mobile phone carrier. The system suggested consists of the mobile phone normally registered in communication service and a mobile phone that can receive a call from another phone. Existing methods for control and monitoring, using mobile phones have usage problems because the cost and need for continuous control. One of the disadvantage, being the lack of feedback during the process. This paper proposes to solve the problems of existing methods of control that use simple voice call. Method proposed uses the DTMF (Dual Tone Multi Frequency) generated when a keypad button of the mobile phone is pressed by the user. The mobile phone user controls the system by sending the DTMF tone to the access point. Mobile communication network coverage is larger than that of LANs, thus user can take advantage of mobile phones to control the system.

Page 8: Microcontroller  remote controlling project

DTMF BASICS

DTMF is a generic communication term for touch tone (a Registered Trademark of AT&T). The tones produced when dialing on the keypad on the phone could be used to represent the digits, and a separate tone is used for each digit. However, there is always a chance that a random sound will be on the same frequency which will trip up the system. It was suggested that if two tones were used to represent a digit, the likelihood of a false signal occurring is ruled out. This is the basis of using dual tone in DTMF communication.[2] DTMF dialing uses a keypad with 12/16 buttons. Each key pressed on the phone generates two tones with specific frequencies, so a voice or a random signal cannot imitate the tones. One tone is generated from a high frequency group of tones and the other from low frequency group.[2]

The frequencies generated on pressing different phone keys are shown in the Table 1.

Table 1 – Frequencies generated on Key presses [3]

Button Low Frequency(Hz)

HighFrequency(Hz)

1 697 12092 697 13363 697 14774 770 12095 770 13366 770 14777 852 12098 852 13369 852 14770 941 1209* 941 1336# 941 1477

Each row and column of the keypad corresponds to a certain tone and creates a specific frequency. Each button lies at the intersection of the two tones as shown in Table 2.

Page 9: Microcontroller  remote controlling project

Table 2 – Row and Column Frequency Correspondence [1]

1 2 3 6974 5 6 7707 8 9 852* 0 # 941

1209 1336 1477 Frequency(Hz)

When a button is pressed, both the row and column tones are generated by the telephone instrument. These two tones will be unique and different from tones of other keys. So, whenever we say that there is a low and high frequency associated with a button, it is actually the sum of two waves is transmitted. This fundamental principle can be extended to various applications. DTMF signals can be transmitted over a radio to switch on or switch off home appliances, flash lights, motors, cameras, warning systems, irrigation systems and so on. These encoded data can be stored in a microcontroller and can be transmitted serially to another system for processing. Block diagram for the proposed method is shown in Figure 1. [1]

Page 10: Microcontroller  remote controlling project

Figure 1 – Block diagram of the scheme [1]

Page 11: Microcontroller  remote controlling project

DECODER DESCRIPTION

The decoder used is M-8870. For operating functions (see Fig. 2 – Structure of M-8870). M-8870 includes a band split filter that separates the high and low tones of the received pair, and a digital decoder that verifies both the frequency and duration of the received tones before parsing the resulting 4-bitcode to the output bus. The M-8870 decoder uses a digital counting technique to determine the frequencies of the limited tones and to verify that they correspond to standard DTMF frequencies. Table 3 shows values of Decoder output for various frequencies.

Table 3- Values of Decoder output for various frequencies [3]

Button Low Frequency(Hz)

High Frequency(Hz)

Q1 Q2 Q3 Q4

1 697 1209 0 0 0 12 697 1336 0 0 1 03 697 1477 0 0 1 14 770 1209 0 1 0 05 770 1336 0 1 0 16 770 1477 0 1 1 07 852 1209 0 1 1 18 852 1336 0 0 0 09 852 1477 1 0 0 10 941 1209 1 0 1 0* 941 1336 1 0 1 1# 941 1477 1 1 0 0

Page 12: Microcontroller  remote controlling project

Figure 2 - Structure of 8870 Decoder [3]

Page 13: Microcontroller  remote controlling project

ATMEGA 16 MICROCONTROLLER The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.

The AVR core combines a rich instruction set with 32 general purpose working registers. All the32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega16 provides the following features: 16 Kbytes of In-System Programmable Flash Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1 Kbyte SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundary scan, On-chip Debugging support and programming, three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain (TQFP package only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes.. The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low-power consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to run. The device is manufactured using Atmel’s high density nonvolatile memory technology. The On chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot program

Page 14: Microcontroller  remote controlling project

running on the AVR core. The boot program can use any interface to download the application program in the Application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega16 is a powerful microcontroller that provides a highly-flexible and cost-effective solution to many embedded control applications. The ATmega16 AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits.[4]

Pin Descriptions

VCC Digital supply voltage.GND Ground.Port A (PA7..PA0) Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B also serves the functions of various special features of the ATmega16.Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running. If the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs. Port C also serves the functions of the JTAG interface and other special features of the ATmega16.Port D (PD7..PD0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical

Page 15: Microcontroller  remote controlling project

drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port D also serves the functions of various special features of the ATmega16.RESET Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset.XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating circuit.XTAL2 Output from the inverting Oscillator amplifier.AVCC AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter.AREF AREF is the analog reference pin for the A/D Convert.

Page 16: Microcontroller  remote controlling project

Figure 3 - Pin Configuration of AT Mega16 microcontroller. [2]

Page 17: Microcontroller  remote controlling project

DESIGN BASICS The operation is initiated by calling the second mobile phone (which is connected to the DTMF as shown in the Fig.1) and typing in the desired number corresponding to the required control effort at the transmitter end.

When the handset of the phone at the receiver end is picked up or the phone is picked up automatically, the receiver end comprises of input device, decoder, microcontroller, and relays. The input section consists of a mobile phone and a condenser microphone. For the decoder section, the underlying concept is DTMF signal reception and the decoded signal is fed to the microcontroller. The microcontroller output is connected to relays which perform the required action. Once the connection is established between the two phones, whatever phone key is pressed at the transmitting end, the corresponding DTMF tone is heard in the ear piece of the receiver phone. The ear piece is connected to a condenser microphone which picks up the DTMF tone and this output is fed to the DTMF decoder. The DTMF decoder will give the corresponding BCD value of the tone. The output of DTMF decoder is inverted by IC 74LS04, which is the input of microcontroller. This output is connected to PORT A of the Atmega 16L microcontroller. Then microcontroller’s output from PORT D is fed to the relays. Microcontroller is programmed as by pressing a button of caller handset it activates or deactivates the corresponding relay to switch on or off the home appliances.

Table-4 Actions performed corresponding to the key pressed

Number pressed by user

Output of DTMF decoder

Input to microcontrolle

r

Output from microcontroller

Action performed

2 0x0200000010

0x0D00001101

0x0000000000

Both relays off

4 0x0400000100

0x0B00001011

0x0100000001

One relay on

6 0x0600000110

0x09 00001001

0x0200000010

Another relay on

8 0x0800001000

0x0700000111

0x0300000011

Both relays on

Page 18: Microcontroller  remote controlling project

On a word each key press at transmitter end reflects as a BCD value Q1Q2Q3Q4 at the outputs of 8870 DTMF decoder. (The corresponding values are shown in Table 3) Then outputs Q1Q2Q3Q4 are inverted and processed by microcontroller and sent to the relay which is the basic structure of proposed work.

In this project required power is assumed from 220 V AC main power line. For this scheme AC voltage is step downed and a 7805 voltage regulator is used to supply continuous dc voltage.

Main circuit diagram is shown in figure 4.

Page 19: Microcontroller  remote controlling project
Page 20: Microcontroller  remote controlling project

Microcontroller was programmed in C language on AVR Studio 4 software. But C program is not compatible with ATmega 16, it supports Hex file. The software AVR Studio 4 builds the Hex file corresponding to the C program. [5]

For working in Proteus an equivalent circuit is used, where 8870 DTMF decoder is replaced with 4 binary switches. So the microcontroller input is given by the switches.

Equivalent circuit using Proteus 7.7 is given in figure 5.

Figure 5- Equivalent circuit using Proteus 7.7

Page 21: Microcontroller  remote controlling project

IMPLEMENTATION AND DISCUSSION

The circuit was build and tested. Refer fig. 4 for the picture of the tested circuit. At first the circuit was simulated with software PROTEUS7.7. After successful simulation in PROTEUS the circuit was implemented on a project board. Here relays were checked and each of two relays from microcontroller output was connected with 220V AC light. Relay acts as a switch [6]. The device controlled two 220V / 40W bulb. Then main circuit was implemented onto PCB (Printed Circuit Board).

Required VCC for microcontroller and VDD for DTMF decoder were supplied from main 220V AC power line. 220V AC was firstly step downed to 9V with a step down transformer. Then it was rectified and passed through a 5V voltage regulator IC7805 to VCC and VDD of microcontroller and DTMF decoder.

Handset at transmitting end must be in General mode or profile, thus it can generate audible keypad tones. Handset at receiving end must have the facility of automatic receiving the calls.

Page 22: Microcontroller  remote controlling project

CONCLUSION

This paper presents a method to control a domestic system using the DTMF tone generated by transmitting telephone instrument when the user pushes the keypad buttons of the mobile phone connected to the remote domestic system. This control method uses commercial mobile communication networks as the path of data transmission. This enables the user to control the system continuously by sending the mobile phone DTMF tone. This system is implemented in the 2G mobile communication network, so video data cannot be obtained. Future work includes research on the robot control system in the 3G mobile communication networks. This will facilitate controlling the remote robot, using the DTMF of mobile phone with video data from the remote mobile robot’s camera. The project is also useful in industry automation.

This setup with a little modification can be adapted to the following applications. [1]

1) Combination Lock2) Home Security System3) Mobile / Wireless Robot control4) Wireless Radio Control5) Continuous monitoring of system status6) Remote Switches etc.

Page 23: Microcontroller  remote controlling project

APPENDIX

Appendix 1 -List of Components used

1) IC 7805

2) Rectifier Diode 1N4007

3) 220v-9v Transformer

4) Condenser Microphone

5) 12MHz Crystal Oscillator

6) 3.57 MHz Crystal Oscillator

7) 8870 DTMF Decoder

8) 7404 NOT Gate

9) ATmega 16L Microcontroller

10) Transistor BC 547

11) 6 volts Relay

12) Capacitors of different values

13) Resistors of different values.

Page 24: Microcontroller  remote controlling project

Appendix 2- Microcontroller Program

#include<avr/io.h>

Void main(void)

{

Unsigned int k,h ;

DDRA= 0X00;

DDRD=0XFF;

While (1)

{

k=~PINA;

h=k & 0X0F;

switch (h)

{

case 0X0D ;

{

PORTD=0x00;

break;

}

case 0x0B;

{

PORTD=0x01;

break;

}

Page 25: Microcontroller  remote controlling project

case 0x09;

{

PORTD=0x02;

break;

}

case 0x07;

{

PORTD=0x03;

break;

}

}

}

}

Page 26: Microcontroller  remote controlling project

Appendix 3- ATmega Programming Logic/Port Control Example Guide

Hex Values:

0xFF = all bits set (turned on/high/1/5V) ----------------------- binary equivalent is 0b111111110x00 = all bits cleared (turned off/low/0/0V) ------------------- binary equivalent is 0b000000000xF0 = bits 0-3 are cleared (0) and bits 4-7 are set (1) ------ binary equivalent is 0b111100000x88 = bits 3 and 7 set (1) the rest are cleared (0) ----------- binary equivalent is 0b10001000

Look up : hexadecimal for an entire list of possible hex values. ATmega pin number equivalents example:

Number 7 6 5 4 3 2 1 0 – Pin numbers on the port (and bit numbers)

0x0F==0b00001111 0 0 0 0 1 1 1 1– set to high and low with hex/binary values

Setting Bit Values:

Many times we would like to set the voltage high for only a single pin of a port, and to do that you create what is called a ‘bit mask’, which is a binary number that has single 1-bit in the location corresponding to the pin you want to set, and all the rest of the bits are zero. You then use this number with a bitwise logical operator to finish the task. To create such a number, we should use the command:

_BV(PXn) // Where X is the port letter, and n is the pin number. For example, suppose you would like to make pin 2 on PORTA to be an output. You therefore need a bit mask with a 1 in bit number 2 location. The corresponding bit mask is easily builtby the command: _BV(PA2)

Setting the port’s data direction (input or output) on an ATmega: DDRX = 0x00; // Clears all the bits in the PORTx register, which makes all the associated pins to be inputs (keep in mind there are only ports A, B, C, and

Page 27: Microcontroller  remote controlling project

D on the ATmega328), so you can read various signals from things such as switches, sensors, or for analog to digital conversion, etc. (by default all pins are set to input, but you should always set them to make sure anyway.)

DDRX = 0xFF; // Sets all the bits in the PORTx register, which makes all the associated pins to be outputs (keep in mind there are only ports A,B,C, and D on the ATmega328), so you can control devices, such as motors, LED’s, speakers, etc., pretty much anything you would want the microcontroller to control (keep in mind that the ATmega cannot source much current, so you will probably need to use a transistor between the microcontroller and whatever you are trying to control if it needs more than 10 mA of current).

Initializing Port Values:

PORTX = 0xFF; // Clears all the bits in the PORTx register, and assuming that the pins are outputs, will make all the pins in PORTx go high (as mentioned in the section on Hex values above). So for example, PORTA = 0xFF; would set all pins in port A to on/high/1/5V, which would be the same as writing: PORTA = 0b11111111; Keep in mindthat the right-most bit corresponds to pin 0 on PORTA in this example.

PORTX = 0x00; // Clears all bits in the PORTx register and makes all pins in PORTx go low (as mentioned in the section on Hex values above). So for example, PORTB = 0x00; would clear all bits in the PORTB register and make all pins in PORTB go off/low/0/0V. This would be the same as writing: PORTB = 0b00000000;

Bitwise Logic:

PORTX |= 0xF0; // Method for setting bits. Performs a bitwise OR operation with the current bit values of PORTX and the bit mask represented by the binary number, 0xF0. The result is that only pins 4-7 in PORTX are set high, and the other pins are not affected. Equivalent in ‘long hand’ would be: PORTX = PORTX | 0xF0;

PORTX &= ~0x01; // Method for clearing bits. Performs a bitwise AND operation with the current bit values of PORTX and the bit mask represented by the binary number, ~(0b00000001) or 0b11111110. The result is that pin 0 is set low (referred to as ‘cleared’), regardless of what was there before. In this

Page 28: Microcontroller  remote controlling project

example, only pin 0 is cleared, and the state of the other pins are not affected. Equivalent in ‘long hand’ would be PORTX = PORTX & ~0x01;

PORTX ^= 0x02; // Method for toggling bits. Performs a bitwise XOR operation with the current bit values of PORTX and the bit mask represented by the binary number, 0x02. The result is that pin 1 is ‘toggled’ between the off and on states. Think of this operation like a light switch. Each time the statement is executed, it changes the state to be the opposite of what it was previously. Similar to the prior statements, this method of toggling only affects the bits in the locations where there are ones in the bit mask hex value. ‘Long hand’ would be PORTX = PORTX ^ 0x02;

The methods shown above are what we need to do to set up and control all the functions of the microcontroller. For example, suppose to turn on the ADC (analog to digital converter). To do so, set bit 7 in the ADCSRA register. See if can remember how to do this (without disturbing bits 6 – 0) from the description above1.

1 ADCSRA |= 0x80;Equivalently, we would have written: ADCSRA |= _BV(ADEN); // (ADEN is macro-defined to be 7)

Page 29: Microcontroller  remote controlling project

REFERENCES

[1] Tuljappa M Ladwa, Sanjay M Ladwa, R Sudharshan Kaarthik ; “Control of Remote Domestic System Using DTMF” ; ICICI-BME 2009 Bandung, Indonesia,2009.

[2] Yun Chan Cho and Jae Wook Jeon ; “Remote Robot control System based on DTMF of Mobile Phone” ; IEEE International Conference INDIN 2008, July 2008.

[3] 8870 Datasheet,http://www.clare.com/datasheets/8870-01.pdf

[4] ATmega 16 Microcontroller Datasheet,http://www.atmel.com/dyn/products/datasheets.asp?family_id=607

[5] Joe Pardue ;“C Programming for Microcontrollers”; 3rd Ed , 2010.

[6] Kevin R. Sullivan ; “Understanding Relays” .

[7] Relay,http://en.wikipedia.org/wiki/Relay