IR remote and Arduino

ElectroBatool
ElectroBatool's picture
Offline
Joined: Aug 04, 2016
IR remote and Arduino
August 4, 2016 - 10:07am

I want to know the codes for each button that I use for my (car mp3 remote control), I write the following programming code: 

#include <IRremote.h>

int Recv_Pin=8;

IRrecv irrecv(Recv_Pin);

decode_results results;

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

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

but when I upload it to the arduino board, it keeps giving the same code for different bottons. So is my code correct, and how to solve this problem and know the right code for each button ? 

Abhishek
Abhishek's picture
Offline
Joined: May 19, 2015
You first need to decode
August 5, 2016 - 6:16pm

You first need to decode output of all the remote buttons and then code them accordingly. 

If you don’t know the Decoded output for your IR remote, it can be easily found, just follow these steps:

  1. Download the IR remote library from here https://github.com/z3t0/Arduino-IRremote.
  2. Unzip it, and place it in your Arduino ‘Libraries’ folder. Then rename the extracted folder to IRremote.
  3. Run the below program from your Arduino and open the Serial Monitor window in Arduino IDE. Now press any IR Remote button and see the corresponding decoded hex output in Serial Monitor window.
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

For more information go through this project: IR Remote Controlled Home Automation using Arduino

Neal McDonald
Neal McDonald's picture
Offline
Joined: Jul 12, 2016
Writing down the codes along
September 7, 2016 - 11:45am

Writing down the codes along with keeping a track of unknown codes can help in cracking the difficulties easily.