Need help understanding IR!

Hello,

Please pardon the n00b question, I do a lot of stuff with Arduino but I've never used IR before!

I'm trying to do something really simple with an IR: send an int with an IR LED from one Arduino and receive the int with an IR receiver connected to another Arduino (it's for an installation with two interacting halves). I've been reading tons of tutorials on this and all the examples I've found use actual remotes with protocols (ie Sony), and I'm not sure how to understand this in the context of just wanting to send a simple int. I've read the datasheet for the ATMega328 to try to understand what's going on but I don't really get it.

I was thinking that I could send, for example, pulses that are multiples of 10 and divide the received signal by 10 to get the int (for example, to send a 7 pulse 70 ms). However since all the examples I can find use hex, I'm not sure how to do this - do I have to send hex values?

Does anyone have any simple explanation for this, or maybe an example that doesn't use a protocol and is for much simpler communication?

Thank-you so much for any guidance! :-*

The thing here is that you need to use a modulated 38kHz signal (probably 38 anyway, if your IR receiver is a common one).

That is, the IR source blinks at 38kHz off-on, and you do that blinking sequence for a certain time which means something at the receiving end. The 38kHz blinking isn’t your message: it’s a means of carrying that message.

Have a look here at adafruit, and particularly this page where she controls her Nikon camera.

The function pulseIR(x) sends a pulse of x microsecs, but that pulse itself is blinking at 38kHz. To the Nikon, a pulse of x followed by a gap of y and another pulse of z, means something. But the x and z pulses are not solid: they’re at 38kHz blinks.

That might help you figure this out?

(This is a case where an oscilloscope is going to prove its value!)

edit: if I have a chance I’ll experiment with this…

Hi, thanks for your reply!

I've been looking at this tutorial: http://www.terryjfield.com/?p=22

It pretty much does the simplest thing possible, which is send a character. This would be ideal and avoid all the demodulation faffing about! To test I loaded it onto my two Arduinos.

The sender is sending a number character, that is the number of characters in the string plus the beginning and end characters (ie, for "Hello" it's sending a 7), but the receiver isn't seeing anything. I've ruled out this being an ambient light issue. I've got the txPin set as the + end of my transmitter LED, and the rxPin set as the pin leg on my receiver (it's one of those three-leg receivers, not another LED.)

Any feedback or ideas is very much appreciated! I'm glad the code is it's generating a reliable character, I just need it to be transmitted now. :)

Hi, sorry, I realise I should have posted the code I’m using.

#include <SoftwareSerial.h>

#define rxPin 5  // receiver is on pin 5
#define txPin 3  // transmitter + is on pin 3

SoftwareSerial displayPort(rxPin, txPin); // Rx, Tx
SoftwareSerial inputPort =  SoftwareSerial(rxPin, txPin, false);

void setup() {
  inputPort.begin(1200);
  displayPort.begin(1200);
  Serial.begin(9600); 
  Serial.println("Begin listening ...");
  delay(2000);
}

void loop() { 
int buttonState = digitalRead(6); // buttonState reads button attached to pin 6; when it's HIGH it's being pressed
  if (buttonState == HIGH) {
    Serial.println("BUTTON PRESSED!"); // print to my serial monitor
    displayPort.println("1"); // send a character to the other arduino
    // print that character (it will print number of chars in the string + start & end chars, in this case 3):
    Serial.println(displayPort.println("1")); 
    delay(2000);  // wait a couple of seconds
  }
  if (inputPort.available()) { // if there's something to read ...
    Serial.print((char)inputPort.read()); // receive it and print in the serial port
  }
}

Thanks again!

When you said "IR receiver" in your opening post, I thought that meant demodulating receiver not a simple phototransistor as in the tutorial you linked to now so then I thought that's what you meant. But you also refer to it as "one of those three-leg receivers" so I'm not sure what your hardware is now.

If it's a 38kHz receiver (like this, for example you'll need to modulate the signal.

Time for a schematic and link to that receiver's datasheet.....

Hi Jimbo,

I did mean a demodulating receiver; sorry, I didn't realise that and the phototransistor in the example I posted were so different (this is my first foray into IR, sorry about my ignorance!)

What I want to do:

  • Have Arduino A and Arduino B, both with an IR LED transmitter and demodulating receiver.
  • Enable one Arduino to send a character to the other Arduino (not simulataneously!)

This seems simple enough but I'm learning it's a lot more complicated. All the examples I'm seeing are about demodulating remote control signals, but I don't need anything that complicated - I just need to send one number at a time.

What I'm thinking I should do is pulse the LED for a number of microseconds and divide that by 100 to get a single integer (for example, 700us / 100 = 7), but I haven't been able to find a good tutorial on how to pulse the LED except by digitalWrite() and microsecond delays. I'm led to believe there's timer issues with this, that digitalWrite() isn't fast enough?

Sorry again if this is confusing, I really appreciate your input!