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
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.
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).
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.
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:
#includeYou 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#includeToday'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
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
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
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
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.