DO IT URSELF You can use your cell phone or any landline to call up your home when everyone is away, and leave instructions to switch off the oven or switch on the air conditioner. Here’s how you can program your PC and phone to listen to you. By: NITIN KOTHARI —The author has taught electronics and is an experienced graphics designer. At present he is the director of Unique Computer Education, Ratlam. How to Control Devices at Home with a Phone ; ou are tired after a long day at work and just wish a warm cup of tea was ready for you as soon as you reach home, even though there is no one at home to make that tea. Well, you neednt despaira few instructions from your cell phone can activate the tea-making machine at home and your cup of tea will be ready by the time you open your front door. And if youve forgotten to switch off an electric gadget after embarking on a weekend holiday, you can give instructions through your cell phone and your work will be done. In fact, you can control any electronic or electric device from anywhere in the world through a telephone or a cell phone. Sounds wonderful, doesnt it? But it doesnt work that easily. So lets take a look at how we can turn our home into a sci-fi house, and use our telephone as a remote control. The process of turning your telephone into a remote control involves the use of an IVRS (Interactive Voice Response System). You would have come across such systems while interacting with your bank, credit card company, railway enquiry ticket reservation services, and so on. An IVRS consists of a PC with a modem connected to the telephone line and software that can handle voice modems. IVRS allows users to activate software through telephone keys. The software & INFORMATION TECHNOLOGY Connecting telephone with a gadget plays a wave file (.wav), which is recorded by the Windows Sound Recorder and asks you what you want to do. By pressing the telephone keys you can activate any function you want to. As an example, if you press 1 on your mobile phone to switch on or off any electronic or electric gadget, there is a function in the software, which will be activated and set the bit to the parallel port (Print Port or LPT1). And there is a relay circuit connected to it, which will be activated and switch your electronic gadgets on or off, depending on your program. Heres an in-depth step-by-step process to help you easily switch on or off any one electronic/electric gadget in your home. I am taking an example of a tea-maker here. You can carry out this project even if you dont have any programming skills. And in case you can program, you could November 2003 CMYK customise this project according to your needs and convert your home into a digital home. Just follow the steps given hereits a complete recipe to cook up some great digital fare for your home. Setting up the environment Your home PC should be running Windows 98 with a modem connected to a telephone line. The telephone line should be DTMF (Dual Time Multi Frequency) tone that is now a standard DO IT URSELF all over the country, and your modem should be a voice modem. Before we begin, you must install an appropriate driver for the modem and Visual Basic 6.0, because I am using it to develop the software. Also, make sure that the sound card is installed in your computer and your PC has a speaker and microphone connected to it. Downloading the components Before writing a program you will need a component called KDTele. Its an ActiveX component, which you can download from the website http://www.kaed.com/ kdtele3.zip This is a 5.35 MB zip file and does not take much time to download. Its a 30-days evaluation version and the version number is 3.5. This component allows the software to pick-up and answer incoming calls automatically. KDtele tools consist of lots of components, which are very useful for different applications but here we will use only two components called KDPhone and KDVoice. The KDPhone component allows the software to pick-up and answer incoming calls, and KDVoice plays the audio (.wav file) on the phone. Next, extract the KDtele3.zip file after downloading by double clicking on it. Then install KDtele tools on your computer by clicking on the KDtele3561.exe file. The KDtele tools welcome screen will appear on the screen. Press Next, read the agreement carefully and then accept the KDtele tools Licence Agreement by clicking Yes. Press the Next button twice to continue the installation process and then click on Finish to finish the installation process. Downloading the (.DLL) file In this project we are using a parallel port to operate the relays. But in Visual Basic we cant access the hardware directly. All hardware requests must go through Windows. To control the port directly we have to use (.DLL) files. You can get these as a free download by going to the following pagehttp:// webpages.charter.net/grumble/ ParallelPort/ParallelPort.html Here, click on the link cardio32.zip and download the file. Then extract this zip file and copy the cordio32.DLL file into Windows\system directory. This file will be in the Windows system directory. 1. Welcome! Please press 1 to switch the tea-maker on and press 2 to switch it off. 2. You have pressed the wrong key. Please confirm the number. 3. You have switched on the tea-maker. 4. You have switched off the tea-maker. Adding the components to Visual Basic Start Microsoft Visual Basic and add the components that you have downloaded. Click on the Project menu and choose Sound recorder Sound selection Components Components. The Components dialogue box will appear on the screen. Click on the check box Kaed System-KD tele tools and then click OK. All the KDtele tools are now added to the VB toolbox. Recording the messages In this step we have to record the messages that will be played on the phone when a call is made. These files are (.wav) files and will be played Toolbox by the KDVoice control. KDVoice is compatible with the PCM wave files. It is suggested that you always use 8000 Hz, 16-bit mono format because it is compatible with all ordinary modems. To begin the message recording process, start the Sound Recorder program from Entertainment in Accessories. Click on Record and start recording with your microphone. You need to record four messages, which are: Save all these messages by clicking on the Save as option in the File menu, give the file name, and then click on Change. Choose PCM from the Format drop-down list box and choose 8000 Hz, 16-bit mono from the Attribute dropdown list box. Save all the files with the following names because these names are used in the program. Welcome.wav Wrong.wav On.wav Off.wav Writing the entire program (a) Start Microsoft Visual Basic. The new project dialogue box will appear on the screen. Click Standard.exe and then enter Open. Your screen will look as shown in the figure titled Project form 1 (given on the next page). Change the caption of Form 1 to Telephone As a Remote by clicking Caption in the Property window. Place KDPhone and KDVoice control to your form. By default, KDPhone and November 2003 CMYK INFORMATION TECHNOLOGY ' DO IT URSELF first activate the telephone device. Therefore, we use Line active method in the forms load event as described in the following code... Project form 1 KDVoice control have the names KDphone1 and KDvoice1. Leave these as they are. You can also attach a background music file, which can be played during the call. To do this, click on KDvoice control and set its Background Enable properties to True. Then type in the path of your background wave file in the Background files property in the Property window. Place a Text box and change its text property to 0 (zero). It will show you the time in seconds on the timer. Place two timer controls to your form. By default their names will be Timer1 and Timer2. Leave these as they are. We are using Timer1 to display a counter and Timer2 to cut off the tea-maker after a specified time period. Click on Timer1 control and change its interval properties to 1000. Here 1000 means one second. Set Timer2s interval properties to the time interval you want your tea-maker to be cut off at. For example, if you want to cut it off after 10 seconds give a time interval of 10000. Now click on the Project menu and then click on the Add module option. Open a new module and write the following code in the General declarations... Option Explicit Public Declare Function CardOutpb Lib “cardio32.dll” (ByVal porta As Integer, ByVal databyte As Integer) As Integer In this code we have declared a public function that is defined in (cardio32.DLL) file to set bits to the parallel port. In this entire process, it is important to INFORMATION TECHNOLOGY Private Sub Form_Load() Dim a As Long a = KDPhone1.LineActive(0, True) If a <> 0 Then MsgBox “Error” & KDPhone1.GetErrorMsg(a) End If ‘if an error has occured it shows a message with an error. End Sub To ensure that the call is properly connected, we will use the KDphone1.answer method. If the call is properly connected, we have to play the welcome message file over the call. KDPhone will fire OnCallState event with a call state of csConnected as the code below describes in detail. Add the following code to the OnCallState event of KDPhone1... Private Sub DPhone1_OnCallState(ByVal CallState As KDTele.TxCallState, ByVal Param1 As Long, ByVal Param2 As Long, ByVal CallHandle As Long) Dim c As Long Dim b As Long Select Case CallState Case csRing ‘When incoming ring is detected b = KDPhone1.Answer(0) Print “phone is received” Case csConnected: ‘When call is connected properly c = KDVoice1.Play(KDPhone1.WavePlayID, “c:\telephone.wav”, 0, -1) If c <> 0 Then KDPhone1.Hangup MsgBox “error” & KDVoice1.GetErrorMsg(c) End If Case csError: ‘When any error occured during the call KDPhone1.Hangup MsgBox “error” & KDPhone1.GetErrorMsg(Param1) End Select End Sub After the welcome message is played, the user will be given a choice to press a key on a mobile handset or a telephone instrument. If he presses 1, the tea-maker should be switched on and if he presses 2 the tea-maker should be switched off. In case the user presses a key other than November 2003 CMYK 1 or 2, the Wrong.wav file should be played. As soon as the user presses any key the OnDigit Detected event will be fired. Here we are using a parallel port to attach the tea-maker, so by setting the bits we will turn it on/off. Lets first understand the parallel port and what it has. The parallel port is made up of three different sections. These are the data lines, control lines and status lines. There are eight data lines and these are the primary means of getting information out of the port. In simple projects like this, we will concentrate on the data lines. To deal with parallel port you must know its address for data line port, which is same as the port address. decimal 888 Hex 378 h You must also know the command and number you want to set it to. In the parallel port, data lines are from pin no. 2 to 9. So to switch on or off any one device you can use any one of these. Here I have used pin no. 2. When the bit is 0 on pin no. 2 there will be no voltage at all at this pin, and when the bit is set to 1 there will be a voltage of 5 volt DC. This 5 volt DC can be used to drive a relay circuit and the tea-maker will be connected to this relay circuit. CardOutpb is a function in cardio32.DLL, which can be used to set a bit on or off. Syntax of Cardoutpb is as follows... CardOutpb Port address, value which is to be set When the user presses 1 the tea-maker will be switched on by setting bit 1 of pin 2 of the parallel port and play a (on.wav) file so that the user can understand that the switch is on. In the meanwhile, Timer1 and Timer2 will be enabled. After the specified time interval the tea-maker will be switched off. The user also can switch the tea-maker off by pressing 2 on the telephone. Go through the following code, which will make things clearer to you. Add the following code to OnDigit Detected event of KDPhone1 control. Private Sub KDPhone1_OnDigitDetected(ByVal DO IT URSELF Digit As String, ByVal CallHandle As Long) Dim x As Long Select Case Digit Case 1 CardOutpb 888, 1 Timer1.Enabled = True Timer2.Enabled = True x = KDVoice1.Play(KDPhone1.WavePlayID, “c:\on.wav”, 0, -1) Case 2 CardOutpb 888, 0 Timer1.Enabled = False Timer2.Enabled = False x = KDVoice1.Play(KDPhone1.WavePlayID, “c:\off.wav”, 0, -1) Text1.Text = 0 Case Else ‘Off.Wav x = KDVoice1.Play(KDPhone1.WavePlayID, “c:\wrong.wav”, 0, -1) End Select End Sub Add the following code to the timer event of Timer1 control... Private Sub Timer1_Timer() CardOutpb 888, 0 Timer1.Enabled = False Timer2.Enabled= False Text1.Text = 0 End Sub Add the following code to the timer event of Timer2 control... Private Sub Timer2_Timer() Text1.Text = Val(Text1.Text) + 1 End Sub In this project I have attached only one device in this wayyou can attach many devices by using all the eight data lines. In that case, eight relay circuits will be required. You can also customise this project according to your needs. Running and testing the program In the end, attach the gadgets with a relay circuit to the parallel port at pin no. 2, and for negative voltage take out a black wire from the SMPS. Relay circuits are very cheap and easily available in project books and magazines, or you can consult any electronic student. The relay circuit may vary according to the load you connect to it. Save this project and run it by clicking the F5 function key. If the project runs successfully make an executable file for it by clicking on File menu and then click on Make Exe. Copy this (.exe) file to the start-up folder; otherwise if the power is cut off when you are out of the house you will not be able to control any device. To control any device by a telephone or mobile, your PC and this application must be running. I do hope you have a great time constructing and working on this project, and that it helps you relax at the end of a long, hard days work. Warning: You must take adequate care while building the complete project. The author and editor are not responsible in case of any damage to your computer while building and implementing the project. SPREADING THE KNOWLEDGE ARE YOU A ‘TECHIE?’ We define a ‘techie’ as a person who has a technical background on any subject related to the IT industry. A techie could belong to the Internet, software, hardware or the telecom industry—together which we define as IT industry. DO YOU WANT TO WRITE AND BE READ? If you fit our bill, we invite you to share your knowledge with our two-and-a-half lakh readers, and quench their thirst for questions like: ³ Should we put RD RAM in our PIV PCs or not? ³ When does one need to switch to Windows 2000 or any other Networking OS? ³ What difference can the 3G technology have on the current scenario of telecom? So, if you’re craving to explain and enlighten, join the ‘i.t.’ bandwagon in spreading knowledge. In the process, a positive image for yourself and your organisation will automatically be generated. INTERESTED? Simply send us your brief resume highlighting your IT related experience. Also, attach a list of topics you would like to discuss in the form of articles. You may either post to: The editor, ‘i.t.’ magazine EFY Enterprises Pvt Ltd D-87/1, Okhla Industrial Area, Phase I, New Delhi 110020, Phone: 26810601/02/03; Fax: 26817563, 26812312 OR e-mail at: [email protected] (Please state the subject as: ‘I am a techie’ ) November 2003 CMYK INFORMATION TECHNOLOGY !
© Copyright 2018