Remote control of electrical appliances using infrared emission

Infrared remote control is a wireless control technology. It has many advantages such as low power consumption, low cost, and easy implementation. Therefore, it is widely used by various electronic equipment, especially household appliances, such as TV remote control and air conditioner remote control in daily life. And so basically use infrared remote control technology.
However, the remote control is not all infrared remote control, it may also be a radio frequency remote control. Infrared remote control uses near-infrared light (frequency is only tens of thousands of hertz) as a remote control light source, while radio frequency remote control uses ultra-high frequency electromagnetic waves (frequency up to several hundred million hertz) as a signal carrier. On the top of the infrared remote control, some are inlaid with one or more small bulbs, and some have a small black cover. This black cover is transparent to infrared rays, but the human eye cannot see through it. On the top of the RF remote control, some protrude an antenna, and some have nothing (in fact, the transmitter is enclosed in the cover). The infrared remote control with a light bulb is like a flashlight. Wherever the infrared light hits, the electrical appliance will receive the response, which determines the three characteristics of the infrared remote control:
1. The remote control must be aimed at the electrical appliance to respond. If the flashlight does not shine here, it must be dark;
2. The remote control should not be too far away from the electrical appliance, preferably within five meters. This is also understandable, the flashlight is far away, and the light on the object will be dimmed;
3. There should be no obstacles between the remote control and the electrical appliance. Can you imagine the light from a flashlight penetrating a wall?
The radio frequency remote control is just the opposite of infrared characteristics. It uses ultra-high frequency electromagnetic waves, so the signal is scattered and does not have directionality, and the effective distance of the radio frequency signal can be as long as tens of meters, and finally the radio frequency signal can easily pass through. through non-metallic obstacles. The different characteristics of infrared remote control and radio frequency remote control determine their respective areas of expertise. Infrared remote control seems to have many limitations, but it is actually suitable for household appliances. Otherwise, everyone can remotely control the neighbor's electrical appliances through the wall. The strong anti-interference ability of the remote control is more suitable for some professional electronic equipment. Because infrared remote control is closer to daily life, the smart phones purchased by the public are naturally equipped with infrared remote control (some mobile phones may not be equipped with infrared transmitters).
It sounds like a mobile phone equipped with an infrared transmitter can be used as a remote control, and a mobile phone can also control many home appliances.

First, the infrared permission configuration should be supplemented in the AndroidManifest.xml of the App project. The specific configuration example is as follows:

    <!-- 红外遥控 -->
    <uses-permission android:name="android.permission.TRANSMIT_IR" />
    <!-- 仅在支持红外的设备上运行 -->
    <uses-feature android:name="android.hardware.ConsumerIrManager" android:required="true" />

Secondly, initialize the manager of the infrared remote control in the code. Note that the infrared remote control function has only been supported since Android 4.4. The management class corresponding to the infrared remote control is called ConsumerIrManager. There are three common methods, which are described as follows:
hasIrEmitter : Check whether the device has an infrared transmitter. Return true for yes, and false for no.
getCarrierFrequencies : Get the available carrier frequency range.
transmit : Transmits infrared signals. The first parameter is the signal frequency, in Hertz (Hz). The infrared frequency of household appliances is usually 38000Hz; the second parameter is the signal format in the form of an integer array.
The following is an example of the initialization code of the infrared remote control manager:

    private ConsumerIrManager cim;
    private void initInfrared() {
        // 获取系统的红外遥控服务
        cim = (ConsumerIrManager) getSystemService(Context.CONSUMER_IR_SERVICE);
        if (!cim.hasIrEmitter()) {
            tv_infrared.setText("当前手机不支持红外遥控");
        }
    }

Finally, just call the transmit method when you are ready to transmit the remote control signal.

Is it really that simple? Of course not, the mystery here is all in the signal format parameter of the transmit method. Think about it, there are many kinds of home appliances, and there are several brands of each kind of home appliance. For a home appliance in the room, there are also rows of buttons on the remote control. In this way, there are countless combinations of signal formats, and ordinary developers are not insiders of electrical appliance manufacturers. It is really difficult to crack the infrared signal encoding of these electrical appliances.
Manual cracking is not easy, but it is not impossible. Now there is a decoder for infrared remote control, which can be purchased on Taobao. This decoder can analyze the infrared remote control signals of common household appliances, except for the following two:
1. Air conditioner remote control, the control of air conditioners is more complicated, and the light temperature may be adjusted more than ten times, which is difficult to crack.
2. The light remote control, the light itself emits heat and emits a lot of infrared rays, which is bound to cause serious interference to the external infrared signal; so the light can only use radio frequency remote control.
The infrared decoder is an essential instrument for home appliance maintenance personnel. It is often used to detect whether the remote control works normally. In order to enable the mobile phone to realize the remote control function, the developer should also use the decoder to capture the infrared signal corresponding to each button. Next, take the remote control decoding of the sweeping robot as an example to introduce how to obtain the corresponding infrared remote control commands through the decoder.
First, aim the remote control of the sweeping robot at the infrared receiving window on the front of the decoder, and press the clean button on the remote control (start sweeping/stop sweeping). At this time, the analysis results of the decoder are shown in the following figure:

As can be seen from the above figure, the infrared signal of the clean key consists of three parts, namely user code 4055, data code 44, and circuit 61212. Among them, the user code represents the manufacturer's code, and each manufacturer has its own unique code; the data code represents the number of the button, and different data codes represent different buttons; the circuit format represents the encoding protocol of the infrared signal, and each protocol has special instructions. Format. For example, the circuit 61212 represents the NEC6121 protocol. The infrared signal encoding format of this protocol is: boot code + user code + data code + data inverse code + end code, where the boot code and end code are fixed, and the data inverse code is determined by The data code is obtained by inverting the bits, and only the user code and the data code are really changed.
However, the user code and data code obtained by the decoder cannot be directly written in the code, because the code on the LCD screen is actually a hexadecimal number, which needs to be converted into a binary number. For example, user code 4055, the corresponding binary number is 0100 0000 0101 0101; data code 44, the corresponding binary number is 0100 0100, and the binary number obtained by bit inversion is 1011 1011.
However, in the aforementioned transmit method, the parameter should pass a signal in the form of an integer array, not a binary number, which means that the binary number has to be converted into an integer array. So what data is stored in the integer array? This starts with the level in the digital circuit. Level is the abbreviation of "voltage platform", which refers to the high and low state of the voltage at a certain point in the circuit. In digital circuits, a high level is often used to represent "1", and a low level is used to represent "0". When the remote control transmits the infrared signal, "1" is represented by "560 microsecond low level + 1680 microsecond high level", and "0" is represented by "560 microsecond low level + 560 microsecond low level". So when writing Android code, use "560,1680" to represent binary 1, and use "560,560" to represent binary 0. Here 560 and 1680 are only approximate values. You can also use 580, 600 to replace 560, or use 1600 , 1650 to replace 1680.
According to the level rules of digital circuits, the binary number corresponding to user code 4055 is 0100 0000 0101 0101, and when converted into a level signal, it becomes "560, 560, 560, 1680, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560 , 560,1680, 560,560, 560,1680, 560,560, 560,1680, 560,560, 560,1680, ”, the level signal of data code 44 and its inverse code and so on. Coupled with the fixed boot code "9000,4500" of the NEC protocol, and the end code "560,20000", the infrared signal integer array of the previous clean key can be obtained. The specific array values ​​are as follows:

int[] pattern = {9000,4500, // 开头两个数字表示引导码
    // 下面两行表示用户码
    560,560, 560,1680, 560,560, 560,560, 560,560, 560,560, 560,560, 560,560,
    560,560, 560,1680, 560,560, 560,1680, 560,560, 560,1680, 560,560, 560,1680,
    // 下面一行表示数据码
    560,560, 560,1680, 560,560, 560,560, 560,560, 560,1680, 560,560, 560,560,
    // 下面一行表示数据反码
    560,1680, 560,560, 560,1680, 560,1680, 560,1680, 560,560, 560,1680, 560,1680,
    560,20000}; // 末尾两个数字表示结束码

Then, substitute the above signal format array into the App code, that is, call the transmit method to pass the format parameters. The example is as follows:

    // 普通家电的红外发射频率一般为38KHz
    cim.transmit(38000, pattern);

When I ran the test app, I found that no matter how many times the infrared signal was sent from the mobile phone, the sweeping robot was dumbfounded and did not respond at all. What's going on here? The secret is that the NEC protocol only specifies the general coding rules, and the actual remote control signal is slightly adjusted within the overall rules. The decoder mentioned above is not only an after-sales testing instrument for home appliances, but also a debugging tool for App developers. Pick up the mobile phone and aim it at the receiving window on the front of the decoder, click the button to send the infrared signal, and the decoder synchronously displays the analyzed signal data, as shown in the following figure:

As can be seen from the above figure, the infrared signal sent by the mobile phone at this time conforms to the NEC6121 protocol, but the user code becomes 02AA and the data code becomes 22. Translate these two code numbers into binary, then the user code 02AA is converted into 0000 0010 1010 1010, and the data code 22 is converted into 0010 0010. Go back and compare the decoded data of the remote control, the user code 4055 sent by the remote control corresponds to 0100 0000 0101 0101, and the data code 44 corresponds to 0100 0100. It seems that the difference between the signal of the mobile phone and the remote control should be that every two hexadecimal numbers are first converted into binary numbers, and then arranged in reverse, which is the so-called reverse encoding.
It is easy to find the crux of the problem. In mathematics, there is a negative and a positive, and in coding, there is a reverse and a smooth. Since 4055 becomes 02AA after reverse encoding, then 02AA must be 4055 after reverse encoding, so the level signal of user code 02AA and data code 22 is constructed again. The changed infrared signal data is as follows:

int[] pattern = {9000,4500, // 开头两个数字表示引导码
    // 下面两行表示用户码
    560,560, 560,560, 560,560, 560,560, 560,560, 560,560, 560,1680, 560,560,
    560,1680, 560,560, 560,1680, 560,560, 560,1680, 560,560, 560,1680, 560,560,
    // 下面一行表示数据码
    560,560, 560,560, 560,1680, 560,560, 560,560, 560,560, 560,1680, 560,560,
    // 下面一行表示数据反码
    560,1680, 560,1680, 560,560, 560,1680, 560,1680, 560,1680, 560,560, 560,1680,
    560,20000}; // 末尾两个数字表示结束码

Recompile and run the test app, the phone is still aimed at the decoder, and then click the button to emit infrared signals, the decoder finally displays the user code 4055 and data code 44 normally. At this time, point the mobile phone at the sweeping robot, click the launch button, and the robot actually turns. So far, the infrared code of the clean key of the remote control has been officially deciphered, and the infrared signal codes of other buttons and other remote control devices of home appliances can be deciphered by the decoder.
Of course, the above infrared signal analysis methods are limited to the NEC protocol whose coding rules are widely disclosed. For circuit protocols whose formats are unknown, they can only be analyzed with the help of a more professional single-chip microcomputer. It is said that the developer picks up the circuit board and works as an electrician and a code farmer at the same time. There are many types and brands of household appliances that use infrared remote control. The predecessors have done a lot of signal deciphering work on them. For the known infrared signal data, please refer to the website http://www.remotecentral.com/cgi-bin/ codes/, which includes the signal codes of major foreign home appliance brands, interested readers can refer to.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325338838&siteId=291194637