Page 1 of 1

about IR LED and sensors

Posted: Wed Jan 19, 2022 6:33 pm
by lladam
Hi,
I am testing IR LED as a sender pin3, and IR module as receiver pin2, and used codes as below, question are:

1. the receive data seems lot of noise;

2. I checked the send code mostly like this:

Code: Select all

 mySender.send(rawData, RAW_DATA_LEN, 2) 

Code: Select all

 mySender.send(SONY,0xa8bca, 20); 

Code: Select all

  IrSender.sendNEC(0x0102, 0x34, true, 0); 
can I use a code like:

Code: Select all

 mySender.send(xyz); 
to send any thing I like?
xyz = any number or characters.

Thanks for help.
Adam

Sender code:

Code: Select all

#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender

IRsendRaw mySender;
#define RAW_DATA_LEN 2
uint16_t rawData[RAW_DATA_LEN] = { 2406,  1000};

int button = 4;

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

void loop() {

  if (digitalRead(button) == HIGH) {
    for (int i = 0; i < 3; i++)
    {
      mySender.send(rawData, RAW_DATA_LEN, 2); //Pass the buffer,length, optionally frequency
      Serial.println(F("Sent signal."));
    }
  }
}
Receiver code:

Code: Select all

#include <IRLibRecvPCI.h> 

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

void setup() {
  Serial.begin(115200);
  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()) { 

    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
  }
}

Re: about IR LED and sensors

Posted: Wed Jan 19, 2022 6:57 pm
by AnalysIR
I suggest you take a step back and start with the examples provided with the library.

first get the rawRecv example working with a tv remote and only then move on to getting the rawSend example working (using the output from the rawRecv for your remote)

you should be able to control your TV easily with this approach.

Re: about IR LED and sensors

Posted: Wed Jan 19, 2022 7:13 pm
by lladam
AnalysIR wrote: Wed Jan 19, 2022 6:57 pm I suggest you take a step back and start with the examples provided with the library.

first get the rawRecv example working with a tv remote and only then move on to getting the rawSend example working (using the output from the rawRecv for your remote)

you should be able to control your TV easily with this approach.
Thank you AnalysIR.
I did that already, with a receiver module received the TV remoter and used a IR LED send out what it got, works well. with the link:
https://dronebotworkshop.com/using-ir-r ... h-arduino/

Re: about IR LED and sensors

Posted: Wed Jan 19, 2022 7:33 pm
by AnalysIR
The link you provided uses the IRremote library. The code you posted uses the IRLIB2 library.

If you had everything working....then the first issue I see in your original code is:
uint16_t rawData[RAW_DATA_LEN] = { 2406, 1000};
This is not a complete signal and will only send 1 mark pulse of 2406 uSecs. You need to include a full signal that you captured using the recv example.

Re: about IR LED and sensors

Posted: Wed Jan 19, 2022 8:58 pm
by lladam
AnalysIR wrote: Wed Jan 19, 2022 7:33 pm The link you provided uses the IRremote library. The code you posted uses the IRLIB2 library.

If you had everything working....then the first issue I see in your original code is:
uint16_t rawData[RAW_DATA_LEN] = { 2406, 1000};
This is not a complete signal and will only send 1 mark pulse of 2406 uSecs. You need to include a full signal that you captured using the recv example.
Thank you AnalysIR.
Yes. I have both libraries installed.
the uncompleted signal is modified from a complete signal of 42 bytes, the purpose is to test if I can send that? seems not possible?

Re: about IR LED and sensors

Posted: Wed Jan 19, 2022 9:57 pm
by AnalysIR
the purpose is to test if I can send that? seems not possible?
Why not test with a real signal?

Re: about IR LED and sensors

Posted: Thu Jan 20, 2022 12:48 am
by lladam
AnalysIR wrote: Wed Jan 19, 2022 9:57 pm
the purpose is to test if I can send that? seems not possible?
Why not test with a real signal?
actually, that is what my question is, does the real signal just included the three lines as topic? is it possible to send any data to?
Would you please recommend me an one Arduino + IR LED emitter and IR receiver module code?
Thanks

Re: about IR LED and sensors

Posted: Thu Jan 20, 2022 7:47 pm
by AnalysIR
actually, that is what my question is, does the real signal just included the three lines as topic?
Sorry I do not understand what you mean by this.
is it possible to send any data to?
Yes. But it is not really intended for that. IR signals would be relatively slow versus RF.
Would you please recommend me an one Arduino + IR LED emitter and IR receiver module code?
Please refer to the examples provided with the IRLIB2 & IRremote libraries.
You should complete your learning about IR remote control with devices like TVs before moving on to other tasks.

Also check out this good site to find out how IR signals work. https://www.sbprojects.net/knowledge/ir/index.php
(Make sure to look thru the menus for more info about IR protocols etc)