IR Receiver/Arduino fails to decode most IR signals sent from remote

Hi All,

I’m working on a project that will let me turn a light switch on and off from across the room using an IR remote. I have an IR receiver wired to an Arduino Uno, which will receive IR signals from a small IR remote, and move a servo to one of two positions (on/off) accordingly.

The issue I’m having is that the IR receiver/Arduino only successfully decodes about 1 in 5 IR signals, even when the remote is less than a foot away. Once I move more than 2 feet away, the IR receiver/Arduino isn’t able to successfully decode any signals from the remote at all. There is a direct line of sight between the receiver and remote and it will need to function at a distance of about 10 ft.

Here are pictures of what shows up on my serial monitor for successful/unsuccessful decodings:
Successful/Unsuccessful Decodings

(I have included parts, wiring, and code at the bottom of the post)

The IR receiver I am using came with 3 identical units, which all have the same problem, making me think the issue isn't a faulty receiver. I have also tried a few other remotes with very similar results. Even the TV remotes I've tried run into the same issue, although one expensive Panasonic remote I tried seemed to be more effective, although far from perfect.

Please let me know if you have any idea what the source of this issue may be.

Thanks!

Parts List:

Remote: Amazon.com

IR Receiver: Amazon.com

Wiring:

I don't know how to make those fancy wiring diagrams, but I'll do my best to describe the wiring. It's pretty simple.

The Arduino is powered by an AC/DC outlet adapter with an output of 9V/2A. The IR receiver's signal wire is connected to the Arduino's Pin 11 and the servo's control pin is connected to the Arduino's Pin 9. Both the IR receiver and servo are connected to the Arduino's 5V and GND pins via a breadboard.

Code:

#include <IRLib.h>
#include <Servo.h> 


#define MY_PROTOCOL NEC
#define CHdown 0xFFA25D   
#define CHup 0xFFE21D   

IRrecv My_Receiver(11); //Receive on pin 11
IRdecode My_Decoder; 
Servo My_Servo;  // create servo object to control a servo 
int pos;         // variable to store the servo position 
int Speed;       
long Previous;   // Stores previous code to handle NEC repeat codes
void setup() 
{ 
  
  Serial.begin(9600);
  Serial.print("Starting set up\n");
  //My_Servo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pos = 0;            // starting servo point
  Speed = 3;           
  My_Receiver.enableIRIn(); // Start the receiver
  
  Serial.print("Set up complete\n");
  
}  
 
void loop() 
{ 
   if (My_Receiver.GetResults(&My_Decoder)) {
        My_Decoder.decode();		//Decode the data
        My_Decoder.DumpResults();	//Show the results on serial monitor
 
        Serial.print("Decoder Value: ");
        Serial.println(My_Decoder.value); 
        switch(My_Decoder.value) {
            case CHdown:      pos=0; break;
            case CHup:      pos=70; break;
        }      
    
        Serial.print("Writing to servo pos: ");
        Serial.println(pos);
        My_Servo.attach(9);
        My_Servo.write(pos); // tell servo to go to position in variable 'pos' 
        //My_Servo.detach();
        delay(3000);
        My_Servo.detach();
    
        My_Receiver.resume(); //Restart the receiver
    }
   
   
   
    
}