Sending DIY code through IR

Hi guys,

I have been searching the forum for someone who is sending his own code with the IRremote Library. I have yet to find someone.
Here is my problem with all the other projects:
They want to use a remote to control stuff, i just want to send data over it.
Let me explain: I have a couple of trains which run on a track. I want to know where they are and who they are. My thoughts where to let the train send something like: “TR035” (TR for train and 035 for train nr. 35) via an IR transmitter. The receivers would be placed on the track and send the data to a ‘master’ which then creates a map. But for now I’m trying to get the IR communication to work.

I bought some IR transmitters and receivers and used the IRremote library to test the connection. When use the IRrecord example on 2 arduino’s and hook up the components as described in the comments, I can use my Samsung remote to read a raw signal and then repeat this signal with the push button. This works as it should.
Proof:
Serial data from COM3:
Received unknown code, saving as raw

m4350 s4500 m450 s1750 m500 s1750 m500 s1700 m500 s600 m450 s650 m500 s600 m500 s600 m500 s600 m500 s1700 m500 s1700 m500 s1750 m500 s600 m450 s650 m450 s600 m500 s600 m500 s600 m500 s1750 m450 s1750 m450 s650 m450 s1750 m450 s650 m450 s650 m450 s650 m450 s650 m450 s650 m400 s700 m400 s1800 m450 s650 m450 s1750 m450 s1800 m400 s1800 m450 s1750 m450
Received unknown code, saving as raw
 m4300 s4550 m400 s1800 m450 s1750 m450 s1800 m400 s700 m400 s700 m400 s700 m400 s650 m450 s650 m450 s1800 m400 s1800 m450 s1750 m450 s650 m450 s650 m450 s650 m450 s650 m450 s650 m450 s1750 m450 s1800 m400 s650 m450 s1800 m450 s650 m400 s700 m400 s700 m400 s650 m500 s600 m450 s650 m500 s1750 m400 s700 m400 s1800 m450 s1750 m450 s1800 m400 s1800 m450
Pressed, sending
Sent raw
Released
Pressed, sending
Sent raw
Pressed, sending
Sent raw
Released
Pressed, sending

Serial data from COM4

Received unknown code, saving as raw
 m4250 s4650 m300 s1900 m400 s1750 m350 s1950 m300 s800 m300 s800 m350 s750 m350 s700 m350 s750 m350 s1900 m300 s1900 m350 s1850 m400 s700 m300 s750 m400 s750 m350 s750 m350 s750 m300 s1850 m400 s1850 m350 s700 m400 s1900 m350 s700 m350 s750 m350 s800 m300 s700 m450 s700 m350 s700 m450 s1800 m350 s750 m350 s1850 m400 s1800 m400 s1850 m350 s1850 m400
Received unknown code, saving as raw
 m4200 s4650 m350 s1900 m400 s1800 m400 s1800 m350 s800 m300 s800 m350 s750 m250 s800 m350 s750 m350 s1900 m300 s1900 m350 s1850 m350 s700 m400 s700 m400 s750 m350 s700 m400 s700 m400 s1850 m350 s1850 m350 s750 m350 s1850 m400 s700 m300 s800 m400 s700 m350 s700 m400 s750 m350 s700 m500 s1750 m350 s750 m350 s1850 m350 s1850 m400 s1850 m300 s1900 m350
Received unknown code, saving as raw
 m4200 s4650 m350 s1900 m350 s1850 m350 s1900 m250 s850 m350 s750 m250 s850 m350 s700 m350 s750 m350 s1900 m350 s1850 m300 s1900 m300 s800 m350 s750 m350 s750 m350 s750 m300 s800 m400 s1800 m350 s1900 m350 s700 m350 s1900 m300 s800 m250 s850 m250 s850 m250 s800 m400 s700 m350 s700 m400 s1900 m300 s800 m300 s1850 m350 s1850 m450 s1800 m300 s1900 m400
Received unknown code, saving as raw
 m4200 s4700 m300 s1900 m350 s1850 m350 s1900 m350 s750 m250 s850 m250 s850 m350 s700 m350 s750 m300 s1950 m350 s1850 m350 s1850 m400 s700 m350 s750 m350 s750 m300 s800 m350 s750 m350 s1800 m350 s1900 m350 s700 m400 s1900 m300 s750 m350 s750 m350 s800 m250 s750 m400 s750 m350 s700 m400 s1850 m350 s750 m300 s1900 m400 s1800 m400 s1850 m350 s1850 m300
Received unknown code, saving as raw
 m4150 s4700 m300 s1900 m400 s1800 m350 s1900 m350 s750 m350 s800 m300 s750 m350 s700 m400 s750 m300 s1900 m350 s1900 m350 s1800 m400 s700 m350 s750 m350 s750 m350 s750 m400 s700 m400 s1800 m400 s1850 m350 s700 m400 s1850 m350 s750 m350 s750 m300 s800 m250 s800 m400 s700 m400 s700 m350 s1900 m350 s750 m350 s1850 m300 s1900 m400 s1850 m300 s1900 m300

Then I went on to the IRsendDemo and altered it a bit to send raw codes like in the IRrecord:

 #include <IRremote.h>

IRsend irsend;
unsigned int rawCode[1]={025}; //The code to transmit
int codeLen; // The length of the code

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    codeLen = sizeof(rawCode);
    for (int i = 0; i < 3; i++) {
      Serial.print("Length: ");
      Serial.println(codeLen);
      irsend.sendRaw(rawCode, codeLen, 38);
      Serial.println("Sent");
      delay(40);
    }
  }
}

The receiving end stays blank, the sending end displays:

 Length: 2
Sent
Length: 2
Sent
Length: 2
Sent
Length: 2
Sent
Length: 2
Sent
Length: 2
Sent

Does anyone have an idea of what I’m doing wrong?
Thanks in advance,
Kind regards,
Da_Beast

I used the technique in this Thread to send data to an NGauge wagon to operate an onboard decoupling device. It works very well.

http://forum.arduino.cc/index.php/topic,10555.0.html

…R

Thanks alot Robin! I'll give this a go and test out the reliability of the setup!

one possible issue... codeLen = sizeof(rawCode); should be codeLen = sizeof(rawCode)/sizeof(INT);

another thing you can do is to use standard signals from your remote and map them to commands that make sense in your app. eg you send the signal for button 1 on your remote and in software you take that to mean "TR00352" etc

alternatively, your could just send 0xF00352 using the NEC protocol to signify "TR00352". sendNEC(0x00F00352,32)

= simplest solution & lots of permutations to play with

Robin2: I used the technique in this Thread to send data to an NGauge wagon to operate an onboard decoupling device. It works very well.

http://forum.arduino.cc/index.php/topic,10555.0.html

...R

I tried this and it works great! But the serial connection is at 2400 baud and if you change it, it stops working. The reason for the change is that i want to send the code through a nRF24L01 and that uses 9600 baud. Any sugestions?

AnalysIR: one possible issue... codeLen = sizeof(rawCode); should be codeLen = sizeof(rawCode)/sizeof(INT);

What do you mean with the INT? There needs to be one, but which one?

another thing you can do is to use standard signals from your remote and map them to commands that make sense in your app. eg you send the signal for button 1 on your remote and in software you take that to mean "TR00352" etc

This would work, but then I am limited to 9 trains? That's not enough, so this option is not possible?

alternatively, your could just send 0xF00352 using the NEC protocol to signify "TR00352". sendNEC(0x00F00352,32)

= simplest solution & lots of permutations to play with

I think it’s a great idea! I would have to give each Arduino a number because the number is programmed via software. Is there an easy way to give it a hardware number? I’m thinking about a DIP-switch or something? But then I need a lot of inputs to read the switch.

Thanks again for your input!

codeLen = sizeof(rawCode)/sizeof(int);

sizeof(rawCode)....is the number of bytes allocated for this array. Therefore you need to divide it by 2, because it stores int (s) , which are each 2 bytes long. In the above, codeLen equals the number of elements the array can hold. Inyour code it was double the number.

I think it’s a great idea! I would have to give each Arduino a number because the number is programmed via software. Is there an easy way to give it a hardware number? I’m thinking about a DIP-switch or something? But then I need a lot of inputs to read the switch.

Yes just write a unique id to eeprom and read it back during startup.

Da_Beast: I tried this and it works great! But the serial connection is at 2400 baud and if you change it, it stops working. The reason for the change is that i want to send the code through a nRF24L01 and that uses 9600 baud. Any sugestions?

Sorry, I don't have any suggestions. Just realized that IR is a slow medium limited by the 38kHz carrier frequency.

I don't understand your reference to nRF24 as I thought you wanted to send the signals using IR.

...R

AnalysIR:

codeLen = sizeof(rawCode)/sizeof(int);

sizeof(rawCode)…is the number of bytes allocated for this array.
Therefore you need to divide it by 2, because it stores int (s) , which are each 2 bytes long.
In the above, codeLen equals the number of elements the array can hold. Inyour code it was double the number.

Thanks! I did not know this.

Yes just write a unique id to eeprom and read it back during startup.

This i knew! :slight_smile: But it will still be software programmed?

Robin2:
I don’t understand your reference to nRF24 as I thought you wanted to send the signals using IR.

I want to have a lot of these IR receivers and send them through RF to a master device for display of where the train is.

I want to have a lot of these IR receivers

http://www.hackster.io/rayburne/infrared-dedicated-decoder The project pix shows the decoder to the right of the board and the clock/calendar IC to the left. A mega2560 was used to control the setting for the DS1307.

Have you thought about just converting IR into ASCII over serial. At that time, you can build your own "control protocol"... You can even label an old remote control so that "TV" means Unit_1 and "VCR" means Unit_2, etc. It is a flexible concept and the URC are dirt-cheap.

Ray

mrburnette:

I want to have a lot of these IR receivers

http://www.hackster.io/rayburne/infrared-dedicated-decoder The project pix shows the decoder to the right of the board and the clock/calendar IC to the left. A mega2560 was used to control the setting for the DS1307.

Have you thought about just converting IR into ASCII over serial. At that time, you can build your own "control protocol"... You can even label an old remote control so that "TV" means Unit_1 and "VCR" means Unit_2, etc. It is a flexible concept and the URC are dirt-cheap.

Ray

Hey Ray! Thanks for the input. But i don't want to use a remote, I want the train to say "I'm TR00352" through IR. And with the input of AnalysIR I am testing with the NEC protocol and so far it works great! Now i have to send this through RF to the master and then decode it from F00352 to Train nr: 352.

Da_Beast:
I want to have a lot of these IR receivers and send them through RF to a master device for display of where the train is.

I am doing something like that with 2.4Ghz wireless transceivers (similar to NRF24, but different brand).

I don’t see why the IR baud rate should have anything to do with the speed of the NRF24, but perhaps I don’t understand a key element of your project. If one of the Arduinos “harvests” the data from the IR system it can surely send it as fast as it likes over the wireless connection?

In my 2.4Ghz setup the speed bottleneck is the USB connection between the “master” Arduino and my PC.

…R

Robin2:

Da_Beast: I want to have a lot of these IR receivers and send them through RF to a master device for display of where the train is.

I am doing something like that with 2.4Ghz wireless transceivers (similar to NRF24, but different brand).

I don't see why the IR baud rate should have anything to do with the speed of the NRF24, but perhaps I don't understand a key element of your project. If one of the Arduinos "harvests" the data from the IR system it can surely send it as fast as it likes over the wireless connection?

In my 2.4Ghz setup the speed bottleneck is the USB connection between the "master" Arduino and my PC.

...R

I'm not a pro in arduino.. So i'm not sure what the baud rate is used for? I'm just saying that the sketches use a different baud rate. I don't know if the NRF modules use the baud rate, but the defenition of baud rate is the number of pulses per second. I thought that by this defenition the baud rate used by the arduino is something like this?

Baud rate is the speed at which the serial connection on the Arduino sends data to/from another device using a serial connection. The obvious one is the connection from the Arduino to a PC. But I think, for example, bluetooth connections also use it. With this system every byte takes roughly 10 bits to transmit so, for example, 115200 baud will send about 11,500 bytes per second.

Each different serial connection can work at a different baud rate.

A 2.4GHz wireless system should be able to work at a much faster speed. The devices I have use a Cypress 2.4GHz transceiver (I presume the NRF24 is similar) and a quick glance at the datasheet suggests that they work at a million bits per second.

...R

Robin2: Baud rate is the speed at which the serial connection on the Arduino sends data to/from another device using a serial connection. The obvious one is the connection from the Arduino to a PC. But I think, for example, bluetooth connections also use it. With this system every byte takes roughly 10 bits to transmit so, for example, 115200 baud will send about 11,500 bytes per second.

Each different serial connection can work at a different baud rate.

A 2.4GHz wireless system should be able to work at a much faster speed. The devices I have use a Cypress 2.4GHz transceiver (I presume the NRF24 is similar) and a quick glance at the datasheet suggests that they work at a million bits per second.

...R

Thank you for this information! But the link to the sketches about the ir you proposed is sendin the serial communication at 2400 baud and the sketch of the RF is sending at 115200 baud. If i change the baud of the ir, because the RF needs to be fast, it does not work anymore. With the IRremote library i can change the baud rate as much as i like.

There is no need to use the same baudrate for the IR and for the RF. Just do each at their own best speed.

Or am I misunderstanding what is behind your question?

...R

Robin2: There is no need to use the same baudrate for the IR and for the RF. Just do each at their own best speed.

Or am I misunderstanding what is behind your question?

...R

The RF and the IR will be on the same arduino. Because of this i can only set 1 baud rate. Hence the RF needs a high baud rate, the IR needs to work at the same baud rate. With the sketch you told me about, i can't change the baud rate. The IRremote library does not use the tx and rx pins and so i can chance the baud rate as much as i like.

Ok, thanks to Robin2 & AnalysIR I now have a working IR sender and receiver. Now i want to implement this with the RF. What would be the best way to go? - Make the IR receiver translate the IR code to the right train number. - Send the NEC code through the RF and let the master translate all numbers.

I think the 2nd one is the way to go, but then i want to implement some code to check if the received NEC code is in fact one of the train numbers. Any thoughts?

What would be the best way to go?

2, because it should be easier to maintain over time.

Otherwise the approach with the least work....

Da_Beast:
The RF and the IR will be on the same arduino. Because of this i can only set 1 baud rate.

I seem to have missed this post. I still don’t understand why you are limited to a single baud rate.

My general approach would be to do as little as possible on the Arduino if there is a PC waiting in the background to do the heavy lifting.

What does the NEC code look like and how does it relate to train number? Could you just use the NEC code as the train id for the Arduino’s purposes?

…R

AnalysIR:

2, because it should be easier to maintain over time. Otherwise the approach with the least work....

This would indeed be the easiest solution to maintain. But now I have to write some code to check if the code is correct because sometimes the code is not completely received. I’m not sure on how to do this because sometimes the received code is something like F003 when I’m sending F00352.

Robin2: I seem to have missed this post. I still don't understand why you are limited to a single baud rate. My general approach would be to do as little as possible on the Arduino if there is a PC waiting in the background to do the heavy lifting.

The concept of the IR communication is that the receivers, which are distributed all over the track, send their received data though RF to the master Arduino. Because the IR and the RF have to be on one Adruino (slave), I can only set one baud rate.

What does the NEC code look like and how does it relate to train number? Could you just use the NEC code as the train id for the Arduino's purposes?

I’m not sure on how the NEC code works, but I send the code “0x00F00352” via sendNEC. On the receiving end this comes out as a HEX code: “F00352”. The code that I’m sending is basically the train ID. Now this ID is just software programmed by implementing it in the code for the Arduino. The ultimate goal is to somehow make this ID hardware, but that’s for the future.