Ir barrier arduino modulated signal. Arduino - working with IR signals - TSOP22 receiver (recording IR signal). Data transfer with protocol specification

  • Input voltage: 4.0 ... 5.5 V (5 V nominal)
  • Current consumption: up to 100 mA in pulse mode (at Vcc = 5 V)
  • Light wavelength: 940 nm ( peak value)
  • Maximum signal frequency: up to 10 MHz
  • Transmission distance: up to 10m (at Vcc=5V)
  • Operating temperature: -25 … 85 °C
  • Directional angle: 120° (with power loss< 50%)

All modules of the "Trema" line are made in the same format

Connection:

It is convenient to connect the module in 3 ways, depending on the situation:

Method - 1: Using a wired cable and Piranha UNO

The library uses a second hardware timer,

DO NOT OUTPUT PWM SIGNALS TO 3 OR 11 OUTPUT!

Read more about installing the library in our...

Additional information on working with the module:

Packages: Almost all remotes send not only an information packet (indicating the type of device and the code of the pressed button), but also repeat packets telling the device that the button was held down. Thus, the receiving device can respond to pressing the button once or during the entire time it is held.
For example: by pressing and holding a button with a TV channel number, the TV will switch to that channel only once. While pressing and holding the volume up button, the TV will increase it for the entire time you hold the button.

Number of information packages Most remote controls have one, but some devices, such as air conditioners, use 2, 3 or more information packets.

Package contents: The information package contains information about the manufacturer's code, device type, code of the button pressed, etc. Repeat packets can partially or completely coincide with an information packet, copy its bits with inversion, or not carry any information, representing a sequence of several identical bits for each repeat packet.

Duration of pauses between packets: usually does not exceed 200ms.

Data transfer protocols: determine the following basic parameters:

Carrier frequency: for most remote controls it is 38 kHz; it is this frequency that the Trema IR receiver is tuned to.

Information coding: This is the principle of transmitting data bits. We distinguish three main types of encoding, in which each bit is transmitted by a sequence of one pulse and one pause:

Start, Stop and Toggle signals: by their name are located at the beginning, end or middle of the package.

Stop: When encoding a long pause, it is impossible to determine the value of the last bit in the packet, since the packet is followed by a long pause, and the last bit will always be defined as “1”, so the Stop signal is added to the packet, which is a pulse that does not carry any information.

Start: With biphase coding, a Start signal is required, since it is impossible to start transmitting a packet from a pause.

Toggle: This is a bit that changes its value with each new button press, used in the RS5, RS5X, RS6 (Philips) protocols, where repeat packets completely repeat the data of the information packet. This way, the receiving device can differentiate between holding the button and pressing it again.

pulse length encoding- first a pulse is transmitted, the length of which depends on the value of the transmitted bit, followed by a pause, the length of which does not depend on the value of the bit. For example: in the SIRC protocol (Sony), the pulse length for bit “1” = 1200 µs, and for bit “0” = 600 µs, the length of pauses is always 600 µs. Thus, it is possible to distinguish "1" from "0" by the length of the pulse.

pause length encoding- first a pulse is transmitted, the length of which does not depend on the value of the transmitted bit, followed by a pause, the length of which depends on the value of the bit. For example: in the NEC protocol, the pause length for bit “1” = 1687.5 µs, and for bit “0” = 562.5 µs, the pulse length is always 562.5 µs. Thus, it is possible to distinguish "1" from "0" by the length of the pause.

biphasic coding- the length of the pulse is equal to the length of the pause, and their sequence determines the type of transmitted bit. For example: in the RS5 protocol (Philips), for bit "1" a pulse follows a pause, and for bit "0" a pause follows a pulse. For the NRC protocol (Nokia), on the contrary, for bit “1” a pause follows a pulse, and for bit “0” a pulse follows a pause.

Examples:

One-time data transfer:

#include // Connect the library to work with the IR transmitter iarduino_IR_TX VD(10); // Declare a VD object, indicating the pin to which the IR transmitter is connected void setup())( VD.begin(); // Initiate work with the IR transmitter VD.send(0x00FFA25D); // Send code 0x00FFA25D once, without packets repeats ) void loop()() // Arduino will send code 0x00FFA25D, signaling that it is turned on

Data transmission with retry packets:

#include // Connect the library to work with the IR transmitter iarduino_IR_TX VD(2); // Declare the VD object, indicating the pin to which the IR transmitter is connected void setup())( pinMode(3,INPUT); // Configure pin 3, to which the button is connected, as an input pinMode(4,INPUT); // Configure 4 pin, to which the button is connected, as an input pinMode(5,INPUT); // Configure pin 5, to which the button is connected, as an input VD.begin(); // Initiate work with the IR transmitter ) void loop())( if(digitalRead(3))(VD.send(0x00FFA25D, true);) // If the button connected to pin 3 is pressed, then we send code 0x00FFA25D, and when it is held down, we send repeat packets, since the function was called with the true parameter if(digitalRead(4))(VD.send(0x00FF629D, true);) // If the button connected to pin 4 is pressed, then we send code 0x00FF629D, and when it is held down, we send repeat packets, since the function was called with the true parameter if(digitalRead(5))(VD.send(0x00FFE21D, true);) // If the button connected to pin 5 is pressed, then we send the code 0x00FFE21D, and when it is held down, we send repeat packets, since the function was called with the true parameter )

Data transfer indicating the protocol:

#include // Connect the library to work with the IR transmitter iarduino_IR_TX VD(5); // Declare the VD object, indicating the pin to which the IR transmitter is connected void setup() ( VD.begin(); // Initiate work with the IR transmitter pinMode(6,INPUT); // Configure pin 6 to which the button as input pinMode(7,INPUT); // Configure pin 7, to which the button is connected, as input pinMode(8,INPUT); // Configure pin 8, to which the button is connected, as input VD.protocol("AeQQV ~zK]Kp^KJp[@@@@@@@Bp"); // Specify the data transfer protocol from the ELENBERG remote control) // You can get the protocol line by pressing any button on the TV remote control // and calling the receiver function of the same name, without parameters void loop())( if(digitalRead(4))(VD.send(0x417, true);) // send an ON/OFF signal (with packets of repetitions, packets are repeated after a time interval specified in the protocol) if(digitalRead(5) )(VD.send(0x425, true);) // send the VOL- signal (with repeat packets, packets are repeated after the time interval specified in the protocol) if(digitalRead(6))(VD.send(0x427);) // send a VOL+ signal (without repeat packets, the volume will increase faster, since the function is called in a loop without intervals) )

This example shows how the transmitter can completely simulate the signals of other IR remote controls.

The resulting protocol string must be passed as a parameter to the protocol() function, after which you can send button codes using the send() function. As a result, devices will respond to the IR transmitter as if they were responding to their own IR remote control.

Description of the main functions of the library:

Connecting the library:

#include // Connect the library to work with the IR transmitter. iarduino_IR_TX VD(PIN_NO[,INVERSION]); // Declare a VD object, indicating the pin number to which the IR transmitter is connected. // The second parameter, of type bool, can indicate that the data to the transmitter needs to be inverted.

Function begin();

  • Purpose: initialization of work with the IR transmitter
  • Syntax: begin();
  • Options: No.
  • Return values: None.
  • Note: Called once in setup code.
  • Example:
VD.begin(); // Initiate work with the IR transmitter

Function send();

  • Purpose: Data transfer.
  • Syntax: send(DATA [, HOLD ]);
  • Options:
    • DATA - code, such as uint32_t, that needs to be transmitted;
    • HOLD - an optional parameter, type bool - indicating that it is necessary to transmit not only the code, but also retry packets. The parameter makes sense if the function is called while the button is held down.
  • Return values: None.
  • Note: If the function is called without the HOLD parameter, or it is equal to false, then the function, each time it is called, will transmit the specified code once. If the function is called with the HOLD parameter equal to true, then the function debounces the button and sends retry packets (at the interval specified in the protocol) when it is held.
  • Example:
VD.send(0xCCDDEEFF); // Send code 0xCCDDEEFF. If the function is called constantly, in a loop, then it will send this code every time. VD.send(0xCCDDEEFF, true); // Send code 0xCCDDEEFF. If the function is called constantly, in a loop, then it will send the code only the first time, and then it will send repeat packets in accordance with the specified data transfer protocol.

Function protocol();

  • Purpose: Setting the data transfer protocol.
  • Syntax: protocol(STRING);
  • Options:
    • LINE - consisting of 25 protocol characters + end-of-line character. This string can be obtained by calling the function of the same name, without parameters, for the receiver.
  • Return values: bool - the string contains correct protocol data or not.
  • Note: The function sets the communication protocol, so the IR transmitter can imitate the signals of conventional remotes. After calling this function, data transmission by the send() function will be carried out using the new protocol. The default data transfer protocol corresponds to the “Car mp3” remote control.
  • Example:
VD.protocol("AeQQV~zK]Kp^KJp[@@@@@@@Bp"); // Specify the data transfer protocol from the ELENBERG remote control. // Now the transmitter will send data encoded according to the specified protocol. // Get the protocol string by pressing any button on the TV remote and calling the function of the same name for the IR receiver, without parameters.

Frequency variable:

  • Value: Sets the carrier frequency of data transmission in kHz;
  • Data type: uint8_t;
  • Note: If the variable is not assigned a value, then the transmission is carried out at the frequency specified in the protocol. If you specify a value of 0, then data will be transmitted without modulation.
VD.frequency=36; // Set the carrier frequency for data transmission to 36 kHz. VD.send(0xCCDDEEFF); // Send data with a carrier frequency of 36 kHz. VD.send(0xABCDEF); // Send data with a carrier frequency of 36 kHz. // The carrier frequency will be changed by setting a new value for the frequency variable, or setting a new data transfer protocol by calling the protocol() function.

Application:

  • control of robots, moving, flying and floating models, household and specialized appliances.
  • turning on/off lighting, heating, ventilation, watering, etc.
  • opening/closing doors, blinds, roof windows, vents, etc.

Every home has a TV remote control, or other remote control (remote control). This device allows you to remotely control any device, which is very convenient. There is no need to waste precious calories and make unnecessary movements. If you have some kind of device and would like to control it from a distance, then you can do remote control this device. If you wish, you can also make a remote control with your own hands, but this is not necessary and that's another story. Why might you need remote control?! - it's simple:

Laziness is a quality that makes one make great efforts to reduce the overall energy costs.

For the first time, remote control in action was shown to the world by inventor Nikola Tesla; in 1898, at an exhibition in Madison Square Garden, he presented a radio-controlled boat called “teleautomatic”. Today, this technology has become widespread, only more different ways transmission of commands (communication channel).

The main communication channels include:

  • Radio channel
  • Ultrasonic
  • Infrared

In this article we will talk about controlling the device with an infrared remote control. Infrared radiation - electromagnetic radiation, occupying the spectral region between the red end of visible light and microwave radiation. Infrared radiation is not visible to the human eye, but can be seen with a camera or video camera. This is often how they check the functionality of the TV remote control at home.

How long ago old job I took the remote control and the “peephole” (IR receiver) from the security system that was being written off, it lay idle for a long time and finally I got around to checking it in operation.

Having disassembled this receiver, I saw some trick; in this “eye” 4 IR receivers were soldered together. This was done in order to receive IR waves from four sides. And it’s convenient, you don’t need to limit yourself to a certain reception angle.

I also sketched out a similar circuit with four receivers, in case I need it. I used TSOP1836 IR receivers, but you can use others. To ensure 360-degree reception, you need to select appropriate IR receivers (with a wide reception angle) and place them as close as possible to each other. I didn't notice any reception problems with my receivers. I also added it to the attachment printed circuit board and arrangement of elements.

To process commands I will naturally use arduino uno; I can use an IR receiver
TSOP34836 (has a high reception range, but is more expensive) or TL1838. You can take any IR remote control, even from a TV. Well, if you need your own remote control, you can buy a kit for arduino.

Principle of operation:
When you press a button on the remote control, it sends the button code to infrared light, after which the receiver receives this button code and sends it to the actuator, which, depending on the button, will perform a certain action.

You can also use infrared waves to transmit information over a short distance. To transfer your commands or information, you can use a second arduino with an IR transmitter. But the speed of such transmission is very slow. The advantages of the infrared channel include insensitivity to electromagnetic interference.

To receive arduino IR signals, we will connect the IR receiver as follows:

Please note that the location of the receiver legs may vary.


The receiver has 3 legs, “+” and “-” power supply (mainly voltage 3.3-5V) and the data leg is the one that transmits information to the device (in our case, arduino). The supply voltage for TSOP34836 is 2.7-5.5 volts. I will use 5 volts from the standard arduino output.

Well, of course you need firmware for arduino. The operation algorithm will be as follows: when you press the top button arduino remote control turns on the relay, and when pressed again turns it off. Using this relay, you can power, for example, the backlight, but it is not necessary to program the button press on the relay, you can output a command to the computer or perform a certain operation in arduino, etc.
To simplify the work, we will use a ready-made library. Firmware code:

#include int RECEIVE_PIN = 11;//receiver pin int RELAY_PIN = 3;//relay contact IRrecv irrecv(RECEIVE_PIN);//assign receiver pin decode_results results;//received data

void setup() (
Serial.begin(9600);
irrecv.enableIRIn(); // turn on the receiver
pinMode(RELAY_PIN, OUTPUT); // configure the relay for output
digitalWrite(RELAY_PIN,HIGH); //set the value high
}

void loop() (
if (irrecv.decode(&results)) (//if data is received
Serial.print("0x");
Serial.println(results.value, HEX);//output the received message to the terminal
if ((results.value == 0x8FF40BF) ||(results.value == 0xD72040BF)) digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN));//if the button code is 0x8FF40BF or 0xD72040BF, change the relay state to the opposite
delay(200); // delay from double triggering
irrecv.resume();// Get the next value
}
}

Let me explain a little with the sketch:



if ((results.value == 0x8FF40BF) ||(results.value == 0xD72040BF))

The resulting value is compared with "0x8FF40BF" and "0xD72040BF" - these are button codes in hexadecimal. Two meanings only because I use two remote controls with unique codes.



digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN));

Standard procedure for digital pin recording except for "!digitalRead(RELAY_PIN)". Sign "!" stands for inversion, in our case the inversion of the state of the digital output "RELAY_PIN".



Serial.print("0x");
Serial.println(results.value, HEX);//output the received message to the terminal

These lines output all received codes to the terminal. IN work program this is unnecessary, but you need to find out required code one button or another. That is, first we load the sketch into arduino, go to the terminal and by clicking on the button we get the desired code.


Also in the IRremote library there are several different examples, which may be useful.


In the attachment to the article:


  • sketch for arduino

  • PCB for 4 sensors

Today's article will look at connecting the TSOP34836 IR receiver to an Aduino UNO board. For these purposes, you can use any receiver you have that is compatible with your remote control in frequency. The assignment of the pins is shown in the figure.

1. Vout – receiver output.
2. GND – “ground”, common wire.
3. Vcc – power supply.
Data transmission from the IR remote control to the receiver is carried out according to the RC5 protocol, which is a sequence of pulses. The connection is made according to the following diagram.

And having collected, we get something like this:

To process the data transmitted by the remote control, we use the IRremote library, this library is attached to the article. Paste the following code:

#include "IRremote.h" IRrecv irrecv(11); // Specify the pin to which the receiver is connected decode_results results; void setup() ( Serial.begin(9600); // Set COM port speed irrecv.enableIRIn(); // Start receiving ) void loop() ( if (irrecv.decode(&results)) // If data has arrived ( Serial .println(results.value, HEX); // Send the received data to the console irrecv.resume(); // Accept the following command ) )

Now in the COM port console you can see the code of the pressed key in HEX.


That's all, now you can use this circuit in your devices. Below is an example of one practical applications IR receiver.

As a demonstration, I will show you how to control the servo using the IR remote control.

Device diagram:

This is what it should look like:

To operate the device we use the following code:

#include "Servo.h" #include "IRremote.h" IRrecv irrecv(11); decode_results results; Servo servoMain; int servPoz = 90; //Initial position of the servo int lastPoz = 0; void setup() ( irrecv.enableIRIn(); servoMain.attach(10); // Servo is attached to pin 10 servoMain.write(servPoz); ) void loop() ( if (irrecv.decode(&results)) ( int res = results.value; Serial.println(res, HEX); if(res==0xFFFF906F) // If the "+" button is pressed ( lastPoz=res; servPoz++; servoMain.write(servPoz); ) else if(res== 0xFFFFA857) // If the "-" button is pressed ( servPoz--; lastPoz=res; servoMain.write(servPoz); ) else if(res==0xFFFFFFFF) // If the button is held ( if(lastPoz==0xFFFF906F) servPoz++; // Hold "+" if(lastPoz==0xFFFFA857) servPoz--;// Hold "-" servoMain.write(servPoz); ) irrecv.resume(); delay(100); ) )

The remote control used is some kind of Chinese, when you press “+” the servo rotates in one direction, when you press “-” it rotates in the other.

An IR receiver and infrared remote control are the most common and easiest way to control electronic equipment. The infrared radiation spectrum is not visible to the human eye, but it is perfectly received by IR receivers that are built into electronic devices. Arduino ir remote modules are used to control various equipment in line of sight.

The widespread use of IR emitters has become possible due to their low cost, simplicity and ease of use. IR radiation lies in the range from 750 to 1000 microns - this is the closest part of the spectrum to visible light. In the region of infrared radiation, the optical properties of various materials can change. Some glasses, for example, become opaque to IR rays, while paraffin, on the contrary, is transparent in the IR spectrum.

Radiation is recorded using special photographic materials, on the basis of which receivers are made. In addition to heated bodies (the Sun, incandescent lamps or candles), the source of infrared radiation can be solid-state devices - IR LEDs, lasers. Radiation in the infrared range has a number of features that make them convenient to use in remote controls:

  • Solid state emitters (IR LEDs) are cheap and compact.
  • Infrared rays are not perceived or detected by the human eye.
  • IR receivers are also cheap and small in size.
  • Low interference since the transmitter and receiver are tuned to the same frequency.
  • Absent Negative influence on human health.
  • High reflectance from most materials.
  • IR emitters do not affect the operation of other devices.

The remote control works as follows. When the button is pressed, the signal is encoded in infrared light, the receiver receives it and performs the required action. Information is encoded as a logical sequence of bursts of pulses with a certain frequency. The receiver receives this sequence and demodulates the data. To receive a signal, a microcircuit is used, which contains a photodetector (photodiode), amplifiers, band pass filter, a demodulator (a detector that allows you to highlight the signal envelope) and an output transistor. It also has filters – electrical and optical. Such devices operate at a distance of up to 40 meters. The IR method of data transmission exists in many devices: in household appliances, industrial equipment, computers, fiber optic lines.

IR receiver Arduino

To read the IR signal you will need the Arduino board itself, a breadboard, an IR signal receiver and jumpers. There are a huge variety of different receivers, but it is better to use TSOP312 or others suitable for Arduino. Data from the remote control to the receiver can be transmitted via the RC5 or NEC protocol.

To determine which leg belongs to what, you need to look at the sensor from the receiver side. Then on the receiver the central contact is ground, on the left is the output to the microcontroller, on the right is power.

For convenience, you can use ready-made IR receiver modules.

Connecting the IR receiver to Arduino

The IR receiver outputs are connected to the Arduino to the GND, 5V and digital input ports. The diagram for connecting the sensor to the 11th digital pin is shown below.

This is what the circuit with the infrared receiver module looks like:


Libraries for working with IR

To work with IR devices, you can use the IRremote library, which simplifies the construction of control systems. You can download the library. After downloading, copy the files to the \arduino\libraries folder. To connect to your library sketch, you need to add the header file #include .

To read information, use the IRrecvDumpV2 example from the library. If the remote control already exists in the list of recognized ones, then scanning is not required. To read codes you need to run ARduino environment IDE and open the IRrecvDemo example from IRremote.

There is a second library for working with IR signals - this is IRLib. It is similar in functionality to the previous one. Compared to IRremote, IRLib has an example for determining the frequency of an IR sensor. But the first library is simpler and more convenient to use.

After loading the library, you can start reading the received signals. The following code is used for this.

The decode_results operator is needed to assign the variable name results to the received signal.

In the code you need to rewrite "HEX" to "DEC".

Then, after loading the program, you need to open the serial monitor and press the buttons on the remote control. Various codes will appear on the screen. You need to make a note indicating which button the received code corresponds to. It is more convenient to record the obtained data in a table. This code can then be written into the program so that the device can be controlled. The codes are written into the memory of the Arduino EEPROM board itself, which is very convenient, since you don’t have to program the buttons every time you turn on the remote control.

It happens that when loading a program, the error “TDK2 was not declared In his scope” is displayed. To fix it, you need to go to Explorer, go to the folder in which the Arduino IDE application is installed and delete the files IRremoteTools.cpp and IRremoteTools.h. After this, you need to reload the program onto the microcontroller.

Conclusion

Using Arduino ir remote makes life easier for the user. Can act as a remote control mobile phone, tablet or computer - you just need special software for this. Using Arduino you can centralize all control. With one button on the remote control you can perform several actions at once - for example, turn on the TV and Blu-Ray at the same time.

The IR Receiver module in combination with an IR remote control will allow you to easily implement remote control of the Arduino board.

It is nothing more than a VS1838B IR receiver with the manufacturer’s recommended harness installed on the board.

To work with this module out of the box, you need a remote control with a frequency of 38 kHz.

The advantage of this board is the push-in connector, which allows you to replace the IR receiver with another one operating at the frequency required for your project without soldering.

Main technical characteristics:

Supply voltage: 2.7 - 5.5V

Modulation frequency: 38kHz

Temperature range: - 20 ... + 80°C

Interface: Digital

Connecting to Arduino

The module is equipped with a three-pin 2.54mm connector

: connects to GND pin

: connects to +5V output

: connects to digital pin (D2 in example)

An example of working in the Arduino environment

To work with this module you need to install the IRRemote library

Download, unpack and put it in the libraries folder in the Arduino folder. If the Arduino IDE was open at the time of adding the library, reboot the environment.

Reading remote control buttons

To read the remote control readings, fill in the sketch below. It will output the encoding of the pressed buttons to the port.

As an example, we will use the remote control, as in the picture, because This type of remote control is included in the set

You can read about the differences in the operating logic of various remote controls in the original article from a member of our community under the nickname

Sample code:

#include int RECV_PIN = 2; IRrecv irrecv(RECV_PIN); //Create an object for receiving a signal from a specific port decode_results results; //Variable storing the result void setup () { Serial // Start receiving) void loop() ( if (irrecv.decode(&results)) //When receiving a signal... { Serial.println(results.value); //...output its value to the serial port irrecv.resume(); ) )

You should see the following in the port monitor:

By holding each button for almost a second, we get about 10 codes. The first one is the button code. And after it, a standard code begins to appear, which reports that the button is stuck.

Controlling Arduino board with remote control

Let's make the LED on the Arduino board (D13) light up when the first button is encoded and turn off when the second button is encoded.

Sample code:

// Tested on Arduino IDE 1.0.3#include int RECV_PIN = 2; int LED = 13; IRrecv irrecv(RECV_PIN); decode_results results; void setup () { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver pinMode(LED, OUTPUT); ) void loop() ( if (irrecv.decode(&results)) ( Serial.println(results.value); if (results.value == 16769565) // When receiving encoding 1( digitalWrite(LED, HIGH); // Turn on the LED) if (results.value == 16761405) // When receiving encoding 2( digitalWrite(LED, LOW); // Turn off the LED) irrecv.resume(); // Get the next value } }

If you find an error, please select a piece of text and press Ctrl+Enter.