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)
// 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;

int ledPin = 11;

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

void loop() {
  // if the receiver gets a signal
  if(myReceiver.getResults()) {
    // decode the signal
    // 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);
        // otherwise, turn off the LED
          digitalWrite(ledPin, LOW);
      // keep the LED set to the last button value
      Previous = myDecoder.value;
    // enable the IR receiver

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 Jun 30, 2017.

This page (Code) was last updated on Jul 11, 2017.

Text editor powered by tinymce.