IR sensor does not work when connected to pin 13.

I am attempting to use an IR remote but I am limited by my pins. The only open space is pin 13 on my Arduino Nano. However, when testing out my sensor, the serial monitor only displays random codes instead of the repetitive codes that one would expect. For example, if I am in pin 13 and press a button multiple times, the codes that the serial monitor displays vary even though the same button is being pressed. However, if I am in pin 2 for example, the codes are displayed as expected. Does anyone have any idea why?

#include <IRremote.h>

const int RECV_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
}

Pin 13 has the on board LED attached to it which could be a problem.

Have you got any analogue pins free apart from A6 and A7 ?

Yes! How would I set those up with the sensor?

How would I set those up with the sensor?

Just use any of A0 to A5 in the same way as you would any digital pin but use the A* names to differentiate them from the digital only pins with the same numbers

Ahahaa!! I figured got it!! Thank you!! Would you happen to know how to use a code from the remote to call a function?
I have a larger project that this was just a small part of that had me stuck but I'm unsure how to be able to call a function using the IR code OR a physical button. I'm making a scoreboard that I want to be able to control through an IR remote or a keypad. Here is what I have. So far its just the keypad but I want to just add in the remote codes to call the same functions.

#include "IRremote.h"

#include "LedControl.h"  // Library used for communication with 7 segments

LedControl lc = LedControl(11, 12, 10, 1); //  (DIN, CLK, LOAD, number of Max7219 chips)

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int RECV_PIN = A0;
IRrecv irrecv(RECV_PIN);
decode_results results;

int scoreA;                                        // Team A
int scoreB;                                        // Team B
int scoreAdd = 0;                                  // Hold the number that will be added to the team and the number that will be subtracted from current score if over 21
int value = 0;                                     // the number accumulator
int key;                                           // the key press
int isnum;
bool twentyOne;
bool bestOf;
bool powerOn = true;
int aOne;
int aTen;
int bOne;
int bTen;
const int dOff = 0xFF;
int aWin = false;
int bWin = false;

void(* resetFunc) (void) = 0;

void progRefresh() {
  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  powerOn = true;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;

  lc.shutdown(0, false);
  lc.setIntensity (0, 15);

  lc.setDigit(0, 0, 0, aWin);
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);
}

void setup() {
  Serial.begin(9600);

  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  powerOn = true;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;
  bestOf = true;
  twentyOne = true;

  lc.shutdown(0, false);                         // Wake up MAX7219
  lc.setIntensity (0, 15);
  // Put zeros on both displays at startup
  lc.setDigit(0, 0, 0, aWin);                    // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);

  irrecv.enableIRIn();                           // Start the receiver

}

void loop() {
  char key = keypad.getKey();

  if (twentyOne == true) {
    lc.setDigit(0, 5, 8, true);
  }
  if (twentyOne == false) {
    lc.setDigit(0, 5, 4, false);
  }
  if (bestOf == true) {
    lc.setDigit(0, 7, 8, true);
  }
  if (bestOf == false) {
    lc.setDigit(0, 7, 4, false);
  }
  do
  {
    key = keypad.getKey();                          // input the key
    isnum = (key >= '0' && key <= '9');             // is it a digit?
    if (isnum)
    {
      scoreAdd = scoreAdd * 10 + key - '0';         // accumulate the input number
    }
  }
  while (isnum || !key);                          // until not a digit or while no key pressed

  if (key != NO_KEY) {
    if (key == 'A') {
      scoreA += scoreAdd;
      //     Serial.println(results.value);
      if (twentyOne == true) {
        if (scoreA > 21) {
          scoreAdd -= (21 - scoreA);
          scoreA -= scoreAdd;
        }
      }
      aOne = scoreA % 10;
      aTen = scoreA / 10;
      lc.setDigit(0, 0, aOne, aWin);
      lc.setDigit(0, 1, aTen, false);
    }
    if (key == 'B') {
      scoreB += scoreAdd;
      if (twentyOne == true) {
        if (scoreB > 21) {
          scoreAdd -= (21 - scoreB);
          scoreB -= scoreAdd;
        }
      }
      bOne = scoreB % 10;
      bTen = scoreB / 10;
      lc.setDigit(0, 2, bOne, bWin);
      lc.setDigit(0, 3, bTen, false);
    }
    if (key == '*') {
      powerOn = !powerOn;
      lc.setDigit(0, 0, 0, aWin);
      lc.setDigit(0, 1, 0, false);

      lc.setDigit(0, 2, 0, bWin);
      lc.setDigit(0, 3, 0, false);

      aWin = false;
      bWin = false;
    }
    if (key == 'C') {
      bestOf = !bestOf;
    }
    if (key == 'D') {
      twentyOne = !twentyOne;
    }
    if (key == '#') {
      progRefresh();
    }
    if (powerOn == true) {
      lc.shutdown(0, false);
    }
    if (powerOn == false) {
      lc.shutdown(0, true);
    }
  }
  scoreAdd = 0;

  if (scoreA == 21) {
    if (bestOf == true) {
      if (aWin == true) {
        delay(3000);
        resetFunc();
      }
      if (aWin == false) {
        aWin = true;
        delay(2000);
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
  if (scoreB == 21) {
    if (bestOf == true) {
      if (bWin == true) {
        delay(3000);
        resetFunc();
      }
      if (bWin == false) {
        delay(2000);
        bWin = true;
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
}

Would you happen to know how to use a code from the remote to call a function?

Test the value returned by results.value and call the function

    if (results.value == 0xFF00FF)
    {
      someFunction();
    }

Is your question really more complicated than it seems at first sight ?

I already have all of the functions that I want to use set in place but I want to be able to just add the IR buttons to call the function. For example, I have

Jamescross449:

    if (key == '#') {

progRefresh();
    }

And I want to have something like this:

    if (key == '#' || results.value == 0xFFB04F) {
      progRefresh();
    }

A) is this the proper notation and such because I have not been able to get this to work?
B) Would it be easier to add the IR codes to call the functions or would it be easier (or even possible) to define the codes to equal what already calls the function?
Thank you so much for any help!!

Hello! I am creating a scoreboard that I want to be able to control from an IR remote as well as a keypad on the side of it. I currently have a code that works perfectly for the keypad, however, I am unsure how to incorporate the keypad to call the same functions that the keypad buttons do. Here;s the working code:

#include "IRremote.h"

#include "LedControl.h"  // Library used for communication with 7 segments

LedControl lc = LedControl(11, 12, 10, 1); //  (DIN, CLK, LOAD, number of Max7219 chips)

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int RECV_PIN = A0;
IRrecv irrecv(RECV_PIN);
decode_results results;

int scoreA;                                        // Team A
int scoreB;                                        // Team B
int scoreAdd = 0;                                  // Hold the number that will be added to the team and the number that will be subtracted from current score if over 21
int value = 0;                                     // the number accumulator
int key;                                           // the key press
int isnum;
bool twentyOne;
bool bestOf;
bool powerOn = true;
int aOne;
int aTen;
int bOne;
int bTen;
const int dOff = 0xFF;
int aWin = false;
int bWin = false;

void(* resetFunc) (void) = 0;

void progRefresh() {
  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;

  lc.shutdown(0, false);
  lc.setIntensity (0, 15);

  lc.setDigit(0, 0, 0, aWin);
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);
}

void setup() {
  Serial.begin(9600);

  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  powerOn = true;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;
  bestOf = true;
  twentyOne = true;

  lc.shutdown(0, false);                         // Wake up MAX7219
  lc.setIntensity (0, 15);
  // Put zeros on both displays at startup
  lc.setDigit(0, 0, 0, aWin);                    // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);

  irrecv.enableIRIn();                           // Start the receiver

}

void loop() {
  char key = keypad.getKey();

  if (twentyOne == true) {
    lc.setDigit(0, 5, 8, true);
  }
  if (twentyOne == false) {
    lc.setDigit(0, 5, 4, false);
  }
  if (bestOf == true) {
    lc.setDigit(0, 7, 8, true);
  }
  if (bestOf == false) {
    lc.setDigit(0, 7, 4, false);
  }
  do
  {
    key = keypad.getKey();                         // input the key
    isnum = (key >= '0' && key <= '9');             // is it a digit?
    if (isnum)
    {
      scoreAdd = scoreAdd * 10 + key - '0';         // accumulate the input number
    }
  }
  while (isnum || !key);                          // until not a digit or while no key pressed

  if (key != NO_KEY) {
    if (key == 'A') {
      scoreA += scoreAdd;
      //     Serial.println(results.value);
      if (twentyOne == true) {
        if (scoreA > 21) {
          scoreAdd -= (21 - scoreA);
          scoreA -= scoreAdd;
        }
      }
      aOne = scoreA % 10;
      aTen = scoreA / 10;
      lc.setDigit(0, 0, aOne, aWin);
      lc.setDigit(0, 1, aTen, false);
    }
    if (key == 'B') {
      scoreB += scoreAdd;
      if (twentyOne == true) {
        if (scoreB > 21) {
          scoreAdd -= (21 - scoreB);
          scoreB -= scoreAdd;
        }
      }
      bOne = scoreB % 10;
      bTen = scoreB / 10;
      lc.setDigit(0, 2, bOne, bWin);
      lc.setDigit(0, 3, bTen, false);
    }
    if (key == '*') {
      progRefresh();
      bestOf = true;
      twentyOne = true;
      aWin = false;
      bWin = false;
      powerOn = !powerOn;
    }
    if (key == 'C') {
      bestOf = !bestOf;
    }
    if (key == 'D') {
      twentyOne = !twentyOne;
    }
    if (key == '#') {
      progRefresh();
    }
    if (powerOn == true) {
      lc.shutdown(0, false);
    }
    if (powerOn == false) {
      lc.shutdown(0, true);
    }
  }
  scoreAdd = 0;

  if (scoreA == 21) {
    if (bestOf == true) {
      if (aWin == true) {
        delay(3000);
        resetFunc();
      }
      if (aWin == false) {
        aWin = true;
        delay(2000);
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
  if (scoreB == 21) {
    if (bestOf == true) {
      if (bWin == true) {
        delay(3000);
        resetFunc();
      }
      if (bWin == false) {
        delay(2000);
        bWin = true;
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
}

I want the IR codes to perform the same functions as the keys that are pressed. What would be the best way to do this?
A) if (key == 'A' || results.value == 0xFF10EF);
-> adding the ir code to call each individual function?
-->tried but never successful
B) Redoing every function but only calling through IR codes
-> One section for keypad, one for IR remote but they do the same thing
C) Defining a code to equal a key
-> If the code 0xFF10EF is received, it would be the same as if key A was pressed?
--> Not sure how to go about this.

Thanks for any help!! Really appreciate it!!
Please let me know if you have any questions or if anything is unclear.

tried but never successful

Post what to tried and describe what was wrong

is this the proper notation and such because I have not been able to get this to work?

It looks OK. What happens when you try to use it ?
Try printing the values that you ate testing just before the test

You could certainly have 2 separate if clauses if you wanted

Whether you get a key from the keyboard or IR, what you do with the key is the same. Once you have the key, use one set of functions to deal with the key.

How would I setup the IR remote code to equal that key?

Its a little more complicated. I've tried this but get no result. Am I doing something wrong.

Jamescross449:

void loop() {

char key = keypad.getKey();

do
  {
    key = keypad.getKey();                                                            // input the key
    isnum = (key >= '0' && key <= '9');                                        // is it a digit?
    if (isnum)
    {
      scoreAdd = scoreAdd * 10 + key - '0';                                    // accumulate the input number
    }
  }
  while (isnum || !key || (irrecv.decode(&results));                          // until not a digit or while no key pressed

if (key != NO_KEY) {
    if (key == '#' || results.value == 0xFFB04F) {
      progRefresh();
    }
}

Would it make more sense or even be possible to define the IR codes to equal the individual keys?

Would it make more sense or even be possible to define the IR codes to equal the individual keys?

It's not possible so don't even think about doing it

Why do you have two threads on the same subject ?

Jamescross449:
How would I setup the IR remote code to equal that key?

You can't, but you don't need to

Read the keypad then read the IR and test whether either of them is the correct value as in (A) in your original post. You say that it didn't work but have never posted the non working code. Please post the code

Why have you got two threads on the same subject ?

Sorry, I had two threads for different subjects but only one was getting responses so I asked my other question on here as well.

Can I suggest that you click Report to moderator and ask them to merge the threads

Sorry, I'm pretty new to this. Here is the code that will not work.

#include "IRremote.h"

#include "LedControl.h"  // Library used for communication with 7 segments

LedControl lc = LedControl(11, 12, 10, 1); //  (DIN, CLK, LOAD, number of Max7219 chips)

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

const int RECV_PIN = A0;
IRrecv irrecv(RECV_PIN);
decode_results results;

int scoreA;                                        // Team A
int scoreB;                                        // Team B
int scoreAdd = 0;                                  // Hold the number that will be added to the team and the number that will be subtracted from current score if over 21
int value = 0;                                     // the number accumulator
int key;                                           // the key press
int isnum;
bool twentyOne;
bool bestOf;
bool powerOn = true;
int aOne;
int aTen;
int bOne;
int bTen;
const int dOff = 0xFF;
int aWin = false;
int bWin = false;

void(* resetFunc) (void) = 0;

void progRefresh() {
  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;

  lc.shutdown(0, false);
  lc.setIntensity (0, 15);

  lc.setDigit(0, 0, 0, aWin);
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);
}

void setup() {
  Serial.begin(9600);

  scoreA = 0;
  scoreB = 0;
  scoreAdd = 0;
  powerOn = true;
  aOne = 0;
  aTen = 0;
  bOne = 0;
  bTen = 0;
  bestOf = true;
  twentyOne = true;

  lc.shutdown(0, false);                         // Wake up MAX7219
  lc.setIntensity (0, 15);
  // Put zeros on both displays at startup
  lc.setDigit(0, 0, 0, aWin);                    // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0, 1, 0, false);

  lc.setDigit(0, 2, 0, bWin);
  lc.setDigit(0, 3, 0, false);

  irrecv.enableIRIn();                           // Start the receiver

}

void loop() {
  char key = keypad.getKey();

  if (twentyOne == true) {
    lc.setDigit(0, 5, 8, true);
  }
  if (twentyOne == false) {
    lc.setDigit(0, 5, 4, false);
  }
  if (bestOf == true) {
    lc.setDigit(0, 7, 8, true);
  }
  if (bestOf == false) {
    lc.setDigit(0, 7, 4, false);
  }
  do
  {
    key = keypad.getKey();                         // input the key
    isnum = (key >= '0' && key <= '9');             // is it a digit?
    if (isnum)
    {
      scoreAdd = scoreAdd * 10 + key - '0';         // accumulate the input number
    }
  }
  while (isnum || !key);                          // until not a digit or while no key pressed

  if (key != NO_KEY || irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
    if (key == 'A' || results.value == 0xFF10EF) {
      scoreA += scoreAdd;
      //     Serial.println(results.value);
      if (twentyOne == true) {
        if (scoreA > 21) {
          scoreAdd -= (21 - scoreA);
          scoreA -= scoreAdd;
        }
      }
      aOne = scoreA % 10;
      aTen = scoreA / 10;
      lc.setDigit(0, 0, aOne, aWin);
      lc.setDigit(0, 1, aTen, false);
    }
    if (key == 'B' || results.value == 0xFF5AA5) {
      scoreB += scoreAdd;
      if (twentyOne == true) {
        if (scoreB > 21) {
          scoreAdd -= (21 - scoreB);
          scoreB -= scoreAdd;
        }
      }
      bOne = scoreB % 10;
      bTen = scoreB / 10;
      lc.setDigit(0, 2, bOne, bWin);
      lc.setDigit(0, 3, bTen, false);
    }
    if (key == '*' || results.value == 0xFF6897) {
      progRefresh();
      bestOf = true;
      twentyOne = true;
      aWin = false;
      bWin = false;
      powerOn = !powerOn;
    }
    if (key == 'C' || results.value == 0xFFF18E7) {
      bestOf = !bestOf;
    }
    if (key == 'D' || results.value == 0xFF4AB5) {
      twentyOne = !twentyOne;
    }
    if (key == '#' || results.value == 0xFFB04F) {
      progRefresh();
    }
    if (powerOn == true) {
      lc.shutdown(0, false);
    }
    if (powerOn == false) {
      lc.shutdown(0, true);
    }
  }
  scoreAdd = 0;

  if (scoreA == 21) {
    if (bestOf == true) {
      if (aWin == true) {
        delay(3000);
        resetFunc();
      }
      if (aWin == false) {
        aWin = true;
        delay(2000);
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
  if (scoreB == 21) {
    if (bestOf == true) {
      if (bWin == true) {
        delay(3000);
        resetFunc();
      }
      if (bWin == false) {
        delay(2000);
        bWin = true;
        progRefresh();
      }
    }
    if (bestOf == false) {
      delay(3000);
      progRefresh();
    }
  }
}

Thank you so much for any help!!

    Serial.println(results.value, HEX);
    irrecv.resume();

What do you see printed ?

Does results.value change after the irrecv.resume() and before the tests ?

Nothing is printed but the light on the receiver blinks when I press a button...