IR sender differences

Hi,
I have two arduino nano:

IR reciver:

#include <IRremote.hpp>

/* rawR&cv.ino Example sketch for IRLib2
 *  Illustrate how to capture raw timing values for an unknow protocol.
 *  You will capture a signal using this sketch. It will output data the 
 *  serial monitor that you can cut and paste into the "rawSend.ino"
 *  sketch.
 */
// Recommend only use IRLibRecvPCI or IRLibRecvLoop for best results
#include <IRLibRecvPCI.h> 

IRrecvPCI myReceiver(2);//pin number for the receiver

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  myReceiver.enableIRIn(); // Start the receiver
  Serial.println(F("Ready to receive IR signals"));
}

void loop() {
  //Continue looping until you get a complete signal received
  if (myReceiver.getResults()) { 
    Serial.println(F("Do a cut-and-paste of the following lines into the "));
    Serial.println(F("designated location in rawSend.ino"));
    Serial.print(F("\n#define RAW_DATA_LEN "));
    Serial.println(recvGlobal.recvLength,DEC);
    Serial.print(F("uint16_t rawData[RAW_DATA_LEN]={\n\t"));
    for(bufIndex_t i=1;i<recvGlobal.recvLength;i++) {
      Serial.print(recvGlobal.recvBuffer[i],DEC);
      Serial.print(F(", "));
      if( (i % 8)==0) Serial.print(F("\n\t"));
    }
    Serial.println(F("1000};"));//Add arbitrary trailing space
    myReceiver.enableIRIn();      //Restart receiver
  }
}

and the sender:


#include <IRLibSendBase.h>
#include <IRLib_HashRaw.h>  
#include <IRLibCombo.h>     

IRsendRaw mySender;

#define IR_SEND_PWM_PIN D3
#define RAW_DATA_LEN 74

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); //delay for Leonardo
  Serial.println(F("Every time you press a key is a serial monitor we will send."));
}

void loop() {

uint16_t rawData[RAW_DATA_LEN]={
  9006, 4502, 642, 1666, 642, 566, 634, 570, 
  638, 570, 638, 566, 634, 574, 634, 570, 
  642, 566, 646, 1662, 642, 562, 638, 1670, 
  638, 570, 638, 566, 642, 566, 634, 574, 
  634, 570, 642, 566, 642, 566, 634, 570, 
  638, 570, 638, 1666, 642, 1666, 642, 566, 
  646, 562, 634, 570, 638, 570, 642, 562, 
  634, 574, 638, 1670, 638, 566, 642, 1666, 
  642, 566, 634, 570, 638, 1670, 638, 570, 
  638, 1000};

  mySender.send(rawData,RAW_DATA_LEN,38);

    delay(5000);
}

I use:

with direct connection.

My reciver display different values that I sent:

#define RAW_DATA_LEN 74
uint16_t rawData[RAW_DATA_LEN]={
	9042, 4550, 642, 1694, 634, 574, 638, 594, 
	614, 622, 610, 594, 618, 590, 642, 594, 
	634, 570, 642, 1694, 638, 594, 614, 1698, 
	634, 598, 610, 598, 634, 598, 614, 594, 
	638, 594, 638, 570, 638, 594, 614, 594, 
	638, 594, 638, 1698, 610, 1702, 642, 590, 
	642, 590, 618, 590, 642, 566, 646, 586, 
	610, 598, 634, 1702, 642, 590, 642, 1666, 
	642, 594, 614, 590, 642, 1694, 638, 598, 
	610, 1000};
Do a cut-and-paste of the following lines into the 
designated location in rawSend.ino

Where is the problem?

1 Like

Thanks for the complement but I assure I am not clairvoyant.

Since we are playing the guessing game, also post an annotated schematic showing exactly how you have wired it. Also include links to technical information on all of the hardware devices.

Physical checks first. Check tx/rx system ground connections. Toggled bits could be caused by +/- thresholds not being met due to ground connections (or lack of) either or both the transmitter and receiver systems' LED, power supply and Arduino.

I have sender with:
arduino nano
ir sender

connected:

Seeeduino Grove - Infrared Emitter
5V Red
GND Black
Not Conencted White
D3 Yellow

and reciver:
next arduino nano, connected:

using D2 with TSOP31236

Maybe frequency?

Could you write something more?

Ground/earth (GND) is used as a reference point (voltage) in determining if the "1" and "0" of data signals have cleared the "1" and "0" state (in the positive + or the negative - direction) . If system-one "ground" is at zero volts, and system-two "ground" is a little higher (or lower), a "1" on system-one might not (or might) be a "1" on system-two. Ensuring all grounds are electrically at the same potential is to make them physically the same... by connecting grounds in a "star" form (one central point, many feeders) or a "bus" form (one continuous bus-wire, many feeders), but not in a cascade (ground-one goes to ground-two, ground-two goes to ground-three, et c.).

oes this mean you connected the two units with wire, bypassing the IR sensors?

did you verify that it works hard wired before you tried the IR link?

I'll check it out

Thanks

This mean:

Seeeduino Grove - Infrared Emitter
5V Red
GND Black
Not Conencted White
D3 Yellow

without this:

Maybe frequency?

Yes. You are transmitting on 38kHz.
Change it to 36kHz

mySender.send(rawData,RAW_DATA_LEN,38);

change to

mySender.send(rawData,RAW_DATA_LEN,36);

Unfortunatelly, it didn't help.

Results are sometims different. Some interference.

I connected GND pins and the same:

#define RAW_DATA_LEN 74
uint16_t rawData[RAW_DATA_LEN]={
	9046, 4546, 642, 1714, 618, 606, 614, 606, 
	614, 1714, 614, 634, 586, 606, 614, 610, 
	610, 582, 638, 1718, 614, 606, 614, 1718, 
	614, 606, 614, 634, 586, 578, 642, 606, 
	614, 634, 586, 634, 586, 582, 638, 610, 
	610, 610, 610, 1722, 606, 1722, 610, 582, 
	638, 582, 638, 1694, 638, 582, 638, 582, 
	638, 582, 638, 1694, 614, 606, 614, 1714, 
	638, 586, 634, 586, 634, 1694, 614, 606, 
	614, 1000};
Do a cut-and-paste of the following lines into the 
designated location in rawSend.ino

#define RAW_DATA_LEN 74
uint16_t rawData[RAW_DATA_LEN]={
	9042, 4550, 638, 1690, 638, 582, 638, 582, 
	638, 1666, 666, 582, 638, 554, 666, 582, 
	638, 554, 666, 1666, 662, 558, 662, 1666, 
	666, 586, 634, 586, 634, 558, 662, 558, 
	662, 586, 646, 574, 634, 558, 674, 546, 
	674, 550, 670, 1662, 666, 1662, 670, 550, 
	602, 618, 602, 1726, 662, 558, 662, 562, 
	666, 554, 614, 1714, 614, 606, 614, 1690, 
	642, 606, 614, 606, 658, 1646, 638, 610, 
	610, 1000};
Do a cut-and-paste of the following lines into the 
designated location in rawSend.ino

#define RAW_DATA_LEN 74
uint16_t rawData[RAW_DATA_LEN]={
	9046, 4546, 642, 1686, 642, 578, 642, 578, 
	642, 1690, 642, 578, 642, 578, 642, 578, 
	642, 550, 670, 1662, 670, 550, 670, 1662, 
	666, 554, 666, 610, 554, 610, 666, 582, 
	638, 582, 638, 582, 638, 554, 666, 558, 
	662, 558, 662, 1666, 666, 1694, 634, 558, 
	610, 610, 662, 1666, 666, 558, 662, 558, 
	662, 558, 638, 1690, 610, 610, 610, 1722, 
	642, 578, 642, 578, 674, 1658, 638, 582, 
	638, 1000};

I power the arduino from the computer's usb ports.

Change the transmitter, compare results.
Change the receiver, compare results.

I found ir led from mouse and used it (with 100ohm resistor).
Results are always different.

I found different reciver:

Still results are always different.

I would like to use ir led for control air conditional panel.

I changed code:

sender:

#include <Arduino.h>

#include "PinDefinitionsAndMore.h"  // Define macros for input and output pin etc.

#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used.
#include <IRremote.hpp>

#define DELAY_AFTER_SEND 2000
#define DELAY_AFTER_LOOP 5000

void setup() {
    Serial.begin(115200);

#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
    delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

#if defined(IR_SEND_PIN)
    IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
#  if defined(IR_SEND_PIN_STRING)
    Serial.println(F("Send IR signals at pin " IR_SEND_PIN_STRING));
#  else
    Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN)));
#  endif
#else
    IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
    Serial.println(F("Send IR signals at pin 3"));
#endif

#if !defined(SEND_PWM_BY_TIMER)
    /*
     * Print internal software PWM signal generation info
     */
    IrSender.enableIROut(38); // Call it with 38 kHz just to initialize the values printed below
    Serial.print(F("Send signal mark duration is "));
    Serial.print(IrSender.periodOnTimeMicros);
    Serial.print(F(" us, pulse narrowing correction is "));
    Serial.print(IrSender.getPulseCorrectionNanos());
    Serial.print(F(" ns, total period is "));
    Serial.print(IrSender.periodTimeMicros);
    Serial.println(F(" us"));
#endif
}

/*
 * Set up the data to be sent.
 * For most protocols, the data is build up with a constant 8 (or 16 byte) address
 * and a variable 8 bit command.
 * There are exceptions like Sony and Denon, which have 5 bit address.
 */
uint16_t sAddress = 0x0102;
uint8_t sCommand = 0x34;
uint16_t s16BitCommand = 0x5634;
uint8_t sRepeats = 0;

void loop() {
    Serial.println(F("Send NEC with 8 bit address"));
    Serial.flush();

        uint32_t tRawData[]={0x50100501, 0x2};
    IrSender.sendPulseDistanceWidthFromArray(36, 8950, 4400, 700, 1600, 700, 500, &tRawData[0], 35, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS);

    delay(DELAY_AFTER_LOOP); // additional delay at the end of each loop
}

reciever:

#include <Arduino.h>

#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.

#if !defined(RAW_BUFFER_LENGTH)
#  if RAMEND <= 0x4FF || RAMSIZE < 0x4FF
#define RAW_BUFFER_LENGTH  180  // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100.
#  elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF
#define RAW_BUFFER_LENGTH  600  // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100.
#  else
#define RAW_BUFFER_LENGTH  750  // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100.
#  endif
#endif

/*
 * MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
 * to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142.
 *
 * You can change this value accordingly to the receiver module you use.
 * The required value can be derived from the timings printed here.
 * Keep in mind that the timings may change with the distance
 * between sender and receiver as well as with the ambient light intensity.
 */
#define MARK_EXCESS_MICROS    20    // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules.

//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.

#include <IRremote.hpp>

//+=============================================================================
// Configure the Arduino
//
void setup() {
    pinMode(LED_BUILTIN, OUTPUT);

    Serial.begin(115200);   // Status message will be sent to PC at 9600 baud
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
    delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

    Serial.print(F("Ready to receive IR signals of protocols: "));
    printActiveIRProtocols(&Serial);
    Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));

    // infos for receive
    Serial.print(RECORD_GAP_MICROS);
    Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
    Serial.print(MARK_EXCESS_MICROS);
    Serial.println();
    Serial.println(F("Because of the verbose output (>200 ms at 115200), repeats are probably not dumped correctly!"));
    Serial.println();
}

//+=============================================================================
// The repeating section of the code
//
void loop() {
    if (IrReceiver.decode()) {  // Grab an IR code
        // At 115200 baud, printing takes 200 ms for NEC protocol and 70 ms for NEC repeat
        Serial.println(); // blank line between entries
        Serial.println(); // 2 blank lines between entries
        IrReceiver.printIRResultShort(&Serial);
        // Check if the buffer overflowed
        if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
            Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__));
            // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
        } else {
            if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
                Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
            }
            Serial.println();
            IrReceiver.printIRSendUsage(&Serial);
            Serial.println();
            Serial.println(F("Raw result in internal ticks (50 us) - with leading gap"));
            IrReceiver.printIRResultRawFormatted(&Serial, false); // Output the results in RAW format
            Serial.println(F("Raw result in microseconds - with leading gap"));
            IrReceiver.printIRResultRawFormatted(&Serial, true);  // Output the results in RAW format
            Serial.println();                               // blank line between entries
            Serial.print(F("Result as internal 8bit ticks (50 us) array - compensated with MARK_EXCESS_MICROS="));
            Serial.println(MARK_EXCESS_MICROS);
            IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false); // Output the results as uint8_t source code array of ticks
            Serial.print(F("Result as microseconds array - compensated with MARK_EXCESS_MICROS="));
            Serial.println(MARK_EXCESS_MICROS);
            IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, true); // Output the results as uint16_t source code array of micros
            IrReceiver.printIRResultAsCVariables(&Serial);  // Output address and data as source code variables

            IrReceiver.compensateAndPrintIRResultAsPronto(&Serial);
        }
        IrReceiver.resume();                            // Prepare for the next value
    }
}

Still I have different result:

Protocol=PulseDistance Raw-Data=0x2 35 bits LSB first

Send with:
    uint32_t tRawData[]={0x50100501, 0x2};
    IrSender.sendPulseDistanceWidthFromArray(38, 8950, 4300, 750, 1550, 750, 450, &tRawData[0], 35, PROTOCOL_IS_LSB_FIRST, <RepeatPeriodMillis>, <numberOfRepeats>);

Raw result in internal ticks (50 us) - with leading gap
rawData[74]: 
 -65535
 +179,-86
 +15,-31 +14,- 9 +15,- 9 +15,- 9
 +15,- 9 +15,- 9 +15,- 9 +15,- 9
 +15,-31 +15,- 9 +15,-31 +14,-10
 +14,-10 +14,-10 +14,-10 +14,- 9
 +15,-10 +14,-10 +14,- 9 +15,- 9
 +15,-31 +15,- 9 +15,- 9 +15,- 9
 +15,- 9 +15,- 9 +15,- 9 +15,- 9
 +15,-31 +14,- 9 +15,-31 +15,- 9
 +15,- 9 +15,-31 +15,- 9 +15
Sum: 1271
Raw result in microseconds - with leading gap
rawData[74]: 
 -3276750
 +8950,-4300
 + 750,-1550 + 700,- 450 + 750,- 450 + 750,- 450
 + 750,- 450 + 750,- 450 + 750,- 450 + 750,- 450
 + 750,-1550 + 750,- 450 + 750,-1550 + 700,- 500
 + 700,- 500 + 700,- 500 + 700,- 500 + 700,- 450
 + 750,- 500 + 700,- 500 + 700,- 450 + 750,- 450
 + 750,-1550 + 750,- 450 + 750,- 450 + 750,- 450
 + 750,- 450 + 750,- 450 + 750,- 450 + 750,- 450
 + 750,-1550 + 700,- 450 + 750,-1550 + 750,- 450
 + 750,- 450 + 750,-1550 + 750,- 450 + 750
Sum: 63550

I recorded pilot button for shine panel.

After use my sender, air conditional panel dosn't shine.

Where is the problem?

LED backwards (anode +, cathode -)

When I change sender/reciver pins it doesn't work.

LEDs have anode and cathode pins (not sender/receiver pins). Please explain your observation.

I switched connections of legs.
plus connect to opisite leg and minus- connect to oposite leg (first time with sender led and second with reciver led).

In both cases I didn't have any results on serial monitor.

I don't know what I am doing wrong.

I think, I connect everything correct. What is going on?

Do you have any example of ir sender in web?