I need help with my arduino ir sensor and ir remote

I need help with my Arduino IR sensor and IR remote. I'm actually new to Arduino I just bought my first Arduino kit around 20 October 2022 so I was trying to make a simple thing with my IR things like when I press my remote's button the led with blink but when I saw tutorials on youtube.. it doesn't work I wasted my past few hours doing it so please help me at least make my newbie time with Arduino good :slight_smile:

This is the code I just copied from a random article

#include <IRremote.h>  //including infrared remote header file     
int RECV_PIN = 7; // the pin where you connect the output pin of IR sensor     
IRrecv irrecv(RECV_PIN);     
decode_results results;     
void setup()     
{     
Serial.begin(9600);     
irrecv.enableIRIn();     
{     
void loop()     
{     
if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready.     
{     
 int results.value = results;// Results of decoding are stored in result.value     
 Serial.println(" ");     
 Serial.print("Code: ");     
 Serial.println(results.value); //prints the value a a button press     
 Serial.println(" ");     
 irrecv.resume(); // Restart the ISR state machine and Receive the next value     
}     

What does that mean exactly? What results to you get?

like when i press the button the serial monitor shows nothing

Post a link.

Post a picture / diagram of how you have the sensor connected.

its this https://create.arduino.cc/projecthub/electropeak/use-an-ir-remote-transmitter-and-receiver-with-arduino-1e6bc8 you can see diagrom from here too

Show a picture of how you have connected.

Does the remote have good battery?

Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

my actual bread board is pretty like dirty because I was make a big project so I cannot take the perfect picture
IMG_20221203_171853

Black - GND
Yellow - 5V
Pink or Whatever one is my arduino uno port one

and I took with my laptop so its weird plus my remote battery is good

Would you back out a bit so we can see the whole breadboard with connections to the Arduino.

it would be hard to see but ill do
IMG_20221203_172630
um at the bottom its ir receiver and at the right it is uno board

Oh my :astonished: .

  • Measure the voltage on the sensor power pins to confirm it is powered.

  • Let’s see an image (focused) of the sensor module.




Not saying this is your receiver but your sensor does need to be connected correctly. :thinking:

image

Confirm the sensor output is going to Arduino pin 7.

Try this:


#include <IRremote.h>  //including infrared remote header file     


int RECV_PIN = 7; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;


//********************************************^************************************************
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();

} //END of   setup()


//********************************************^************************************************
void loop()
{
  //**************************************
  if (irrecv.decode(&results)) //this checks to see if a code has been received
  {
    if (results.value != 0xFFFFFFFF)
    {
      Serial.print("Code: ");
      Serial.println(results.value, HEX); //prints the hex value a a button press
    }
    irrecv.resume(); // Restart the ISR state machine and Receive the next value
  }
  
} //END of   loop()


FYI

This example use library version 3.3.0

//IR remote ON/OFF example

//********************************************^************************************************
// Version    YY/MM/DD    Description
// 1.00       21/09/27    Running sketch
//
//

//Install IRremote Version 3.3.0
#include <IRremote.h>   // Ver 3.3.0 <-------<<<<<<<

#define DECODE_NEC

unsigned long irMillis;


//                                   s e t u p ( )
//******************************************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(13, OUTPUT);  //LED feedback
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9,  OUTPUT);

  //**************************************
  const byte IR_RECEIVE_PIN = 2;

  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

  //IR_RECEIVE_PIN (UNO) default = 2
  //IrReceiver.begin(IR_RECEIVE_PIN); //receive on pin 2
  //IrReceiver.begin(4);              //receive on pin 4

  //disableLEDFeedback();
  //enableLEDFeedback ();

  //use pin 12, defaults to 13, true/false
  //setLEDFeedback(12,true);

} //END of   setup()


//                                    l o o p ( )
//******************************************************************************************
void loop()
{
  //*******************************************************
  if (IrReceiver.decode())
  {
    //Some code lines to try
    //
    //IrReceiver.printIRResultShort(&Serial);
    //IrReceiver.printIRResultRawFormatted(&Serial, true);
    //IrReceiver.printIRResultMinimal(&Serial);
    //Serial.println(IrReceiver.decodedIRData.command);
    //Serial.println(IrReceiver.decodedIRData.address);
    //Serial.println(IrReceiver.decodedIRData.protocol);
    //Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);

    IrReceiver.resume(); // Enable receiving of the next value
  }

  //*******************************************************
  //have we received a new IR code form the remote ?
  if (IrReceiver.decodedIRData.command != 0)
  {
    checkIRcode();
  }

} //END of   loop()


//                                c h e c k I R c o d e ( )
//******************************************************************************************
void checkIRcode()
{
  Serial.println(IrReceiver.decodedIRData.command);

  switch (IrReceiver.decodedIRData.command)
  {
    //*********************  key #1
    case 22:
      {
        digitalWrite(12, !digitalRead(12));
      }
      break;

    //*********************  key #2
    case 25:
      {
        digitalWrite(11, !digitalRead(11));
      }
      break;

    //*********************  key #3
    case 13:
      {
        digitalWrite(10, !digitalRead(10));
      }
      break;
      
    //*********************  key #4
    case 12:
      {
        digitalWrite(9, !digitalRead(9));
      }
      break;

  }  //END of   switch...case


  //needed to block repeat codes
  IrReceiver.decodedIRData.command = 0;

} //END of   checkIRcode()



Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

uhm excuse me sorry for late reply but when I try that code it says
14:41:49.393 -> The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData.

And im sure with port 7 of uno please help

//Install IRremote Version 3.3.0
#include <IRremote.h>   // Ver 3.3.0 <-------<<<<<<<

//**************************************
const byte IR_RECEIVE_PIN = 7;


//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

  IrReceiver.begin(IR_RECEIVE_PIN);

} //END of   setup()


//********************************************^************************************************
void loop()
{
  //*******************************************************
  //have we received a new IR code form the remote ?
  if (IrReceiver.decode())
  {
      if (IrReceiver.decodedIRData.command != 0)
      {
        Serial.print("Code: ");
        Serial.println(IrReceiver.decodedIRData.command);

        //needed to block repeat codes
        IrReceiver.decodedIRData.command = 0;
      }
    
    IrReceiver.resume();
  }

  //*******************************************************
  // other non blocking code goes here
  //*******************************************************

} //END of   loop()

Foe every library, there are examples File > Examples > IRremote > ReceiveDemo (or SimpleReceiver)) , you should try first, not some ancient code :slight_smile:

You might be interested in these inexpensive IR key pads (eBay).

Add a cover and turn it into an IR wireless keyboard.

image

uhm mine is this one

i just found it online

That looks like an NEC remote; it should work with the sketch quite nicely.