Combined Working Code gives no Output

All

I have tested the code below individually for IR read and SD card read and together alone they work. However having combined the code and compiled ok it doesn’t appear to work.

The SD card is initiating ok and on start I hear a sound.

However I don’t believe the IR sensor is readying any longer. I left in a serial print code to show on the serial monitor what was being received but now when checking all I see are zeros… I go back and test the code separately and it all works ok … so I assume my circuit design is not the problem.

So at this stage I suspect its a conflict created one combining my two circuits and which is affecting IR sensor data…

Your thoughts / feedback would be much welcome; :confused:

// Title: IR Reader and Action Trigger (inc Sound Files on SD Card) + TBC
// Date:  26 May'15
// Notes: Compiled ok on 26May after adding prefix 0X and suffix ul for Hex code
// moved Serial.println(results.value, HEX) and irrecv.resume();  outside of button select of loop
/////////////////////////////////////////////////////////////////////////////////

// IRremote Libraries
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 10;            // using digital pin 10 on Uno for IR Rx. Chgd from 11 to 10 as conflict'd with SDcard MOSI pin
IRrecv irrecv(RECV_PIN);
decode_results results;

// SD Card Libraries
#include <SPI.h>
#include <SD.h>                
#define SD_ChipSelectPin 4     // using digital pin 4 on arduino nano 328 for SD card select (CS)
#include <TMRpcm.h>            // also need to include this library...
TMRpcm tmrpcm;                 // create an object for use in this sketch
char mychar;

void setup() 
{ 
  // put your setup code here, to run once:
  Serial.begin(9600);
  irrecv.enableIRIn();               // Start the receiver
  tmrpcm.speakerPin = 9;             // using digital pin 9 on Uno, Nano (11 on Mega) for Spkr output
  if (!SD.begin(SD_ChipSelectPin))   // see if the card is present and can be initialized:
   { 
    Serial.println("SD fail");  
    return;                          // don't do anything more if not
   }
   tmrpcm.play("start.wav");         // Sound file "Start" will play each time arduino powers up, or is reset
}

void loop() 
{
  // put your main code here, to run repeatedly:
  if (irrecv.decode(&results))
    {
     if(results.value == 0x9716BE3Ful)          // Check IR input for hex 9716BE3F(for button1)to start playback
      {
       tmrpcm.play("button1.wav");              // Play sound file Button1 (???????)
      }
     else if(results.value == 0x3D9AE3F7ul)     // Check IR input for hex 3D9AE3F7(for button2)to start playback
      {
       tmrpcm.play("button2.wav");              // Play sound file Button2 (???????)
      }
    }
     Serial.println(results.value, HEX);        // Send the Hex over the serial monitor (can remove later)
     irrecv.resume();                           // Receive the next value
}

int RECV_PIN = 10; // using digital pin 10 on Uno for IR Rx. Chgd from 11 to 10 as conflict'd with SDcard MOSI pin

So, instead you conflict with another pin. 10, 11, 12, and 13 are NOT available to you when using ANY SPI device.

You CAN use Pin 10 (hardware SPI Slave Select) as an OUTPUT when using SPI but you can't use it as an INPUT because that switches the hardware SPI port from Master mode to Slave mode. Your SD works because when you call SD.begin() it switches Pin 10 to an OUTPUT. That leaves the IRremote library reading input from an output pin.

Many thanks :)

So instead of using pins 10, 11, 12, and 13 for the IR Receiver, I assume I can use pins 2 to 9 ?

I assume I can use pins 2 to 9 ?

If your ethernet shield has an SD card on it, you should avoid pin 4, too.