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
}
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
//
http://tronixstuff.com/tutorials > 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
}