Help with IRremote library | sending:

Hello. Firstly I apologise I am extremely new to arduino IDE. I am not sure if this is the right place to post my support request hopefully its okay. My intention: I wish to send just a single command over my IR diode, the sample code I find that comes with the library seems to just send on repeat which I am not sure how to stop firstly, I have managed to stop the sample code from interating by commenting that code out. I have the remote codes using the IRremote library for receiving okay. My issue: I am not entirely sure where to put my send code, I have tried various places. Code: Due to limitations of thread character limit I've had to upload to github - https://raw.githubusercontent.com/HybridZach/HybridZach/refs/heads/main/SimpleSender_IR_C6.ino The readme on the github which links to documentation here - https://dronebotworkshop.com/ir-remotes/#SimpleSender_Example_Code With regards to where to change the command I am a bit lost. The receiver gave me this for example for a UP button
Send with: IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
Send with: IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
So I assumed you change that line but it didn't work. I see the IR working (looking at it via a camera) so I've defined the pin correctly with the compile options, I'm just stuck on where to place the send code. Thanks.
DroneBot Workshop
DroneBot Workshop
IR Remotes Revisited - 2023 | DroneBot Workshop
Learn to interface infrared remote controls with microcontrollers like Arduino and ESP32. Includes those tricky remotes as well!
71 Replies
AnonEngineering
AnonEngineering2mo ago
there are many, many IR protocols in the world, you must use the one your receiving device expects. you "see" the IR with your cell phone, so likely the code being sent isn't what your receiver expects
HybridZach
HybridZachOP2mo ago
No I know its NEC protocol I have the code from using the receiving demo code. I now want to apply that to the send demo code but I don't know where to replace it. The receiving demo says this:
23:01:29.513 -> EA15E710
23:01:29.513 -> Protocol=NEC Address=0xE710 Command=0x15 Raw-Data=0xEA15E710 32 bits LSB first Gap=3276750us Duration=67450us
23:01:29.513 -> Send with: IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
23:01:29.513 -> EA15E710
23:01:29.513 -> Protocol=NEC Address=0xE710 Command=0x15 Raw-Data=0xEA15E710 32 bits LSB first Gap=3276750us Duration=67450us
23:01:29.513 -> Send with: IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
So where do I place the send with code in the send demo code? What I meant by I see it in my phone camera is I must have the correct pin defined for the send pin as I see its sending IR signals fine I just need to send the right command
AnonEngineering
AnonEngineering2mo ago
currently you are sending
c++
IrSender.sendNEC(0x00, sCommand, sRepeats);
c++
IrSender.sendNEC(0x00, sCommand, sRepeats);
once a second and you defined those variables up top
c++
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;
c++
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;
0x00 is the address, which doesn't match NEC Address=0xE710
HybridZach
HybridZachOP2mo ago
Yeah so I replaced that with
IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
IrSender.sendNEC(0xE710, 0x15, <numberOfRepeats>);
And the github says if unsure what number of repeats set to 3 as a start My problem is the console shows that its not sending the correct command (I think?) My output:
01:46:24.861 -> Send now: address=0x00, command=0x34, repeats=0
01:46:24.861 -> Send standard NEC with 8 bit address
01:46:24.861 -> Send now: address=0x00, command=0x34, repeats=0
01:46:24.861 -> Send standard NEC with 8 bit address
Am I replacing line 72 in my code linked above? Sorry I send that before reading your other reply So to change the command I change these?
AnonEngineering
AnonEngineering2mo ago
try
c++
IrSender.sendNEC(0xE710, 0x15, 3);
c++
IrSender.sendNEC(0xE710, 0x15, 3);
that is "hard coded", not using the variables
HybridZach
HybridZachOP2mo ago
Oh I see Also how do I only send it once?
AnonEngineering
AnonEngineering2mo ago
most IR codes want a repeat for reliability
HybridZach
HybridZachOP2mo ago
Its just while I test the output so I don't spam the console every second
AnonEngineering
AnonEngineering2mo ago
that's two different things, how many times the code is repeated, and how often you send results to the serial monitor
HybridZach
HybridZachOP2mo ago
This is what I tried before I asked for help and my output says its sending the wrong command?
AnonEngineering
AnonEngineering2mo ago
🤷‍♂️ wrong command for what?
HybridZach
HybridZachOP2mo ago
Sorry for noobie let me try start again I changed line 72 to what you put here
AnonEngineering
AnonEngineering2mo ago
the github isn't showing line numbers, you could try pastebin.com
HybridZach
HybridZachOP2mo ago
When I run the code the console says this
01:46:24.861 -> Send now: address=0x00, command=0x34, repeats=0
01:46:24.861 -> Send standard NEC with 8 bit address
01:46:24.861 -> Send now: address=0x00, command=0x34, repeats=0
01:46:24.861 -> Send standard NEC with 8 bit address
Sorry replying using my phone
AnonEngineering
AnonEngineering2mo ago
if you use variable name those values would be used
c++
IrSender.sendNEC(address, command, repeats);
c++
IrSender.sendNEC(address, command, repeats);
(whatever names are defined)
HybridZach
HybridZachOP2mo ago
Lemme give you the correct link one sec
AnonEngineering
AnonEngineering2mo ago
ok, brb
HybridZach
HybridZachOP2mo ago
GitHub
HybridZach/SimpleSender_IR_C6.ino at main · HybridZach/HybridZach
Config files for my GitHub profile. Contribute to HybridZach/HybridZach development by creating an account on GitHub.
HybridZach
HybridZachOP2mo ago
I suck at CPP only good with python. Struggling to find where I change the sample code to run the command here
AnonEngineering
AnonEngineering2mo ago
so as written it executes
c++
IrSender.sendNEC(0x00, 0x34, 0);
c++
IrSender.sendNEC(0x00, 0x34, 0);
c++
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;
c++
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;
yes, line 72 so you could hardcode address, command, repeats there
HybridZach
HybridZachOP2mo ago
Sorry for the confusion that code I linked I replaced line 72 with
IrSender.sendNEC(0xE710, 0x15, 3);
IrSender.sendNEC(0xE710, 0x15, 3);
HybridZach
HybridZachOP2mo ago
Sorry I know I'm trying to explain that what I linked you I changed that line with the above
AnonEngineering
AnonEngineering2mo ago
ok, and what is complaining about that editied line?
HybridZach
HybridZachOP2mo ago
So I change line 72 what about line 54 & 55
AnonEngineering
AnonEngineering2mo ago
those lines set up the variables
HybridZach
HybridZachOP2mo ago
The console output it saying (I think) that the wrong command is being sent Address 0x00 command 0x34
AnonEngineering
AnonEngineering2mo ago
what console? an ino script, a python script? how would the console know it's the wrong command?
HybridZach
HybridZachOP2mo ago
The serial monitor in the ide The code in the loop is meant to display the command it sent
AnonEngineering
AnonEngineering2mo ago
i don't see any receive code or any lines that would send an error message
HybridZach
HybridZachOP2mo ago
I suck at explaining 😅
AnonEngineering
AnonEngineering2mo ago
all i can go by is the link you sent 😉
HybridZach
HybridZachOP2mo ago
So in the loop it says in a comment Print current send values
AnonEngineering
AnonEngineering2mo ago
// comments are not compiled let alone executed
HybridZach
HybridZachOP2mo ago
No lmao that's not what I meant Ermm
AnonEngineering
AnonEngineering2mo ago
this block?
c++
/*
* Print current send values
*/
Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();
c++
/*
* Print current send values
*/
Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();
HybridZach
HybridZachOP2mo ago
Yeah
AnonEngineering
AnonEngineering2mo ago
it's hardcoded, it'll always print that
HybridZach
HybridZachOP2mo ago
I think I'm being dumb I thought it had variables to display but the first line is hard coded text Ditto
AnonEngineering
AnonEngineering2mo ago
yes you could use variables...
HybridZach
HybridZachOP2mo ago
How do I get it to display that its sent the correct code Are variables in a text string defined with $? I just want the console to show what command was sent
AnonEngineering
AnonEngineering2mo ago
looking again
c++
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCommand, HEX);
c++
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCommand, HEX);
will print sCommand (in hexadecimal) in C++ you should avoid "text strings", they are char arrays, an array of characters
HybridZach
HybridZachOP2mo ago
Okay lemme test some things and get back to you to see if I get the desired outcome. Thanks for helping such a noob lol
AnonEngineering
AnonEngineering2mo ago
though in this case they are 16 bit unsigned integers (uint16_t) C++ is very picky about data types 🙂 oh. potentially a problem, they are created as 8 bit integers... (uint8_t) 0xE710 is 16 bits the original repository and examples are here https://github.com/Arduino-IRremote/Arduino-IRremote
HybridZach
HybridZachOP2mo ago
Yah I struggled to understand the examples/readme So on line 54 it is setting up sCommand as the correct data type? The example is 0x34 are you saying I need it to be 16? Also running the code and holding the ir near what I want affected it doesn't work sadly
AnonEngineering
AnonEngineering2mo ago
0x34 is only 8 bits, which might be ok for address, but data is 16 bits iirc
HybridZach
HybridZachOP2mo ago
So what do I need to change that to
AnonEngineering
AnonEngineering2mo ago
uint16_t is an unsigned 16 bit integer, uint8_t is an unsigned 8 bit integer each character in a hex value is 4 bits (a nybble), 2 nybbles is a byte 16 bit is 2 bytes 0xE710 is 4 nybbles, 2 bytes, 16 bits
HybridZach
HybridZachOP2mo ago
So I need to change uinit8_t to 16? Would you be able to edit my ino to send the command the receiver gave me so I can use that as an example to try understand it better perhaps?
AnonEngineering
AnonEngineering2mo ago
do you have a device to control? I'd need to study the NEC (or whatever protocol) to know what you should be sending
HybridZach
HybridZachOP2mo ago
Yeah my AC It came with a remote and I sent the codes with the receive demo file which worked fine I just can't figure out how to send what it gave me lol I thought ir send and receiving would be simple 😅😭
HybridZach
HybridZachOP2mo ago
This is a file I made with the various buttons I sent to the ir receiver with the IRremote ReceiveDemo
AnonEngineering
AnonEngineering2mo ago
ac's use a different protocol, not NEC https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino as an example Raw-Data=0xEA15E710 32 bits LSB first
HybridZach
HybridZachOP2mo ago
Well the receive demo said it should spit out and decode what protocol it uses Which gave me NEC
AnonEngineering
AnonEngineering2mo ago
and it reports a 32 bit protocol there is no "standard" way to send and receive IR
HybridZach
HybridZachOP2mo ago
It says protocol=NEC
AnonEngineering
AnonEngineering2mo ago
i'd read through https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file there may be better tools to read your ACs remote
HybridZach
HybridZachOP2mo ago
Haven't I already read the commands though I just need to send now?
AnonEngineering
AnonEngineering2mo ago
the tool you're using may not truly understand what it's seeing so it makes its best guess might be simpler to start with a TV, they use more "standard" protocols
HybridZach
HybridZachOP2mo ago
My whole goal is to control the AC though haha. I bought a IR send and receiver with an esp dev platform eventually I want to hook that up to home assistant to control my ac. I'm just using audino to decode the commands first because I thought I'd be simple. I guess I was mistaken lol Can you help me try test the commands I got though?
AnonEngineering
AnonEngineering2mo ago
"We love standards, that's why we have so many of them" 😉 https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-to-deal-with-protocols-not-supported-by-irremote your goal is fine, but when setting out to design a Boeing 747, it's best to start with a Cessna 172, in other words, try to control a more standard thing first
HybridZach
HybridZachOP2mo ago
I used this https://dronebotworkshop.com/ir-remotes/#SimpleReceiver_Example_Code to decode the commands and it spit out that it uses NEC
DroneBot Workshop
DroneBot Workshop
IR Remotes Revisited - 2023 | DroneBot Workshop
Learn to interface infrared remote controls with microcontrollers like Arduino and ESP32. Includes those tricky remotes as well!
HybridZach
HybridZachOP2mo ago
This links to that Why is it so complicated lmao oof
AnonEngineering
AnonEngineering2mo ago
yes but ACs don't use NEC. think of protocols as languages, if i try to decode French but I only know German, the results may not be good
HybridZach
HybridZachOP2mo ago
But the irremote readme says If you have a device at hand which can generate the IR codes you want to work with (aka IR remote), it is recommended to receive the codes with the ReceiveDemo example, which will tell you on the serial output how to send them.
AnonEngineering
AnonEngineering2mo ago
this concentrates on TV remotes https://dronebotworkshop.com/ir-remotes/
HybridZach
HybridZachOP2mo ago
Doesn't that tell me what its using so are you saying its guessing its nec
AnonEngineering
AnonEngineering2mo ago
it is listening for a more standard protocol, it hears Swahili so it takes its best guess i'd google up "Decode AC remote", I myself have never used IRremote with an AC
HybridZach
HybridZachOP2mo ago
The ac isn't a big named brand I'd doubt it to use something special
AnonEngineering
AnonEngineering2mo ago
LOL that makes it more likely it has a custom protocol there are examples in the links above for LG air conditioners https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/SendLGAirConditionerDemo
HybridZach
HybridZachOP2mo ago
Hmm this is way over my head then it seems Thanks for the help anyways

Did you find this page helpful?