The following Fritzing schematic representation shows you how to wire each component together with the Arduino board to build the IR Receiver module. It shows the connection between each electronic component:
These three pins are:
You can capture the IR commands sent from the remote control in a hexadecimal notation:
B04844_08_01.ino
, from the Chapter 8
code folder. Alternately, you can open the same file from File | Examples | IRremote | IRrecvDemo.IRremote.h
, at the beginning of the sketch:#include <IRremote.h>
int RECV_PIN = 5;
irrecv
, using the IRrecv
class, and use the RECV_PIN
variable that was declared in the preceding line as the parameter:IRrecv irrecv(RECV_PIN);
results
has a type of decode_results
:decode_results results;
setup()
function, start the serial communication with 9,600 bps and start the IR receiver using the enableIRIn()
function:void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver }
loop()
function, we continuously check any incoming IR commands (signals) and then decode and print them on the Arduino Serial Monitor as hexadecimal values:void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } delay(100); }
RobotIRremote
folder, or rename the folder, Arduino-IRremote-master
, to IRremote
. Now, close and open the Arduino IDE with the sketch file and try to verify the sketch again. This will fix the compiler error:For testing purposes, we used a Samsung television (model number: UA24H4100) remote control to capture IR command values for the volume up and volume down buttons. the following image shows the captured output:
The command values for volume up and volume down in a hexadecimal format are as follows:
VOLUME UP: E0E0E01F VOLUME DOWN: E0E0D02F
Capturing IR commands in the raw format is very useful when you send them back to the target device later. The following steps will guide you in capturing the IR commands sent by a remote control in the raw format:
B04844_08_02.ino
, from the Chapter 8
sample code folder. Alternately, you can open the sketch by clicking on File | Examples | IRremote | IRrecvDumpV2.int recvPin = 5;
Encoding : SAMSUNG Code : E0E0E01F (32 bits) Timing[68]: -47536 +4700, -4250 + 750, -1500 + 700, -1500 + 700, -1550 + 700, - 400 + 700, - 400 + 700, - 400 + 700, - 450 + 650, - 450 + 650, -1600 + 600, -1600 + 650, -1600 + 600, - 500 + 600, - 500 + 600, - 550 + 600, - 500 + 600, - 500 + 600, -1650 + 550, -1650 + 600, -1650 + 550, - 550 + 550, - 600 + 500, - 600 + 500, - 600 + 550, - 550 + 550, - 600 + 500, - 600 + 500, - 600 + 500, -1750 + 500, -1700 + 500, -1750 + 500, -1700 + 500, -1750 + 500, unsigned int rawData[69] = {47536, 4700,4250, 750,1500, 700,1500, 700,1550, 700,400, 700,400, 700,400, 700,450, 650,450, 650,1600, 600,1600, 650,1600, 600,500, 600,500, 600,550, 600,500, 600,500, 600,1650, 550,1650, 600,1650, 550,550, 550,600, 500,600, 500,600, 550,550, 550,600, 500,600, 500,600, 500,1750, 500,1700, 500,1750, 500,1700, 500,1750, 500,0}; // SAMSUNG E0E0E01F unsigned int data = 0xE0E0E01F; Encoding : SAMSUNG Code : E0E0D02F (32 bits) Timing[68]: -29834 +4650, -4300 + 700, -1550 + 700, -1500 + 700, -1500 + 700, - 450 + 700, - 400 + 650, - 500 + 600, - 500 + 600, - 500 + 600, -1650 + 600, -1600 + 600, -1650 + 600, - 500 + 600, - 500 + 600, - 550 + 550, - 550 + 550, - 550 + 550, -1700 + 500, -1700 + 550, - 600 + 500, -1700 + 550, - 550 + 550, - 600 + 500, - 600 + 500, - 600 + 550, - 550 + 550, - 600 + 500, -1700 + 550, - 550 + 550, -1700 + 500, -1700 + 550, -1700 + 500, -1700 + 550, unsigned int rawData[69] = {29834, 4650,4300, 700,1550, 700,1500, 700,1500, 700,450, 700,400, 650,500, 600,500, 600,500, 600,1650, 600,1600, 600,1650, 600,500, 600,500, 600,550, 550,550, 550,550, 550,1700, 500,1700, 550,600, 500,1700, 550,550, 550,600, 500,600, 500,600, 550,550, 550,600, 500,1700, 550,550, 550,1700, 500,1700, 550,1700, 500,1700, 550,0}; // SAMSUNG E0E0D02F unsigned int data = 0xE0E0D02F;
Raw data for the Samsung UA24H4100 TV's volume up and volume down IR remote control buttons, Arduino Serial Monitor output text extract.
You can send any hardcoded IR command in the raw format using an Arduino sketch. In the previous section, we captured the IR raw data for the volume up and volume down buttons. In this example, we will learn how to send the hard coded IR command for volume up to the television. First, we have to build a simple IR sender module by adding an Infrared LED light and a 330 Ohm resistor.
The following Fritzing schematic shows how to wire each component together with the Arduino to build the IR Receiver module. It also shows the connection between each electronic component.
The following are additional wiring instructions for the circuit that you have previously built to capture the IR commands:
B04844_08_03.ino
, located in the Chapter 8
code folder. Verify and upload the sketch on your Arduino board.Encoding : SAMSUNG Code : E0E0E01F (32 bits) Timing[68]: -47536 +4700, -4250 + 750, -1500 + 700, -1500 + 700, -1550 + 700, - 400 + 700, - 400 + 700, - 400 + 700, - 450 + 650, - 450 + 650, -1600 + 600, -1600 + 650, -1600 + 600, - 500 + 600, - 500 + 600, - 550 + 600, - 500 + 600, - 500 + 600, -1650 + 550, -1650 + 600, -1650 + 550, - 550 + 550, - 600 + 500, - 600 + 500, - 600 + 550, - 550 + 550, - 600 + 500, - 600 + 500, - 600 + 500, -1750 + 500, -1700 + 500, -1750 + 500, -1700 + 500, -1750 + 500, unsigned int rawData[69] = {47536, 4700,4250, 750,1500, 700,1500, 700,1550, 700,400, 700,400, 700,400, 700,450, 650,450, 650,1600, 600,1600, 650,1600, 600,500, 600,500, 600,550, 600,500, 600,500, 600,1650, 550,1650, 600,1650, 550,550, 550,600, 500,600, 500,600, 550,550, 550,600, 500,600, 500,600, 500,1750, 500,1700, 500,1750, 500,1700, 500,1750, 500,0}; // SAMSUNG E0E0E01F unsigned int data = 0xE0E0E01F;
The highlighted unsigned
int
array consists of 69
values separated by commas, and it can be used to increase the Samsung television's volume by 1. The array size differs depending on the device and remote control manufacturer.
Also, you need to know the size of the command in bytes. For this, it is 32 bits:
Code : E0E0E01F (32 bits)
The command will be sent to the target device when you press the mini push button attached to the Arduino. We have used the sendRaw()
function to send the raw IR data:
for (int i = 0; i < 3; i++) { irsend.sendRaw(rawData,69,32) delay(40); }
The following is the parameter description for the sendRaw()
function:
irsend.sendRaw(name_of_the_raw_array, size_of_the_raw_array, command_size_in_bits);
In Chapter 1, Internet-Controlled PowerSwitch, we learned how to control a PowerSwitch Tail through the internet by sending a command to the server using the GET method. The same mechanism can be applied here to communicate with the Arduino IR remote and activate the IR LED. To do this, perform the following steps:
B04844_08_04.ino
, into the Chapter 8
code folder.http://192.168.1.177/
and then hit Enter. If you want to control the device through the Internet, you should set up port forwarding on your router.http://192.168.1.177/?volume=up
:Likewise, you can add the VOLUME
DOWN
function to the Arduino sketch and control the volume of your television. Apply this to an air conditioner and try to control the power and temperature through the Internet.
3.21.159.82