Ensure you followed the Installing the IR Library Page. Copy and paste the code below into a blank Arduino Sketch. Then, compile and upload the code to your Metro.

Press button 1 and the LED should turn on. Any other button will turn the LED off.

/*
 * Metro Explorers Guide
 * CIRC16: IR Sensor 
 * 
 * Desc: Turns on and off a 5mm Red LED with Mini Remote (NEC)
 * by Brent Rubell for Adafruit Industries.   Support Open Source, buy Adafruit!
 * 
 * Note: this sketch requires IRLIB2.x
 */
// include all IRLib 2.x libraries 
#include <IRLibAll.h>

// These values are for the Adafruit Mini Remote (using the NEC Protocol)
#define MY_PROTOCOL NEC
// Handles NEC repeat codes
uint32_t Previous;
// button(s)
#define BUTTON_0 0xfd30cf
#define BUTTON_1 0xfd08f7  
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7

// pin for the reciever 
IRrecv myReceiver(6);
// decoder class 
IRdecode myDecoder;

// LED PIN
int ledPin = 11;

void setup() {
  // set the ledPin as an output
  pinMode(ledPin, OUTPUT);
  // enable the receiver
  myReceiver.enableIRIn(); 
}

void loop() {
  // if the receiver gets a signal
  if(myReceiver.getResults()) {
    // decode the signal
    myDecoder.decode();
    // set the decoder's protocol to the set protocol
    if(myDecoder.protocolNum == MY_PROTOCOL) {
      // if there
      if(myDecoder.value == 0xFFFFFFFF) {
        // keep the led set to the last button value
        myDecoder.value = Previous; 
      }
      // based on myDecoder.value, switch between button codes
      switch(myDecoder.value) {
        // Turn on the LED
        case BUTTON_1:  
          digitalWrite(ledPin, HIGH);
          break;
        // otherwise, turn off the LED
        default:
          digitalWrite(ledPin, LOW);
          break;
      }
      // keep the LED set to the last button value
      Previous = myDecoder.value;
    }
    // enable the IR receiver
    myReceiver.enableIRIn();
  }
}

Not Working?

I don't see the colors change

Is your RGB LED wired correctly? Are you using a different remote than the one included in the MetroX or MetroX Express Kit? If so, check out CIRC17 for examples of using different infrared sources. 

Fatal error: IRLibAll.h: No such file or directory #include

The IRLib 2.x library was improperly installed. Go back a step and make sure you have it installed. 

This guide was first published on Aug 18, 2017. It was last updated on Mar 27, 2024.

This page (Code) was last updated on Mar 27, 2024.

Text editor powered by tinymce.