Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

my IR receiver received just UNKNOWN: 0 why?

laoadam

Member level 2
Joined
Feb 22, 2019
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
323
Hi,
The sender send NEC date, but the receiver got UNKNOWN, why?
Code:
#include <Arduino.h>

sender (pin3) code:
/*
   Define macros for input and output pin etc.

   #elif defined(__AVR__) // Default as for ATmega328 like on Uno, Nano etc.
  #define IR_RECEIVE_PIN      2 // To be compatible with interrupt example, pin 2 is chosen here.
  #define IR_SEND_PIN         3

*/
///// #include "PinDefinitionsAndMore.h"

///// #elif defined(__AVR__) // Default as for ATmega328 like on Uno, Nano etc.
#define IR_RECEIVE_PIN      2 // To be compatible with interrupt example, pin 2 is chosen here.
#define IR_SEND_PIN         3
#define TONE_PIN            4
#define APPLICATION_PIN     5
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
#define _IR_TIMING_TEST_PIN  7

#include <IRremote.hpp>

#define DELAY_AFTER_SEND 2000
#define DELAY_AFTER_LOOP 5000

int button = 8;

void setup() {
  Serial.begin(115200);
  Serial.print("T_gd_setup!");

  Serial.print("File   : "), Serial.println(__FILE__);
  Serial.print("Date   : "), Serial.println(__DATE__);

  /*
     Print internal signal generation info
  */

  IrSender.enableIROut(38); // Call it with 38 kHz to initialize the values printed below
  /*
  Serial.print(F("Send signal mark duration is "));
  Serial.print(IrSender.periodOnTimeMicros);
  Serial.print(F(" us, pulse correction is "));
  Serial.print(IrSender.getPulseCorrectionNanos());
  Serial.print(F(" ns, total period is "));
  Serial.print(IrSender.periodTimeMicros);
  Serial.println(F(" us"));
*/
  pinMode(button, INPUT);

}

uint16_t sAddress = 0x0102; ////// A remote control that is programmed with device address 4E.24 can only control the digital signage display that is
                              /////// also programmed with device address 4E.24.
uint8_t sCommand = 0x34;    //// NEC command (HEX) 0x34 = Fast Backward, DEC 52,
uint8_t sRepeats = 0;

void loop() {
  /*
     Print values
  */
  /*
  Serial.println();
  Serial.print(F("address=0x"));
  Serial.print(sAddress, HEX);
  Serial.print(F(" command=0x"));
  Serial.print(sCommand, HEX);
  Serial.print(F(" repeats="));
  Serial.println(sRepeats);
  Serial.println();
  Serial.println();
  Serial.flush();
*/
  if (digitalRead(button) == HIGH) {

    Serial.println(F("Send NEC with 8 bit address"));
    Serial.flush();
    IrSender.sendNEC(sAddress & 0xFF, sCommand, sRepeats);
    delay(DELAY_AFTER_SEND); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal

    Serial.println(F("Send NEC with 16 bit address"));
    Serial.flush();
    IrSender.sendNEC(sAddress, sCommand, sRepeats);
    delay(DELAY_AFTER_SEND);
  }
}

receiver (pin2) code:

Code:
#include <IRremote.h>

const int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

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

  Serial.print("File   : "), Serial.println(__FILE__);
  Serial.print("Date   : "), Serial.println(__DATE__);

}

void loop() {
  if (irrecv.decode()) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    }
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

sm UNKNOWN.JPG
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top