To find the Decoded Value (the unique IR signal for a specific button on your remote), you can use the Serial Monitor in the Arduino IDE to print the code that the IR receiver detects when you press a button.
Here’s how you can do that:
1. Wiring the IR Receiver to Arduino
- IR Receiver Module Pins:
- VCC → Connect to 5V on the Arduino.
- GND → Connect to GND on the Arduino.
- OUT → Connect to Pin 2 on the Arduino (this is where the Arduino will receive the decoded IR signal).
2. Upload Arduino Code:
#include <IRremote.h> // Include IRremote library
#define DECODE_NEC // Define the protocol (NEC)
const byte IR_RECEIVE_PIN = 2; // IR receiver pin
void setup()
{
Serial.begin(9600); // Start serial communication
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Initialize IR receiver
}
void loop()
{
if (IrReceiver.decode()) // Check if IR signal received
{
IrReceiver.resume(); // Prepare for next signal
}
if (IrReceiver.decodedIRData.command != 0) // If valid IR command received
{
checkIRcode(); // Process and print IR code
}
}
void checkIRcode()
{
Serial.print("Raw = ");
Serial.print(IrReceiver.decodedIRData.decodedRawData, HEX); // Print raw data in HEX
Serial.print(" Command = ");
Serial.println(IrReceiver.decodedIRData.command); // Print decoded command
IrReceiver.decodedIRData.command = 0; // Reset command after processing
}
3. Open the Serial Monitor:
- After uploading the sketch, open the Serial Monitor in the Arduino IDE (you can open it by going to Tools > Serial Monitor or by pressing Ctrl+Shift+M).
- Set the baud rate to 9600 to match the setting in the
Serial.begin(9600);
.
4. Press Buttons on the IR Remote:
- While the Serial Monitor is open and running, start pressing buttons on your IR remote.
- For example, when you press button 1, the Serial Monitor may show something like this:
BA45FF00
Tips:
- Different remotes: Keep in mind that different remotes might use different encoding protocols, so the code may appear differently, but the process remains the same.
- Multiple buttons: If your remote has multiple buttons, each will print a different unique code in the Serial Monitor, which you can then use to identify which button corresponds to which function.
Summary:
- Upload a simple code to print the IR codes.
- Open the Serial Monitor and press buttons on the remote.
- Note down the Decoded Value for each button.
- Use the codes in your main project code you are working on.