Tuesday, November 22, 2011

Improved IR code Reciever

Now only a little reformatting is needed on the IR code serial data received before inserting it into a Arduino IR sending program. All you have to do is to remove all digits before the first comma:

Raw (68): 11152,9100,4450,550,600,500,650,500,600,550,600,500,600,550,600,500,650,500,600,500,1750,500,600,550,600,600,1650,550,1750,500,600,500,600,550,1700,550,1750,500,600,550,1750,500,600,500,1750,500,600,550,600,550,600,500,600,550,1750,450,650,500,1750,500,600,550,1750,500,1750,500,1750,500
to
Raw (68): 9100,4450,550,600,500,650,500,600,550,600,500,600,550,600,500,650,500,600,500,1750,500,600,550,600,600,1650,550,1750,500,600,500,600,550,1700,550,1750,500,600,550,1750,500,600,500,1750,500,600,550,600,550,600,500,600,550,1750,450,650,500,1750,500,600,550,1750,500,1750,500,1750,500

But if it is a recognized code, then it will output like(still need to remove all digits before the first comma):
Decoded NEC: 99E817 (32 bits)---OR---Raw (68): 47990,9100,4450,600,550,550,550,550,600,600,550,550,550,550,600,500,600,600,550,600,1650,600,500,600,550,550,1700,600,1650,550,600,500,600,550,1700,550,1750,550,1700,600,1650,550,550,600,1650,550,600,600,550,550,550,600,550,500,600,600,550,500,1750,550,550,550,1750,500,1750,500,1750,500
Look at my previous post on how to use these RAW or DECODED IR codes...


CODE:
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.println("Could not decode message");
  }
  else {
    if (results->decode_type == NEC) {
      Serial.print("Decoded NEC: ");
    }
    else if (results->decode_type == SONY) {
      Serial.print("Decoded SONY: ");
    }
    else if (results->decode_type == RC5) {
      Serial.print("Decoded RC5: ");
    }
    else if (results->decode_type == RC6) {
      Serial.print("Decoded RC6: ");
    }
    Serial.print(results->value, HEX);
    Serial.print(" (");
    Serial.print(results->bits, DEC);
    Serial.print(" bits)---OR---");
  }
  String Test1 = String();
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

    for (int i = 0; i < count; i++)
  {
    Test1+=(results->rawbuf[i]*USECPERTICK);
    Test1+=(",");
  }
  Serial.println(Test1);
}


void loop() {
  if (irrecv.decode(&results))
  {
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}

2 comments:

  1. hello
    i catch this signal

    Raw: (31) 3028, -1024, 1048, -2968, 968, -3024, 964, -3028, 2948, -1024, 1044, -2972, 964, -3028, 964, -21156, 3024, -1028, 1052, -2964, 960, -3032, 968, -3024, 2940, -1032, 1048, -2972, 964, -3028, 964,


    how to reproduce it ?

    ReplyDelete
    Replies
    1. did you read the previous post link? http://dduino.blogspot.com/2011/11/use-sonar-to-control-tv.html

      Delete