Arduino IR Code troubles

Hi,
I've been trying to get my Arduino to send a few IR Remote codes to a projector without any luck. I have code which displays output from my remote using
IrReceiver.printIRResultShort(&Serial);

For the power button I receive the following:

Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first
Protocol=NEC Address=0x1608 Command=0x87 Repeat gap=43950us

From the OK button:

Protocol=NEC Address=0x1608 Command=0xB2 Raw-Data=0x4DB21608 32 bits LSB first

From the Right Arrow key:

Protocol=NEC Address=0x1608 Command=0x8E Raw-Data=0x718E1608 32 bits LSB first
Protocol=NEC Address=0x1608 Command=0x8E Repeat gap=43900us

Ultimately, I want to simulate several remote key strokes when the projector and Arduino power up to automatically begin the short ghost movie which is in a window.

I've included the latest code in my attempt to turn on the projector which has been unsuccessful.

Any help or suggestions would be greatly appreciated
Infrared_Sender.ino (979 Bytes)

DroneBotWorkShop introduces transmitting codes on his web site...

I think this line is missing from your setup:

" sender.begin(IR_PIN); "

Now I'm even more confused. I have both a sender and receiver hooked up. I changed the code to capture and display what I sent. Why is a different Protocol and output? Here is the Serial output

button pushed
Code sent!
button pushed
1068E11E
Protocol=Onkyo Address=0x1E Command=0x1068 Raw-Data=0x1068E11E 32 bits LSB first
Infrared_Sender.ino (1.4 KB)
Code sent!

So I tried a different approach. I setup two Arduinos, one to send the IR, and one to receive the IR. I also changed the parameter information passing the address and command not the Hex code. The following is the Serial Monitor output of the send from the Arduino followed by the actual send from the remote. What am I missing to get the Arduino send code to show the same as the remote? Currently, it does not power on the projector.

The following was received using the Arduino as the sender:

78871608
Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

78871608
Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

The following comes from the actual remote:

78871608
Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first
0
Protocol=NEC Address=0x1608 Command=0x87 Repeat gap=43150us

IR_Sender_Independent.ino (1.4 KB)

Put this line to your receiver code:
IrReceiver.printIRSendUsage(&Serial);
So it's giving you exact syntax to send it.

I modified the receiver code to include IrReceiver.printIRSendUsage(&Serial);
When using the actual remote the Serial output is the following showing how to send and what was actually received:


Send with: IrSender.sendNEC(0x1608, 0x87, );


Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

When I used the Sender sketch with
sender.sendNEC(0x1608,0x87,0);
the receiver output showed the following:


Send with: IrSender.sendNEC(0x1608, 0x87, );


Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

I have both Arduinos positioned in front of the projector. The only time the projector responds is with the remote. I noticed if I held the button on the remote a bit longer I would receive the repeat gap output. I held the button on the Arduino, and it repeated the same as above, yet the projector did not respond.

I also tried using
sender.sendNEC(0x1608,0x87,1);
but the Serial output still showed only one command. Two other attempts were with
sender.sendNECRaw(0x78871608,1);
which returned the same as above. Then sender.sendNEC2(0x1608,0x87,2);
which returned


Send with: IrSender.sendNEC(0x1608, 0x87, );


Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first


Send with: IrSender.sendNEC2(0x1608, 0x87, );


Protocol=NEC2 Address=0x1608 Command=0x87 Repeat gap=45650us Raw-Data=0x78871608 32 bits LSB first

IR_Sender_Independent.ino (1.5 KB)

sketch_IR_Receive_codes.ino (584 Bytes)

Assuming you are using an Uno, Nano or Pro Mini, you might want to try using the IRCaptureRaw.ino sketch from this Github repo:

https://github.com/gbhug5a/SimpleIRRaw

Flash that sketch to your receiver Arduino, with the IR Receiver on D8, then try the remote, and then your sender Arduino, both supposedly sending the same key, and see if they are the same, or post them here if you're not sure.

The raw receiver sketch does not use any library, so there is no translation into protocol or LSB/MSB or address/command. The serial monitor will display what is actually being sent.

Use a very fast keypress on the remote so you can see if it automatically sends a repeat. The sketch will record what is received over a full second from the first transmission, so it will pick that up.

You also might want to give us the make and model of your projector and of its remote.

The first dump is from the remote, the second is from the Arduino send

Waiting for IR transmission...

On    Off     On    Off     On    Off     On    Off

8889, 4549, 566, 539, 559, 571, 569, 537,
554, 1732, 565, 539, 562, 539, 533, 598,
589, 541, 561, 542, 559, 1702, 537, 1749,
566, 537, 562, 1697, 564, 567, 567, 541,
520, 607, 566, 1669, 526, 1757, 502, 1758,
565, 539, 526, 629, 530, 576, 565, 538,
502, 1758, 554, 576, 529, 601, 531, 573,
562, 1698, 554, 1709, 523, 1733, 561, 1723,
566, 540, 565

On Off On Off On Off On Off

8815, 4603, 488, 664, 459, 688, 486, 670,
462, 1808, 458, 690, 458, 690, 441, 694,
465, 668, 457, 747, 459, 1780, 515, 1754,
485, 683, 466, 1778, 489, 657, 467, 711,
435, 717, 459, 1809, 434, 1832, 435, 1838,
434, 717, 433, 717, 432, 694, 485, 662,
464, 1807, 462, 716, 435, 686, 463, 689,
462, 1806, 434, 1824, 467, 1809, 456, 1807,
464, 691, 457

Was having issues with the IRCaptureRaw the only way I managed to get the Serial output was to start the monitor at 9600 baud and change it to 115200 so it was waiting for IR Transmission.

The projector is ARTSEA model M8. The remote has no indication of make or model

IRCaptureRaw.ino (5.0 KB)

I ran the Raw again with the remote and had a few different numbers come up

Waiting for IR transmission...

On    Off     On    Off     On    Off     On    Off

8900, 4532, 567, 538, 566, 563, 503, 603,
565, 1718, 531, 575, 565, 540, 565, 561,
528, 579, 556, 575, 564, 1695, 565, 1719,
567, 537, 566, 1693, 568, 536, 591, 539,
501, 630, 563, 1672, 522, 1761, 566, 1692,
594, 512, 564, 562, 558, 574, 566, 537,
569, 1691, 566, 537, 559, 596, 527, 578,
565, 1695, 558, 1704, 521, 1735, 565, 1721,
567, 536, 568

then ran the Arduino again

On Off On Off On Off On Off

8789, 4657, 436, 683, 464, 718, 416, 721,
459, 1778, 488, 691, 434, 686, 465, 688,
488, 660, 488, 666, 483, 1814, 460, 1808,
433, 716, 434, 1835, 434, 717, 439, 706,
441, 683, 464, 1839, 429, 1830, 436, 1802,
487, 663, 459, 686, 464, 686, 465, 684,
466, 1800, 465, 717, 435, 715, 438, 705,
466, 1832, 412, 1805, 461, 1805, 461, 1809,
461, 690, 462

Looks identic to me. Could be receiver too picky about timings...Or distance?

I only see one header 8900,4500.
Not multiple signals.

Are you using receiver example code, or some custom code? It's not clear how many repeats the signal has..
What brand is your device?

Ok, it certainly appears to be NEC protocol. But in NEC, there are only a few possible values for the On and Off periods. The start bit is nominally 9000us followed by 4500us Off. After that, the actual transmission contents consists of a 562.5us On period followed by either a 562.5us Off period or a 1687.5us Off period, depending on whether the bit is a zero or a one.

So nominally, your transmission should look like this:

9000, 4500, 562, 562, 562, 562, 562, 562,
562, 1688, 562, 562, 562, 562, 562, 562,
562, 562, 562, 562, 562, 1688, 562, 1688,
562, 562, 562, 1688, 562, 562, 562, 562,
562, 562, 562, 1688, 562, 1688, 562, 1688,
562, 562, 562, 562, 562, 562, 562, 562,
562, 1688, 562, 562, 562, 562, 562, 562,
562, 1688, 562, 1688, 562, 1688, 562, 1688,
562, 562, 562

It looks like your remote comes reasonably close to that, at least close enough to work on the projector. But your sending Arduino appears to make the On periods significantly shorter than they should be, and the Off periods significantly longer. Since your library recognizes this as NEC, and sends the right code, I don't see why the timing is so off.

We don't know if that's the reason it isn't working. Other possibilities would be that either the standard oscillation frequency of 38KHz, or the typical 940nm IR "color", is not being used by Artsea. Or, possibly, your transmitting IE LED is not 940nm. But typically, modest variations from those standards work well enough.

To find out if it's just the timing problem, I'd suggest you go back to the repo and download its sending sketch. Then replace the table in that sketch with the table I posted above, and flash the sketch to your sending Arduino. That sending sketch will have impeccably correct timing. So if that doesn't work either, then it must be something else that's wrong, like the frequency or color, or possibly not enough power to the LED.

I have attached both sketches. I only added a button so I could control when the transmission would take place. The receiving sketch returned the following which comes no where close to the input:

Adjust = 0
Enter new Adjust value, or [Enter]
Adjust = 0
Waiting for IR transmission...

On    Off     On    Off     On    Off     On    Off

3316, 250, 5291, 4628, 386, 752, 357, 699,
432, 699, 330, 4321, 220, 951, 118, 715,
405, 727, 327, 1892, 432, 1866, 381, 837,
269, 1958, 288, 782, 323, 1811, 433, 1840,
295, 4338, 205, 924, 210, 905, 203, 703,
406, 888, 135, 2143, 125, 826, 316, 780,
331, 789, 318, 1975, 270, 1864, 380, 2082,
266, 1726, 439

IRCaptureRaw.ino (5.0 KB)

IRSendRaw.ino (4.0 KB)

No, it's not the same at all. I'll try to duplicate your results. Can you say what Arduinos you are using, and how your send IRLED is driven?

Edit: In the Send sketch, please change the 36 in the loop() section to 38. That's the proper KHz for NEC. Also, please remove the serial and pushbutton stuff you added. I don't know what effect they have on the interrupts. You can push the Arduino's reset button to initiate the send again if needed.

Using my original send sketch and the ReceiveDump from the IRRemote library the following is from the dump:

Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

Send with: IrSender.sendNEC(0x1608, 0x87, <numberOfRepeats>);

Raw result in internal ticks (50 us) - with leading gap

rawData[68]:

-65535

+175,-91

+ 9,-14 + 9,-14 +10,-13 + 9,-36

+ 9,-13 + 9,-14 + 9,-14 + 9,-14

+ 9,-13 +10,-35 + 9,-36 +10,-14

+ 8,-36 +10,-13 + 9,-14 + 9,-14

+ 9,-36 + 8,-37 + 9,-35 +10,-13

+ 9,-14 + 9,-13 +10,-13 + 9,-36

+10,-13 + 9,-14 + 9,-13 +10,-35

+10,-35 + 9,-37 + 8,-37 + 9,-13

+ 9

Sum: 1270

Raw result in microseconds - with leading gap

rawData[68]:

-3276750

+8750,-4550

+ 450,- 700 + 450,- 700 + 500,- 650 + 450,-1800

+ 450,- 650 + 450,- 700 + 450,- 700 + 450,- 700

+ 450,- 650 + 500,-1750 + 450,-1800 + 500,- 700

+ 400,-1800 + 500,- 650 + 450,- 700 + 450,- 700

+ 450,-1800 + 400,-1850 + 450,-1750 + 500,- 650

+ 450,- 700 + 450,- 650 + 500,- 650 + 450,-1800

+ 500,- 650 + 450,- 700 + 450,- 650 + 500,-1750

+ 500,-1750 + 450,-1850 + 400,-1850 + 450,- 650

+ 450

Sum: 63500

Result as internal 8bit ticks (50 us) array - compensated with MARK_EXCESS_MICROS=20

uint8_t rawTicks[67] = {175,91, 9,14, 9,14, 10,13, 9,36, 9,13, 9,14, 9,14, 9,14, 9,13, 10,35, 9,36, 10,14, 8,36, 10,13, 9,14, 9,14, 9,36, 8,37, 9,35, 10,13, 9,14, 9,13, 10,13, 9,36, 10,13, 9,14, 9,13, 10,35, 10,35, 9,37, 8,37, 9,13, 9}; // Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

Result as microseconds array - compensated with MARK_EXCESS_MICROS=20

uint16_t rawData[67] = {8730,4570, 430,720, 430,720, 480,670, 430,1820, 430,670, 430,720, 430,720, 430,720, 430,670, 480,1770, 430,1820, 480,720, 380,1820, 480,670, 430,720, 430,720, 430,1820, 380,1870, 430,1770, 480,670, 430,720, 430,670, 480,670, 430,1820, 480,670, 430,720, 430,670, 480,1770, 480,1770, 430,1870, 380,1870, 430,670, 430}; // Protocol=NEC Address=0x1608 Command=0x87 Raw-Data=0x78871608 32 bits LSB first

uint16_t address = 0x1608;

uint16_t command = 0x87;

uint32_t rawData = 0x78871608;

Pronto Hex as string

char prontoData[] = "0000 006D 0022 0000 0151 00AE 0012 001A 0012 001A 0014 0018 0012 0044 0012 0018 0012 001A 0012 001A 0012 001A 0012 0018 0014 0043 0012 0044 0014 001A 0010 0044 0014 0018 0012 001A 0012 001A 0012 0044 0010 0046 0012 0043 0014 0018 0012 001A 0012 0018 0014 0018 0012 0044 0014 0018 0012 001A 0012 0018 0014 0043 0014 0043 0012 0046 0010 0046 0012 0018 0012 06C3 ";

My sending Arduino is an UNO
My Receiving is an UNO rev3

From Amazon:

IR_Sender_Independent.ino (1.5 KB)

ReceiveDump.ino (8.5 KB)

I'm using two Nanos. I'm driving the send IRLED with an NPN transistor, emitter to ground, a 1K base resistor from D10, and 5V through a 47 ohm resistor in series with the LED to the collector. I changed the table in the send sketch to the one I posted above containing the nominal values. And I changed the KHz value in loop() from 36 to 38. I did not add any of the serial stuff you did. The results I got using the receive sketch from the repo were:

Adjust = 20
Enter new Adjust value, or [Enter]
Adjust = 20
Waiting for IR transmission...

On    Off     On    Off     On    Off     On    Off

9006, 4499, 559, 547, 551, 555, 553, 552,
556, 1681, 555, 551, 557, 549, 559, 547,
551, 554, 554, 552, 556, 1681, 556, 1681,
555, 552, 556, 1681, 556, 550, 558, 548,
560, 546, 551, 1685, 552, 1686, 550, 1688,
560, 546, 551, 555, 553, 552, 556, 550,
558, 1679, 558, 548, 560, 546, 551, 555,
553, 1683, 554, 1684, 552, 1686, 551, 1686,
551, 556, 552

Adjust = 20
Enter new Adjust value, or [Enter]

Those results are very close to the nominal. It may be that your serial pushbutton stuff is messing up the send. But I don't have time right now to test that. Will try to do that later today.

Do both of your Unos use the Atmega328P? I think even the original ones used that chip, so your results should work the same as my Nanos as far as I know.

Edit: I'm using a TSOP38438 receiver module.

Don't expect to have long range with that emitter, it doesn't have transistor circuit.
So do your testing with same distance between arduino/projector.
Also, be aware that some spaghetti wiring combined with breadboard can lead to inconsistent results. Also strong natural/artificial lightning can disturb signal.

I tried it with your Serial pushbutton stuff, and that made no difference. I still get near-perfect results. I don't know why we get different results.