Introduction: Infrared Communication Lab

Materials Needed

1. Arduino

2. LED Matrix

3. IR Receiver

Start lab using Remote control to control which LEDs. Have the LEDs display different color patterns

Next pair up to have one Arduino transmit the Joystick's positional data

4. IR Transmitter

5. Joystick

6. Buttons

Step 1: IR Receiver

You will be adding an IR receiver from your Elegoo Kit. The kit uses a breakout board, and in this case you can either connect to it using the ribbon cable (male-female dupont cables) or plug it directly into the breadboard. I do not encourage direct connection to the breadboard, because it will make the sensor point upwards, making it more difficult to receive IR signals.

  1. Connect the GND pin on the Arduino to the ground rail on the breadboard.
  2. Connect the 5v pin to the power rail on the breadboard.
  3. IR receiver connections:
    1. "G" lead connects to the ground rail
    2. "R" lead connects to the power rail
    3. "Y" is the data pin, it connects to Pin 7

Step 2: IR Receiver Code

The code listed here is the original code from the Elegoo Code Files. The most important part is the hex values listed for the provided Elegoo remote. These are specific values for the remotes provided. For any future IR project, make sure to check back over this code for those values.


#include "IRremote.h"

int receiver = 7; // Signal Pin of IR receiver to Arduino Digital Pin 7

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 



  case 0xFFA25D: Serial.println("POWER"); break;
  case 0xFFE21D: Serial.println("FUNC/STOP"); break;
  case 0xFF629D: Serial.println("VOL+"); break;
  case 0xFF22DD: Serial.println("FAST BACK");    break;
  case 0xFF02FD: Serial.println("PAUSE");    break;
  case 0xFFC23D: Serial.println("FAST FORWARD");   break;
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: Serial.println("VOL-");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF9867: Serial.println("EQ");    break;
  case 0xFFB04F: Serial.println("ST/REPT");    break;
  case 0xFF6897: Serial.println("0");    break;
  case 0xFF30CF: Serial.println("1");    break;
  case 0xFF18E7: Serial.println("2");    break;
  case 0xFF7A85: Serial.println("3");    break;
  case 0xFF10EF: Serial.println("4");    break;
  case 0xFF38C7: Serial.println("5");    break;
  case 0xFF5AA5: Serial.println("6");    break;
  case 0xFF42BD: Serial.println("7");    break;
  case 0xFF4AB5: Serial.println("8");    break;
  case 0xFF52AD: Serial.println("9");    break;
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat

} //END translateIR
void setup()   /*----( SETUP: RUNS ONCE )----*/
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  if (irrecv.decode(&results)) // have we received an IR signal?

    irrecv.resume(); // receive the next value
}/* --(end main loop )-- */

Step 3: LED Matrix

The LED matrix is an 8 x 8 grid of LEDs controlled by a MAX7219 chip. This means our Arduino will control the chip, which in turn will control the individual LEDs. Our matrix only has five leads, but the diagram shows 6. Ignore the unused lead!

Connects from left to right:

  1. Power rail
  2. Ground rail
  3. Pin 10
  4. Pin 9
  5. Pin 8

Step 4: LED Matrix Code

This code is a modified version that is provided in your Elegoo Code examples. The Library used is the LedControl.h, its documentation can be found here:

#include "LedControl.h"

 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 10 is connected to the DataIn 
 pin 9 is connected to LOAD(CS)
 pin 8 is connected to the CLK 
 We have only a single MAX72XX.
LedControl lc=LedControl(10,8,9,1);

/* we always wait a bit between updates of the display */

unsigned long delaytime=50;
void setup() {
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
  /* Set the brightness to a medium values */
  /* and clear the display */

void loop() { 
  //Turn all leds on row by row:
  //lc.setRow(address, row, binary bits);
  //The address is 0 because we are only using 1 LED matrix
  //The row can be 0 - 7, we only have 8 rows
  //The binary value is an 8 bit number, where 1 is an on LED
  //and zero is an off LED
  lc.setRow(0,0,B11111111);//8 LEDs -> 8 Binary digits, 1 represents ON
  //Set specific led to off
  //lc.setLed(address, row, column, state)
  lc.setLed(0, 2, 4, false);

Step 5: Combine Example Codes

Now you have code examples for receiving IR signals and setting LEDs on your matrix. The next step is to combine these two example code files, so that you can now control your LED matrix with your remote. Update your code now so that you can use individual buttons to :

1. Turn all of the LEDs on/off

2. Select a unique color pattern

3. Select to have a specific row/col lit

Step 6: IR Communications

We'll now setup our Arduinos to transmit IR signals. For this part, you will need a partner. One Arduino will be used to transmit IR signals and the other receive IR signals. The goal here is to have the transmitter's joystick control the movement of an LED on the receivers LED Matrix display.

Joystick Connections Top to Bottom:

  1. Ground rail
  2. Power rial
  3. Analog 0
  4. Analog 1
  5. Digital 2

Step 7: Joystick Code

This code is taken from the Elegoo Code Examples


// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);

void loop() {
  Serial.print("Switch:  ");
  Serial.print("X-axis: ");
  Serial.print("Y-axis: ");

Step 8: IR Transmitter

The IR transmitter is actually an LED set to the Infrared spectrum. So it's connection is the same as a normal LED. The only exception is that it can't connect to any pin. The library uses pin 3 (timer 2) for controlling the IR transmissions.

  1. Connect the shorter lead to ground
  2. Connect the longer lead to a 220 ohm resistor, which will in turn connect to Pin 3

Step 9: IR Transmitter Code

#include "IRremote.h"

IRsend irsend;//uses pin 3
void setup()

void loop() {
	irsend.sendSony(0x0AA, 12);//Transmits 12 bits in hex
	irsend.sendSony(0x0BB, 12);//Transmits 12 bits in hex

Step 10: Combine Example Code

Your final step for this lab is to combine the joystick and IR code examples to create a functioning transmitter that will allow you to "move" an LED on your partner's LED matrix up, down, left, right.

After you have finished your transmitter, work together to create a lab submission detailing your code and any additional inputs/outputs you've included to your device.