Controlling arduino with IR remote control. Control your Arduino with a remote control IR receiver arduino mega wiring diagram

There are many articles on the Internet about how to make your own TV remote control using Arduino, but I needed a universal remote control to control my TV and media player. The main advantage of my universal remote control is that the buttons in the Android phone application are dual-purpose, but look at the video.



The remote control is very convenient in that almost the same buttons on the screen are used to control the TV and player. One difference is that the " AV"in TV control mode changes to a button" " (stop) when switching to the player control mode. The pictures show two modes, on the left is the TV control mode, on the right is the player control mode.

Well, now I’ll tell you a little about creating such a remote control. For the device I used the remote control for the ERGO TV and the remote control for the DUNE HD TV101W media player.

To receive data from the remote controls, I used an infrared sensor TSOP1138 (analogous to TSOP4838) at an operating frequency of 38 kHz and connected it to the Arduino board according to the scheme:

This sketch will not be needed to determine the encoding of data transmission and read the code of the remote control buttons.

In the sketch in the line int RECV_PIN = 11; indicate our pin number 4

After uploading the sketch, open the “port monitor” and, pressing the remote control buttons, look at the received data.

The picture shows an example of scanning the power button from the TV remote control and the player remote control. Now we create a table for button codes.

I got it like in the photo above. Under the inscription TV TV remote control button codes; under the inscription Player- codes from the media player remote control.

Now we disconnect our infrared signal receiver from the Arduino board and connect the HC-05 Bluetooth module and an infrared LED to it according to the diagram in the photo.

After that, we move directly to the sketch.

Sketch

#include IRsend irsend; int y = 1; void setup() ( Serial.begin(9600); ) void loop() ( if (Serial.available() > 0) ( int x = Serial.read(); if (x == 49) ( y = 1; ) if (x == 50) ( y = 2; ) if (y == 1) ( // button codes for the TV remote if (x == 97) ( irsend.sendNEC(0x807F08F7, 32); delay(40 ); ) if (x == 98) ( irsend.sendNEC(0x807FA857, 32); delay(40); ) if (x == 99) ( irsend.sendNEC(0x807F708F, 32); delay(40); ) if (x == 100) ( irsend.sendNEC(0x807FF00F, 32); delay(40); ) if (x == 101) ( irsend.sendNEC(0x807F30CF, 32); delay(40); ) if (x == 102) ( irsend.sendNEC(0x807FB04F, 32); delay(40); ) if (x == 103) ( irsend.sendNEC(0x807F9867, 32); delay(40); ) if (x == 104) ( irsend .sendNEC(0x807F58A7, 32); delay(40); ) if (x == 105) ( irsend.sendNEC(0x807FD827, 32); delay(40); ) if (x == 106) ( irsend.sendNEC(0x807F38C7 , 32); delay(40); ) if (x == 107) ( irsend.sendNEC(0x807F48B7, 32); delay(40); ) if (x == 108) ( irsend.sendNEC(0x807FB847, 32); delay(40); ) if (x == 109) ( irsend.sendNEC(0x807F6897, 32); delay(40); ) ) if (y == 2) ( //codes of the media player remote control buttons if (x == 97) ( irsend.sendNEC(0xFDC23D, 32); delay(40); ) if (x == 98) ( irsend. sendNEC(0xFDE01F, 32); delay(40); ) if (x == 99) ( irsend.sendNEC(0xFD18E7, 32); delay(40); ) if (x == 100) ( irsend.sendNEC(0xFDE817, 32); delay(40); ) if (x == 101) ( irsend.sendNEC(0xFDA857, 32); delay(40); ) if (x == 102) ( irsend.sendNEC(0xFD6897, 32); delay (40); ) if (x == 103) ( irsend.sendNEC(0xFDA857, 32); delay(40); ) if (x == 104) ( irsend.sendNEC(0xFD6897, 32); delay(40); ) if (x == 105) ( irsend.sendNEC(0xFDE817, 32); delay(40); ) if (x == 106) ( irsend.sendNEC(0xFD18E7, 32); delay(40); ) if (x == 107) ( irsend.sendNEC(0xFD9867, 32); delay(40); ) if (x == 108) ( irsend.sendNEC(0xFD28D7, 32); delay(40); ) if (x == 109) ( irsend.sendNEC(0xFD20DF, 32); delay(40); ) ) ) )


In the sketch you will need to edit the button codes, namely in the lines:

If (x == 97) ( irsend.sendNEC(0x807F08F7, 32); delay(40);
Change the value 807F08F7 to:

If (y == 1) ( //button codes for the TV remote control if (x == 97) ( irsend.sendNEC(0x12345678, 32); delay(40); )
Where 12345678 is the code for your button.

After editing the sketch using your button codes, upload the sketch to the Arduino board and proceed to installing the application on your phone.

We turn on Bluetooth in the phone, look for our device, create a pair, then launch the application Pult on the phone.

Upon startup we will have a screen with a red bluetooth icon in the lower right corner, which signals that we are not connected to our device.

After that, click on this icon. We should see a window with a list of all available bluetooth devices, where we select our device to connect.

Now we are back on the main screen and can already control the TV:

To switch to control mode we need to press the button labeled "Player". As I said earlier, our button labeled "AV" will change to a button " ":

To disconnect from our device, simply hold down the “Power” button for a few seconds.

Well, a few photos of my finished device.

It turned out quite well, it seems. I'm waiting for comments on the article.

An infrared remote control is one of the easiest ways to interact with electronic devices. So, almost every home has several such devices: a TV, a stereo system, a video player, an air conditioner. But the most interesting use of an infrared remote control is remote control of a robot. Actually, in this lesson we will try to implement this control method using the popular Arduino Uno controller.

1. IR remote control

What does it take to teach a robot to obey an infrared (IR) remote control? First, we need the remote control itself. You can use a regular TV remote control, or you can purchase a miniature remote control for your car radio. These types of remote controls are often used to control robots. This remote control has 10 digital buttons and 11 buttons for manipulating music: volume, rewind, play, stop, etc. More than enough for our purposes.

2. IR sensor

Secondly, to receive a signal from the remote control we need a special IR sensor. In general, we can detect infrared radiation with a conventional photodiode/phototransistor, but unlike it, our IR sensor perceives infrared signal only at a frequency of 38 kHz (sometimes 40 kHz). It is this property that allows the sensor to ignore a lot of extraneous light noise from lighting lamps and the sun. For this tutorial we will use the popular IR sensor VS1838B, which has the following characteristics:
  • carrier frequency: 38 kHz;
  • supply voltage: 2.7 - 5.5 V;
  • current consumption: 50 µA.
Other sensors can be used, for example: TSOP4838, TSOP1736, SFH506.

3. Connection

The sensor has three leads (three legs). If you look at the sensor from the IR signal receiver side, as shown in the figure,
  • then on the left there will be an output to the controller,
  • in the center - negative power contact (ground),
  • and on the right - the positive power contact (2.7 - 5.5V).
Schematic diagram of connection Layout appearance

4. Program

Having connected the IR sensor, we will write a program for Arduino Uno. To do this, we will use the standard library IRremote, which is designed specifically to simplify the work with receiving and transmitting IR signals. Using this library, we will receive commands from the remote control, and to begin with, simply display them in the serial port monitor window. This program will be useful to us in order to understand what code each button gives. #include "IRremote.h" IRrecv irrecv(2); // indicate the pin to which the receiver is connected decode_results results; void setup() ( Serial.begin(9600); // set the speed of the COM port irrecv.enableIRIn(); // start receiving ) void loop() ( if (irrecv.decode(&results)) ( // if data arrived Serial .println(results.value, HEX); // print the data irrecv.resume(); // accept the following command ) ) Load the program onto the Arduino. After that, we try to receive commands from the remote control. Open the serial port monitor (Ctrl+Shift+M), pick up the remote control, and point it at the sensor. By pressing different buttons, we observe the codes corresponding to these buttons in the monitor window. Problem loading the program In some cases, when trying to load a program into the controller, an error may appear: TDK2 was not declared In his scope To fix it, just delete two files from the library folder. Let's go to the explorer. Go to the folder where the Arduino IDE application is installed (most likely “C:\Program Files (x86)\Arduino”). Then to the library folder: …\Arduino\libraries\RobotIRremote, and delete the files: IRremoteTools.cpp And IRremoteTools.h. Then, we restart the Arduino IDE and try to load the program onto the controller again.

5. Control the LED using the IR remote control

Now that we know which codes correspond to the remote control buttons, we try to program the controller to turn on and turn off the LED when the volume buttons are pressed. To do this we need codes (may vary depending on the remote control):
  • FFA857 - increase volume;
  • FFE01F - decrease volume.
As an LED, we use the built-in LED on pin No. 13, so the connection diagram will remain the same. So, the program: #include "IRremote.h" IRrecv irrecv(2); // indicate the pin to which the receiver is connected decode_results results; void setup() ( irrecv.enableIRIn(); // start receiving ) void loop() ( if (irrecv.decode(&results)) ( // if data arrived switch (results.value) ( ​​case 0xFFA857: digitalWrite(13, HIGH); break; case 0xFFE01F: digitalWrite(13, LOW); break; ) irrecv.resume(); // accept the following command ) ) Upload to Arduino and test. Click vol+— the LED lights up. Click vol-- goes out. Now, knowing how it all works, you can control robot motors or other homemade microelectronic devices instead of an LED!

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 } }

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

1. Vout – receiver output.
2. GND – “ground”, common wire.
3. Vcc – power supply.
Data transfer from the IR remote control to the receiver is carried out using 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 the speed of the COM port irrecv.enableIRIn(); // Start receiving ) void loop() ( if (irrecv.decode(&results)) // If data arrived ( Serial .println(results.value, HEX); // Send the received data to the console irrecv.resume(); // Accept the next 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 of the practical applications of an IR receiver.

As a demonstration, it will be shown how to control a servo using an 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.

Recently I needed to control the TV remote control for a small project on arduino. The idea was to control the air conditioner through the arduino with temperature sensor. My air conditioner comes with a fairly convenient remote control, but we need to automate turning it on, setting the temperature and turning it off. As a result of a long search, I was able to find a solution for myself. More details about it under the cut.

How it works

Connecting IR receiver, we direct remote control to the receiver, record the signal and output it to Serial. (since this is the first part of the article, we do not consider sending a signal. We will talk about sending in the second part).

What do we need

  • Arduino(or analogues, I use Tosduino- 2 times cheaper, fully compatible with regular arduino)
  • Light-emitting diode ( LED)
  • 220 kOhm resistor
  • IR receiver from the series

Connection

IR Receiver

LED

Arduino Breadboard Arduino
pin number 11 resistor 220 kOhm GND (GrouND)

IR technology

The cheapest way to remotely control a device within visible reach using infrared radiation. Almost all audio and video equipment can be controlled in this way. Thanks to its widespread availability, the required components are quite cheap, making this technology ideal for us who like to use IR remote control for our own projects.

Infrared radiation is actually normal light with a specific color. We humans cannot see this color because its wavelength is 950 nm, which is below the visible spectrum. This is one of the reasons why IR is chosen for telemechanics needs, we want to use it, but we are not interested in seeing it. Although we can't see the infrared light emitted from the remote control, that doesn't mean we can't make it visible.

A video camera or digital camera "sees" infrared light, as you can see in the video below. Even the cheapest cell phones have built-in cameras. Just point the remote control at such a camera, press any button, and you will see the LED flickering.

A series of miniature receivers for infrared remote control systems. The PIN diode and preamplifier are assembled on a lead frame, and are designed as IR filter. The demodulated output signal can be directly decoded by the microprocessor. - This is a standard receiver, supports all major transmission codes.

Part Carrier Frequency
30 kHZ
33 kHZ
36 kHZ
36.7 kHZ
38 kHZ
40 kHZ
56 kHZ

IRremote.h

Download library IRremote you can from my repository on Github.com

To install this library, copy the contents of the archive to: arduino-1.x/libraries/IRremote Where arduino-1.x is the folder where the Arduino IDE is installed. Then the file arduino-1.x/libraries/IRremote/IRremote.cpp should be available and IRremote.h

Example No. 1 - we get the code for the remote control button

This sketch will read the code of the button pressed on the remote control and send information about this button to the Serial port so that we can then use this code.

#include int RECEIVE_PIN = 2; IRrecv irrecv(RECEIVE_PIN); decode_results results; void setup() ( Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver ) void loop() ( if (irrecv.decode(&results)) ( Serial.print("0x"); Serial. println(results.value, HEX); delay(50); irrecv.resume();// Receive the next value ) )

I will use these button codes in all of the following examples:

Example No. 2 - assigning a name to the remote control button

Let's send the names of the buttons to the Serial port. (first we must catch the codes of these buttons and assign names to them, look at the code, I think everything will be clear there).

#include int RECEIVE_PIN = 2; IRrecv irrecv(RECEIVE_PIN); decode_results results; void setup() ( Serial.begin(9600); irrecv.enableIRIn(); ) void loop() ( if (irrecv.decode(&results)) ( switch (results.value) ( ​​case 0x77E1A0CB: Serial.println("Center "); break; case 0x77E160CB: Serial.println("Right"); break; case 0x77E190CB: Serial.println("Left"); break; case 0x77E150CB: Serial.println("Up"); break; case 0x77E130CB: Serial.println("Down"); break; ) irrecv.resume(); ) )

Example No. 3 - turn on the LED using the remote control button

Now let's teach our Arduino turn on the LED on PIN 11 via a button on the remote control

#include int LED = 11; int state = 0; // 0 = LED off while 1 = LED on int RECEIVE_PIN = 2; IRrecv irrecv(RECEIVE_PIN); decode_results results; void setup() ( Serial.begin(9600); irrecv.enableIRIn(); pinMode(LED, OUTPUT); ) void loop() ( if ((irrecv.decode(&results)) && (results.value==0x77E1A0CB) ) ( if (state == 0) ( state = 1; digitalWrite(LED, HIGH); Serial.println("Center - HIGH"); ) else ( state = 0; digitalWrite(LED, LOW); Serial.println( "Center - LOW"); ) delay(50); irrecv.resume(); ) )

Example No. 4 - PWM with remote control

Now let's control the brightness of our LED (since it is connected to port 11, which has PWM, there should be no problems). The up and down buttons on the remote control will be used to control the brightness.

#include int RECEIVE_PIN = 2; int brightness = 0; int LED = 11; IRrecv irrecv(RECEIVE_PIN); decode_results results; void setup() ( Serial.begin(9600); irrecv.enableIRIn(); ) void loop() ( if (irrecv.decode(&results)) ( switch (results.value) ( ​​case 0x77E150CB: if(brightness< 255) { brightness+=15; Serial.println(brightness); } break; case 0x77E130CB: if(brightness >0) ( brightness-=15; Serial.println(brightness); ) break; ) analogWrite(LED, brightness); irrecv.resume(); ) )

Somehow like this. The second part of the article will discuss how we can send the received signal to our equipment. In my case it was the air conditioner. Also in the second part there will be a video that will show the turnkey assembly, from start to finish + an example of work.

Publications on the topic