IRremote help

Hello,

I have just hooked up an ir reciever to my arduino and I was trying to see what information was being sent to my arduino from and iHome ir remote so that I could make another sketch having the remote control stuff, but the info in the serial monitor is odd. Every time I press a button on the remote (even the samme one twice), a random symbol appears, and each time it is different. For example, ð and Ð, after pressing a few buttons the monitor looks like this, ð©úææ¥ô¹©âæùæÐâêù¹Ð¹ù÷ùâ â¹ùâäõ¹ð©ùçùâ©â¹Ð¹ôçùâ¡âçôêØ©àçøàäô©ø©èæØè òà©©èòò © Øô©
Isnt it suppost to show different setts of numbers for each button? If not, how could I implement this into a sketch like this

*/

int irPin = 2; //Sensor pin 1 wired to Arduino's pin 2
int statLED = 13; //Toggle the status LED every time Power is pressed
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)

void setup() {
pinMode(statLED, OUTPUT);
digitalWrite(statLED, LOW);

pinMode(irPin, INPUT);

Serial.begin(9600);
Serial.println("Waiting: ");
}

void loop() {
int key = getIRKey(); //Fetch the key

if(key != 0) //Ignore keys that are zero
{
Serial.print("Key Recieved: ");
switch(key)
{
case 144: Serial.print("CH Up"); break;
case 145: Serial.print("CH Down"); break;
case 146: Serial.print("VOL Right"); break;
case 147: Serial.print("VOL Left"); break;
case 148: Serial.print("Mute"); break;
case 165: Serial.print("AV/TV"); break;
case 149:
Serial.print("Power");
if(digitalRead(statLED) != 1) //This toggles the statLED every time power button is hit
digitalWrite(statLED, HIGH);
else
digitalWrite(statLED, LOW);
break;

default: Serial.print(key);
}

Serial.println();
}
}

int getIRKey() {
int data[12];
int i;

while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit

for(i = 0 ; i < 11 ; i++)
data = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses

  • for(i = 0 ; i < 11 ; i++) //Parse them*
  • { *
    if(data > bin_1) //is it a 1?
    _ data = 1;
    else if(data > bin_0) //is it a 0?
    data = 0;
    * else*
    * return -1; //Flag the data as invalid; I don't know what it is! Return -1 on invalid data*
    * }
    int result = 0;
    for(i = 0 ; i < 11 ; i++) //Convert data bits to integer*

    if(data == 1) result |= (1<<i);
    * return result; //Return key number*
    } [/quote]
    Here is the code for the sketch i used to find the IR info recieved from the remote.
    > #include <IRremote.h>
    > #include <IRremoteInt.h>
    >
    > // example 32.1 - IR receiver code repeater
    > // Arduino Tutorials | tronixstuff.com > chapter 32
    > // based on code by Ken Shirriff - http://arcfn.com
    > #include <IRremote.h> // use the library
    > int receiver = 2; // pin 1 of IR receiver to Arduino digital pin 11
    > IRrecv irrecv(receiver); // create instance of 'irrecv'
    > decode_results results;
    > void setup()
    > {
    > Serial.begin(9600); // for serial monitor output
    > irrecv.enableIRIn(); // Start the receiver
    > }
    > void loop()
    > {
    > if (irrecv.decode(&results)) // have we received an IR signal?
    > {
    > Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal
    > irrecv.resume(); // receive the next value
    > } // Your loop can do other things while waiting for an IR command
    > }_

Are those odd codes from the second sketch ?
What baud rate to you have the serial monitor set to, and does it match that of the sketch ?
What IR receiver are you using and how is is wired to the Arduino ?

The odd codes are from the second sketch, the first sketch is the one where I want to put the info received from the IR remote in so I can control LEDs, servos etc. I got the IR receiver from here https://www.sparkfun.com/products/10266. The baud rate is 300 in the serial monitor.

The baud rate is 300 in the serial monitor.

It is 9600 in the program. Change one or other (or both) so they match.

Alright, I got the sketch to work and I have figured out the info being send to the IR reciever for each button press. Now I need to know how to implement it into this code or similar code.

int irPin = 2; //Sensor pin 1 wired to Arduino's pin 2
int statLED = 13; //Toggle the status LED every time Power is pressed
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)

void setup() {
  pinMode(statLED, OUTPUT);
  digitalWrite(statLED, LOW);

  pinMode(irPin, INPUT);

  Serial.begin(9600);
  Serial.println("Waiting: ");
}

void loop() {
  int key = getIRKey();		    //Fetch the key
  
  if(key != 0) //Ignore keys that are zero
  {
    Serial.print("Key Recieved: ");
    switch(key)
    {
      case 144: Serial.print("CH Up"); break;
      case 145: Serial.print("CH Down"); break;
      case 146: Serial.print("VOL Right"); break;
      case 147: Serial.print("VOL Left"); break;
      case 148: Serial.print("Mute"); break;
      case 165: Serial.print("AV/TV"); break;
      case 149: 
        Serial.print("Power");
        if(digitalRead(statLED) != 1) //This toggles the statLED every time power button is hit
          digitalWrite(statLED, HIGH);
        else
          digitalWrite(statLED, LOW);
        break;

      default: Serial.print(key);
    }

    Serial.println();
  }
}

int getIRKey() {
  int data[12];
  int i;

  while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit
  
  for(i = 0 ; i < 11 ; i++)
    data[i] = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses
  
  for(i = 0 ; i < 11 ; i++) //Parse them
  {	    
    if(data[i] > bin_1) //is it a 1?
      data[i] = 1;
    else if(data[i] > bin_0) //is it a 0?
      data[i] = 0;
    else
      return -1; //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
  }

  int result = 0;
  for(i = 0 ; i < 11 ; i++) //Convert data bits to integer
    if(data[i] == 1) result |= (1<<i);

  return result; //Return key number
}

The power button press is on my remote is 827DC13E. How can I change this code above so that it recognises my power button press?

Have a look at the IRremote library.
It makes it trivial to read the IR codes and act on them

/*
 * 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);
    if (results.value == 0xFF00FF)
    {
      Serial.println("!");
    }
    irrecv.resume(); // Receive the next value
  }
}

The power button press is on my remote is 827DC13E.

If you showed some serial output, and talked in terms of names in the code, that statement might make a lot more sense.

Do you mean that key is 827DC13E when the power button is pressed? If so, that seems unlikely, since key is an int, and the range of values that an int can hold does not include 827DC13E.