📜 ⬆️ ⬇️

Arduino: IR control of home appliances (use of the device)

Zavravstvuy Habr! According to reviews, I realized that in the article “Arduino: IR control of home appliances”, he did not devote much to the final goal of the device and how to put it into practice, so I’ll do it now.
The purpose of our arduino-device is to provide control over the set of devices controlled via the IR channel. The following figure shows an example of how to use this device, right now, while Ethernet Shield has not come to me, I will describe the USB connection to the server as an example.
I’ll say right away that the drawing was made specifically to clarify the device’s capabilities, everything is much simpler at home for me, because I only control the TV and use my PC as a source as the server, as in the second drawing.

Suppose we have two rooms and there are devices in each, and their brands and models are the same, respectively, the sets of commands for the TV, DVD player and satellite receiver in the rooms are the same. Based on this, we can conclude that it is necessary to use an Arduino output for each device.

In the comments, Alexeyslav suggested that I use a demultiplexer for these purposes, under the pretext of simplifying the program part, I understood that it meant using the IRRemote library. I’m not against the demultiplexer, I don’t like the exactness of the IRRemote on conclusion 3, by the way, no one forbids using the demultiplexer with my module.

As for me, I have no need for several ports, attention to the drawing:

')
I used emitting diodes from Global Cache, a diode in a package, as in the figure below.

It is convenient that the radiator can be glued directly onto the equipment in the region of the infrared receiver and thus ensure that the control will be stable and only the device that we want to control (if there is more than one device nearby that reacts to the command sent).

When I wrote the server part, I didn’t want to fool around much, so it was decided to throw a small and dull web server onto Delphi with a built-in “port monitor” (to transfer data to the arduino via the virtual Com port); for this, Indy idHTTPSever and CPort components were used.
On the server side there is an index.html page with files for it (CSS, JS, graphics, etc.) and the file in which codes.txt are stored, codes for controlling equipment. Codes can be stored in two formats: HEX and GlobalCache.
In the HEX format, there is a rule to start a command with the identifier 0000, we will consider this a place for manipulating the number of repetitions of the code and the port to which it should be sent.
The number of repetitions is the first two characters converted from hexadecimal to decimal CC + 1
that is, 00 = 0 + 1 = 1 or 0A = 10 + 1 = 11 ;
The port address is the second two characters in which the arduino port number is simply hidden,
for example: 00 = digital port 0 or 0D = digital port 13 ;
The remaining data of the HEX code is not necessary to change, leaving as is.
For codes in the GlobalCache format, this is a bit more complicated; the format itself looks like this:
sendir,{moduleaddress}:{connectoraddress},{ID},{frequency},{count},{offset},{on1},{off1}...
Where:

I mainly use the HEX format, but it is worth noting that the codes in the GlabalCache format are shorter by almost 2 times and, accordingly, 2 times faster.
Each command must be strictly on a separate line, the line number in the file is used as a pointer to a specific code, for my convenience, codes begin with digits. the lines in the file are numbered from zero, so line number 0 is obtained - this is the button code 0.

I give as an example a part of the codes.txt file with commands to my Philips 47PLF4007:
 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021//digit 0 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0BED 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0021//digit 1 000D 0073 0028 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0021//digit 2 ... 000D 0073 0024 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 001F 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 0020 0010 0010 0010 0021//home sendir,5:2,1,36000,1,1,97,31,16,30,16,16,16,16,16,30,32,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,32,14,16,30,16,16,32,14,16,30,16,16,16,720//list 000D 0073 002A 0000 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 000F 0010 0010 0010 0010 0010 0BEE 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0010 0010 0010 0010 0010 0010 0021//info ... 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021//digit 0 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0BED 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0021//digit 1 000D 0073 0028 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0021//digit 2 ... 000D 0073 0024 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 001F 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 0020 0010 0010 0010 0021//home sendir,5:2,1,36000,1,1,97,31,16,30,16,16,16,16,16,30,32,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,32,14,16,30,16,16,32,14,16,30,16,16,16,720//list 000D 0073 002A 0000 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 000F 0010 0010 0010 0010 0010 0BEE 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0010 0010 0010 0010 0010 0010 0021//info ... 0030 0030 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021//digit 0 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0BED 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0021//digit 1 000D 0073 0028 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0021//digit 2 ... 000D 0073 0024 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 001F 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 0020 0010 0010 0010 0021//home sendir,5:2,1,36000,1,1,97,31,16,30,16,16,16,16,16,30,32,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,32,14,16,30,16,16,32,14,16,30,16,16,16,720//list 000D 0073 002A 0000 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 000F 0010 0010 0010 0010 0010 0BEE 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0010 0010 0010 0010 0010 0010 0021//info ... 0030 0030 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021//digit 0 000D 0073 002A 000D 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0BED 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0021//digit 1 000D 0073 0028 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0010 0021//digit 2 ... 000D 0073 0024 000D 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 001F 0010 0010 0010 0BDE 0061 0021 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 001F 0020 001F 0020 0020 0010 0010 0010 0021//home sendir,5:2,1,36000,1,1,97,31,16,30,16,16,16,16,16,30,32,14,16,16,16,16,16,16,16,16,16,16,16,16,16,16,32,14,16,30,16,16,32,14,16,30,16,16,16,720//list 000D 0073 002A 0000 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 000F 0010 0010 0010 0010 0010 0BEE 0061 0021 0010 0020 0010 0010 0010 0010 0010 0020 0020 000F 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0020 0010 0010 0010 0010 0010 0010 0021//info ... 


The server (or something like that, see the picture below) is completely built on GET requests and this must be taken into account when developing the HTML page. The point is this, I request a file from the server, the name of which begins with an underscore, and then the line number from the codes.txt file on which the command is located.

The server sees that the requested file starts with “_”, deletes the first character from the name and reads the remaining number, then sends the code located on the line with the number of this number to the device.
 procedure TForm1.srvCommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); var S,codeStr:String; i:Cardinal; begin S:=ARequestInfo.Document; Delete(S,1,1); if S='' then S:=ExtractFilePath(ParamStr(0))+'webdata\index.html' else begin if (S[1]='_') then begin Delete(S,1,1); codeStr:=SL.Strings[StrToInt(S)]; Delete(codeStr,pos('/',codeStr),255); if ComPort1.Connected then ComPort1.WriteStr(codeStr+#13); S:='ok.js'; end; S:=StringReplace(S,'/','\',[rfReplaceAll]); S:=ExtractFilePath(ParamStr(0))+'webdata\'+S; end; try AResponseInfo.ContentType:=ARequestInfo.ContentType; AResponseInfo.ContentStream:=TFileStream.Create(S,0); except end; end; 

For the client, I wrote several functions responsible for communicating with the server. To request the server to execute a command, it is enough to add a new tag with the scr attribute to the page, as we will do:
 var boolSendRepeat = false; function addScript(src){ var element = document.createElement('script'); element.type = 'text/javascript'; element.src = src; element.className = 'bufferresponsescript'; document.getElementsByTagName('head')[0].appendChild(element); } function delScripts(){ var z = document.getElementsByClassName('bufferresponsescript'); for(var i=z.length;i>0;i--){ z[i-1].parentNode.removeChild(z[i-1]); } } function sendCommand(cmdNumber){ addScript('_'+cmdNumber); } function sendMacro(arrCmdNumber,arrDelays){ var s=''; for(var i=0;i<arrCmdNumber.length;i++){ s = 'sendCommand('+arrCmdNumber[i]+')'; setTimeout(s,arrDelays[i]); } } function repeatFunc(cmdNumber,repeatTime){ var s = 'repeatFunc('+cmdNumber+','+repeatTime+')'; if(boolSendRepeat==true){ sendCommand(cmdNumber); setTimeout(s,repeatTime); } } function repeatStop(){ boolSendRepeat=false; } function sendRepeat(cmdNumber,repeatTime){ boolSendRepeat=true; repeatFunc(cmdNumber,repeatTime); } 

You can apply it in the interface like this:
  <td onclick="sendCommand(32)">List</td><!-- ,  32     codes.txt--> <td onclick="sendMacro([46,43],[10,550])"></td><!--    46,   550    43--> <td onmousedown="sendRepeat(12,800)" onmouseup="repeatStop()">Vol+</td><!--    12,  800    --> 

The result of all of the above is shown in the following images:

Just yesterday, I added a direct switch to on-air TV channels to the client interface, it turned out pretty:


I hope in this post I was able to answer your questions and reveal what was left behind in the last article.

References:
CPort component
Project files
PDF with a description of the API of Global Cache devices

Source: https://habr.com/ru/post/216355/


All Articles