controlling home appliances using c

16

description

c language

Transcript of controlling home appliances using c

Page 1: controlling home appliances using c
Page 2: controlling home appliances using c

C for Controlling!

Abstract

The computer had seen a lot of evolution both in hardware and software sides, yet

there are some features which remain unbeatable and one among them is the structure

oriented programming language or C. Apart from computer programming they are fused

in circuit boards, microcontrollers.., etc to carry out specified functions. The reason is the

elegance and simplicity of the keywords used in c.

This paper is about Controlling Home/Industrial Appliance with Mobile

phone using C. This idea is evolved from the in-out features of microcontroller. The

same can be extended to a PC where we are going to binary input which is actually

voltage signal from Mobile phone and the output from PC is again a pulse which will

activate a relay and hence controlling electrical/electronic appliance.

This is possible in all PCs having printer port(obviously all the now-a-days pc

have them!) and the mobile phone requirement is that it should have provision for

headset and auto answer feature can be enabled

Page 3: controlling home appliances using c

Introduction

Gadgets are becoming more and more simplified day after day, the best outcome

will be the one which is easier to use and cost effective, also the familiar one. Here I am

going to explain about controlling the appliances using mobile phone and the back end

job is done by a c program

After the completion of this setup, we can control the appliance using a pc when

we are at home and if are out, we can use our mobile phone to control the appliances, by

controlling I mean on/off of that appliance, the code explained below can control up to 9

appliances at a single instance. However we can control any number of appliances using

a multi dimensional array.

Two mobile phones should be used for tele-controlling, the thing is that each key

in a mobile have a unique frequency which can be reproduced using earphone, the sound

can be compared with predefined frequencies in a Matlab and the corresponding number

can be found which when given as input to C program will toggle the appliance on/off

using a relay. The cost for implementation is very less since we use resistors and relays

as majority part

Page 4: controlling home appliances using c

Proto-concept

The c program will check for inputs which is from 1 to 9 and send a pulse to

corresponding port which will activate a relay connected to an appliance. The input can

either be manual or mobile operated

Mobile operated control

The mobile is connected to USB port in Auto Answer mode ON, when the

number is dialed from distance the control side mobile will get switched on, then

we can press any number from 1 to 9, this will produce a corresponding sound

with varying frequencies. The same can be decoded into number by comparing it

with pre defined frequencies in MATLAB, the number decoded will become

input to the c program. This will produce a pulse signal in the printer port. In that

port we will be connecting 9 relays to control 9 appliance

Flow of control

1. The mobile in controlling side is dialed from distance either from mobile phone or

landline

2. The receiving mobile got automatically answered

3. Now this is capable of hearing all the tones (it should be in DTMF mode)

4. Consider we are pressing 1

5. The same is reproduced in the controlling side as frequency form, this is given as

input to the pc via usb port.

6. A Matlab program compares the incoming frequency with predefined frequencies and

decode the number(In this case it is 1)

Page 5: controlling home appliances using c

7. The C program uses a switch case statement, it compares the incoming value and

transfer the control to that appropriate segment.

8. Now a pulse is produced in the printer port corresponding to the input received

9. The corresponding relay is activated

10. If the appliance is on it will be switched off and if its off it will be switched on

11. If the connection is ended the controller side mobile returns to standby mode

Circuit diagram for Telephone operated control

Page 6: controlling home appliances using c

Description

The circuit uses IC KT3170 (DTMF-to-BCD converter), 74154 (4-to-16-line

demult-iplexer), and five CD4013 (D flip-flop) ICs. The working of the circuit is as

follows.

Once a call is established (after hearing ring-back tone), dial ‘0’ in DTMF mode.

IC1 decodes this as ‘1010,’ which is further demultiplexed by IC2 as output O10 (at pin

11) of IC2 (74154). The active low output of IC2, after inversion by an inverter gate of

IC3 (CD4049), becomes logic 1. This is used to toggle flip-flop-1 (F/F-1) and relay RL1

is energised. Relay RL1 has two changeover contacts, RL1(a) and RL1(b). The energised

RL1(a) contacts provide a 220-ohm loop across the telephone line while RL1(b) contacts

inject a 10kHz tone on the line, which indicates to the caller that appliance mode has

been selected. The 220-ohm loop on telephone line disconnects the ringer from the

telephone line in the exchange. The line is now connected for appliance mode of

operation.

If digit ‘0’ is not dialed (in DTMF) after establishing the call, the ring continues

and the telephone can be used for normal conversation. After selection of the appliance

mode of operation, if digit ‘1’ is dialed, it is decoded by IC1 and its output is ‘0001’. This

BCD code is then demultiplexed by 4-to-16-line demultiplexer IC2 whose corresponding

output, after inversion by a CD4049 inverter gate, goes to logic 1 state. This pulse

toggles the corresponding flip-flop to alternate state. The flip-flop output is used to drive

a relay (RL2) which can switch on or switch off the appliance connected through its

contacts. By dialing other digits in a similar way, other appliances can also be switched

‘on’ or ‘off.’

Page 7: controlling home appliances using c

Once the switching operation is over, the 220-ohm loop resistance and 10kHz tone needs

to be removed from the telephone line. To achieve this, digit ‘0’ (in DTMF mode) is

dialed again to toggle flip-flop-1 to de-energise relay RL1, which terminates the loop on

line and the 10kHz tone is also disconnected. The telephone line is thus again set free to

receive normal calls.This circuit is to be connected in parallel to the telephone instrument

Manual control

To achieve this, the following set up should be implemented in pc

Page 8: controlling home appliances using c

Description

The interface circuit along with the given software can be used with the printer

port of any PC for controlling up to eight equipment .

The interface circuit shown in the figure is drawn for only one device, being

controlled by D0 bit at pin 2 of the 25-pin parallel port. Identical circuits for the

remaining data bits D1 through D7 (available at pins 3 through 9) have to be similarly

wired. The use of opto-coupler ensures complete isolation of the PC from the relay driver

circuitry.

Lots of ways to control the hardware can be implemented using software. In C/C+

+ one can use the outportb(portno,value) function where portno is the parallel port

address (usually 378hex for LPT1) and 'value' is the data that is to be sent to the port. For

a value=0 all the outputs (D0-D7) are off. For value=1 D0 is ON, value=2 D1 is ON,

value=4, D2 is ON and so on. eg. If value=29(decimal) = 00011101(binary) -

>D0,D2,D3,D4 are ON and the rest are OFF.

The code in C language

#include<dos.h>#include<stdio.h>#include<conio.h>#define PORT 0x378 /* This is the parallel port address */

main(){char val=0,key=0;char str1[]="ON ";char str2[]="OFF";char *str;clrscr();printf("Press the approriate number key to turn on/off devices:\n\n");printf("Here Device1 is connected to D0 of parallel port and so on\n\n");

Page 9: controlling home appliances using c

printf("Press \"x\" to quit\n\n");gotoxy(1,8);printf("Device1:OFF Device2:OFF Device3:OFF Device4:OFF\n");printf("Device5:OFF Device6:OFF Device7:OFF Device8:OFF");

while(key!='x' && key!='X'){gotoxy(1,12);printf("Value in hex sent to the port:");key=getch();switch(key){

case '1':

gotoxy(9,8);val=(val&0x01)?(val&(~0x01)):val|0x01;str=(val&0x01)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '2':

gotoxy(21,8);val=(val&0x02)?(val&(~0x02)):val|0x02;str=(val&0x02)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '3':

gotoxy(33,8);val=(val&0x04)?(val&(~0x04)):val|0x04;str=(val&0x04)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '4':

Page 10: controlling home appliances using c

gotoxy(45,8);val=(val&0x08)?(val&(~0x08)):val|0x08;str=(val&0x08)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '5':

gotoxy(9,9);val=(val&0x10)?(val&(~0x10)):val|0x10;str=(val&0x10)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '6':

gotoxy(21,9);val=(val&0x20)?(val&(~0x20)):val|0x20;str=(val&0x20)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '7':

gotoxy(33,9);val=(val&0x40)?(val&(~0x40)):val|0x40;str=(val&0x40)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",val);break;

case '8':gotoxy(45,9);val=(val&0x80)?(val&(~0x80)):val|0x80;

Page 11: controlling home appliances using c

str=(val&0x80)?str1:str2;printf("%s",str);outportb(PORT,val);gotoxy(1,13);printf("%x",(unsigned char)val);break;

}

}}

Advantages

Very cheap and reliable

Controlling in as well as outside home

Future trends

The same can be fused in a microcontroller and attacehed with land line so that

there will be no need to use pc and mobile phone in controlling side. By using 3g mobiles

we can watch video of what is going on in home.., etc

Conclusion

We are living in an absolute world of technology rocketing at a greater

speed searching for more and more instruments to make life of humane even

sophisticated. Computer engineering and Instrumentation with clenched fists had made a

lot of successful techoes like PLC, DCS.., hope this will make the next Generation.