IR Raw codes won't work

Everything related to protocols and IR codes
Post Reply
biglemon29
Posts: 1
Joined: Tue Mar 05, 2019 1:45 am

IR Raw codes won't work

Post by biglemon29 » Tue Mar 05, 2019 1:54 am

Hi, I am trying to create an IR remote for a lasko space heater I have. The transmitting code I wrote will not work, It will not turn on the heater

This is the sending code I have

Code: Select all

/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */ //   http://www.instructables.com/id/Arduino-Remote-Control-Less-10/?ALLSTEPS

#include <IRremote.h>

#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11); // TX, RX
String readdata;

IRsend irsend;  // An IR LED must be connected to Arduino PWM pin 3.
 //here put your raw code//

unsigned int raw1[23] = {1250, 450, 1250, 400, 450, 1300, 1250, 400, 1250, 450, 400, 1300, 400, 1300, 400, 1300, 400, 1300, 400, 1300, 350, 1300, 1250,}; 








void setup()
{
  Serial.begin(9600);
   BT.begin(9600);
  
  
}



void loop() {


  delay(3000);
  irsend.sendRaw(raw1,23,38);
  Serial.println("Sending Code");
  
  

 
}
To obtain the RAW codes I tried 2 different sketches, they give me two different bit lengths

Here is the first sketch I used

Code: Select all

//------------------------------------------------------------------------------
// Include the IRremote library header
//
#include <IRremote.h>

//------------------------------------------------------------------------------
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
//
int recvPin = 11;
IRrecv irrecv(recvPin);

//+=============================================================================
// Configure the Arduino
//
void  setup ( )
{
  Serial.begin(9600);   // Status message will be sent to PC at 9600 baud
  irrecv.enableIRIn();  // Start the receiver
}

//+=============================================================================
// Display IR code
//
void  ircode (decode_results *results)
{
  // Panasonic has an Address
  if (results->decode_type == PANASONIC) {
    Serial.print(results->address, HEX);
    Serial.print(":");
  }

  // Print Code
  Serial.print(results->value, HEX);
}

//+=============================================================================
// Display encoding type
//
void  encoding (decode_results *results)
{
  switch (results->decode_type) {
    default:
    case UNKNOWN:      Serial.print("UNKNOWN");       break ;
    case NEC:          Serial.print("NEC");           break ;
    case SONY:         Serial.print("SONY");          break ;
    case RC5:          Serial.print("RC5");           break ;
    case RC6:          Serial.print("RC6");           break ;
    case DISH:         Serial.print("DISH");          break ;
    case SHARP:        Serial.print("SHARP");         break ;
    case JVC:          Serial.print("JVC");           break ;
    case SANYO:        Serial.print("SANYO");         break ;
    case MITSUBISHI:   Serial.print("MITSUBISHI");    break ;
    case SAMSUNG:      Serial.print("SAMSUNG");       break ;
    case LG:           Serial.print("LG");            break ;
    case WHYNTER:      Serial.print("WHYNTER");       break ;
    case AIWA_RC_T501: Serial.print("AIWA_RC_T501");  break ;
    case PANASONIC:    Serial.print("PANASONIC");     break ;
    case DENON:        Serial.print("Denon");         break ;
  }
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpInfo (decode_results *results)
{
  // Check if the buffer overflowed
  if (results->overflow) {
    Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF");
    return;
  }

  // Show Encoding standard
  Serial.print("Encoding  : ");
  encoding(results);
  Serial.println("");

  // Show Code & length
  Serial.print("Code      : ");
  ircode(results);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpRaw (decode_results *results)
{
  // Print Raw data
  Serial.print("Timing[");
  Serial.print(results->rawlen-1, DEC);
  Serial.println("]: ");

  for (int i = 1;  i < results->rawlen;  i++) {
    unsigned long  x = results->rawbuf[i] * USECPERTICK;
    if (!(i & 1)) {  // even
      Serial.print("-");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
    } else {  // odd
      Serial.print("     ");
      Serial.print("+");
      if (x < 1000)  Serial.print(" ") ;
      if (x < 100)   Serial.print(" ") ;
      Serial.print(x, DEC);
      if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one
    }
    if (!(i % 8))  Serial.println("");
  }
  Serial.println("");                    // Newline
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpCode (decode_results *results)
{
  // Start declaration
  Serial.print("unsigned int  ");          // variable type
  Serial.print("rawData[");                // array name
  Serial.print(results->rawlen - 1, DEC);  // array size
  Serial.print("] = {");                   // Start declaration

  // Dump data
  for (int i = 1;  i < results->rawlen;  i++) {
    Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
    if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one
    if (!(i & 1))  Serial.print(" ");
  }

  // End declaration
  Serial.print("};");  // 

  // Comment
  Serial.print("  // ");
  encoding(results);
  Serial.print(" ");
  ircode(results);

  // Newline
  Serial.println("");

  // Now dump "known" codes
  if (results->decode_type != UNKNOWN) {

    // Some protocols have an address
    if (results->decode_type == PANASONIC) {
      Serial.print("unsigned int  addr = 0x");
      Serial.print(results->address, HEX);
      Serial.println(";");
    }

    // All protocols have data
    Serial.print("unsigned int  data = 0x");
    Serial.print(results->value, HEX);
    Serial.println(";");
  }
}

//+=============================================================================
// The repeating section of the code
//
void  loop ( )
{
  decode_results  results;        // Somewhere to store the results

  if (irrecv.decode(&results)) {  // Grab an IR code
    dumpInfo(&results);           // Output the results
    dumpRaw(&results);            // Output the results in RAW format
    dumpCode(&results);           // Output the results as source code
    Serial.println("");           // Blank line between entries
    irrecv.resume();              // Prepare for the next value
  }
}
This gave me a 23 bit array

Code: Select all

Encoding  : UNKNOWN
Code      : A32AB931 (32 bits)
Timing[23]: 
     +1250, - 450     +1250, - 450     + 400, -1300     +1200, - 500
     +1200, - 500     + 350, -1300     + 400, -1300     + 400, -1300
     + 400, -1300     + 400, -1300     + 350, -1300     +1250
unsigned int  rawData[23] = {1250,450, 1250,450, 400,1300, 1200,500, 1200,500, 350,1300, 400,1300, 400,1300, 400,1300, 400,1300, 350,1300, 1250};  // UNKNOWN A32AB931

This was the next sketch

Code: Select all

#include <IRremoteInt.h>
#include <IRremote.h>

// If one keypress results in multiple codes being output, then
// change in IRremoteInt.h:
// #define _GAP 50000
// This sketchThis sketch was obtained from:
//  For more info:
//  jason welsh
//   https://www.youtube.com/watch?v=eR8sQq3pl20
//  https://docs.google.com/document/d/1QgmFbFlB0aI3swrhQkacRe3C-cIS0p1t0TV36-i2lLo/edit

//   http://www.instructables.com/id/Arduino-Remote-Control-Less-10/?ALLSTEPS
/////////////////////////////////
//  I made a few small changes

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

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

int c = 0;

void dump(decode_results *results) {
  int count = results->rawlen;
  Serial.println(c);
  c++;
  Serial.println("For IR Scope: ");
  for (int i = 1; i < count; i++) {
   
    if ((i % 2) == 1) {
      Serial.print("+");
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
  Serial.println("For Arduino sketch: ");
  Serial.print("unsigned int raw");
  Serial.print(c);
   Serial.print("[");
  Serial.print(count, DEC);
  Serial.print("] = {");
  for (int i = 1; i < count; i++) {
   
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.print((int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(",");
  }
  Serial.print("};");
  Serial.println("");
  Serial.print("irsend.sendRaw(");
  Serial.print("raw");
  Serial.print(c);
  Serial.print(",");
  Serial.print(count, DEC);
  Serial.print(",38);");
  Serial.println("");
  Serial.println("");
}

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

This gave me a 24 bit array

Code: Select all

For IR Scope: 
+1250 -450 +1250 -450 +350 -1300 +1250 -450 +1250 -450 +400 -1300 +400 -1300 +350 -1300 +450 -1250 +400 -1300 +400 -1300 +1250 
For Arduino sketch: 
unsigned int raw4[24] = {1250,450,1250,450,350,1300,1250,450,1250,450,400,1300,400,1300,350,1300,450,1250,400,1300,400,1300,1250,};
irsend.sendRaw(raw4,24,38);

Which sketch would be most accurate for receiving the RAW codes? Could this 1 bit difference be effecting the remote not working properly? Or is there another potential issue on the transmitting end not turning on the heater

User avatar
AnalysIR
Site Admin
Posts: 519
Joined: Sat Aug 31, 2013 3:51 pm
Location: Dublin, Ireland
Contact:

Re: IR Raw codes won't work

Post by AnalysIR » Wed Mar 06, 2019 6:49 am

Hi I am travelling for the next few days and will respond next week.

Post Reply