Arduino IR remote keyboard, need some help!

Hey guys,

I have a remote for my TV that I can get my arduino to detect with an IR sensor and that's going great, I got a light to turn on whenever I press a button. But now I want to expand on that and connect a speaker to the arduino and assign different buttons on the remote to different tones to make a keyboard. How would I code in that this IR signal goes with this tone and so on?

If you show the sketch you have now for turning on the light, perhaps we can help.

Don't forget to use Tools->Auto Format to make it pretty.

Don't forget to use code tags around it to make it readable (the # button above the reply box).

I’m using the simple IRRecvdemo example code with the LED added in. THe problem is that the IR codes that I’m getting in the serial monitor only show up as a 0.

/*
 * 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;
int light = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{
  Serial.begin(9600);

  irrecv.enableIRIn(); // Start the receiver
  pinMode(light, OUTPUT); 
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    digitalWrite(light, HIGH);
    delay(100);
    digitalWrite(light, LOW);

    irrecv.resume(); // Receive the next value
  }
}

So you print out a numeric value and blink the light.

To act on keyboard input you would use that numeric value to determine which key was pressed.

You can ten use the Tone library to play a note based on which key was pressed.

yes... that is what I have already found out myself. I need help on getting the value because all I see are 0's so far. I also don't know how to assign a specific key to a tone.

polishdude20: yes... that is what I have already found out myself. I need help on getting the value because all I see are 0's so far. I also don't know how to assign a specific key to a tone.

If you get 0's for the results.value it is probably because the remote was not using one of the recognized protocols (Sony, RC5, RC6, NEC). This article shows how to generate a unique code from the raw pulse length values:

http://www.arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html

see code here for a proejct of mine: http://dduino.blogspot.com/2012/01/ir-tv-remote-controlled-arduino-robot.html

i found all the IR values in decimal for the buttons on the IR remote, then i put them in a array. i know that each button has a specific number in the array, so i can run a for loop from 0 to 49 ( if i had 50 buttons) then check each position in the array against the current IR signal being recieved. when i find the button that is being pressed, say 20, i can use a if statement to do something:

if(BtnPrssd == 20) { //do something }

i dont know if this is the best way, but it works well for me.

hey sirbow2 , I used your code and instead of your values for your remote I put in mine. Then I changed the if statements at the end to the corresponding numbers of the button such as 1 or 2 just as a test to see if it can distinguish which button im pressing. But no luck. It keeps saying FWD no matter which button I press. It looks like it just stays at 0 the whole time. Do you know how to fix this? Here’s the code, I only used 3 buttons:

#include <IRremote.h>
long int Buttons[3] = {
  1153,  //0Play  //
  3201,  //1Repeat
  986012, };  //48BTNHOLD

//-----Robot Stuff-------------------------------------------------//
int LmtrSpd=0;
int RmtrSpd=0;
#define LServoMtrPin 2
#define RServoMtrPin 3
#include <Servo.h>
Servo LServoMtr;
Servo RServoMtr;
//----------------------------------------------------------------//

//-----IR-Stuff---------------------------------------------------//

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int BtnPressed = 0;
//----------------------------------------------------------------//
int Ttime = 0;
int Ftime = 0;
void setup()
{
  Serial.begin(9600);
  LServoMtr.attach(LServoMtrPin);
  LServoMtr.write(90);
  RServoMtr.attach(RServoMtrPin);
  RServoMtr.write(90);

  irrecv.enableIRIn(); // Start the receiver
}

void dump(decode_results *results)
{
  if (results->decode_type == NEC)
  {
    unsigned long store = (results->value);
    //Serial.println(store);
    for(int x=0; x<49; ++x)
    {
      if(store == Buttons[x])
      {
        BtnPressed = x;
        // Serial.println(x);
      }
    }
  }
}

void loop()
{
  Ttime = millis();
  if (irrecv.decode(&results))
  {
    dump(&results);
    if(BtnPressed == 0) //Fwd
    {
      Serial.println("FWD");
      LmtrSpd=180;
      RmtrSpd=0;
    }
    if(BtnPressed == 1) //Fwd Right
    {
      Serial.println("FWD+RIGHT");
      LmtrSpd=180;
      RmtrSpd=23;
    }
    if(BtnPressed == 2) //Fwd left
    {
      Serial.println("FWD+LEFT");
      LmtrSpd=113;
      RmtrSpd=0;
    }
    else if(BtnPressed == 3) //Back
    {
      Serial.println("BACK");
      LmtrSpd=0;
      RmtrSpd=180;
    }



    LServoMtr.write(LmtrSpd);
    RServoMtr.write(RmtrSpd);

    irrecv.resume(); // Receive the next value
  }
  int Ftime = millis();
  delay(25-(Ftime-Ttime));
}

I fixed it! Your code was using NEC, I just switched to SONY and it worked!

i prob wouldnt have noticed that, but that was more your issue :). the rest of the code looks fine. i didnt answer because i was studying for the 4 tests in my 4 class periods today :( (totally aced them though :D)