Example Code for Arduino-Infrared Remote Communication
Last revision 2026/01/24
Hardware Preparation
- DFRduino UNO R3 x2
- IO Expansion Shield x2
- Digital IR Receiver x1
- IR Transmitter Module x1
Software Preparation
- Arduino IDE
- Get Arduino library Arduino-IRremote and install it
Wiring Diagram
- IR Transmitter: same as above, Notice: Arduino-IRremote only supports D3 as transmitter.
- IR Receiver: connet it to D11 port.
Step by Step
- Open Arduino IDE
- Upload code to the UNO connected with IR Transmitter:
#include <IRremote.h>
IRsend irsend;
void setup()
{
}
void loop() {
irsend.sendRC5(0x0, 8); //send 0x0 code (8 bits)
delay(200);
irsend.sendRC5(0x1, 8);
delay(200);
}
- Upload code to the UNO connected with IR Receiver:
#include <IRremote.h>
const int RECV_PIN = 11;
const int LED_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
if ( results.bits > 0 )
{
int state;
if ( 0x1 == results.value )
{
state = HIGH;
}
else
{
state = LOW;
}
digitalWrite( LED_PIN, state );
}
irrecv.resume(); // prepare to receive the next value
}
}
Result
The "L" LED of the shield connected with IR Receiver will blink when IR Receiver faces to IR Transmitter.
Was this article helpful?
