Infrared - Send signal and receive from another Arduino

Hi,

I send an infrared signal from an Arduino and would like to receive this signal with another Arduino.

I use an infrared LED as a transmitter --> Datasheet

And the TSOP38238 as receiver-> Datasheet

Sending works but how can I receive the signal?
Do I need a library or can I do this with digitalWrite (for send) and digitalRead (for receive)?

Thanks in advance

How do you know the transmission works, if you haven't received it to see what it is?

To use a receiver like that TSOP you need to create a carrier signal flashing at 38kHz and then, modulate that signal with the message you want to send.

That message could simply just be an on and an off, or a number of flashes, in which case you could read that with just a digitalRead.

You may find this useful.

You could use the VirtualWire library for one way transmission or SoftSerial for two way with an RX/TX pair at each end. One problem you'll see is ambient IR background from other sources. Device aiming and shielding will solve that to some degree.

Arctic_Eddie:
One problem you'll see is ambient IR background from other sources.

Using a 38kHz TSOP, where a 38k carrier is modulated by the actual message, reputedly takes a lot of that problem away. I guess it's unlikely that stray IR will be a modulated 38kHz signal.

Good idea Jimbo.

There are examples for these devices used as TV remote controls.

Arctic_Eddie:
Good idea Jimbo.

It's what the OP actually said he has already.

I explain how to modulate the signal in different ways, in the link in my first post.

Thank you for your answers.

JimboZA:
How do you know the transmission works, if you haven't received it to see what it is?

I'm looking through a camera, which can see IR light. You have described this trick also in your PDF.

Can you help me with the code from the receiver?

This is the code from the sender. I think the code works because I can see the light with a camera.

const int LED_PIN = 3;

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  delay(1000);
}

This is the code for the receiver (from your PDF file). The code generates only 1 in the serial output.

int phDiodePin =2;

void setup(){
  Serial.begin(9600);
  Serial.println("starting....");
}

void loop(){
  Serial.println(digitalRead(phDiodePin));
 // delay(5000);
}

Thank you for your help

If you are using that TSOP receiver, you need to send it a modulated signal. That is, a 38kHz carrier, modulated by the "message" you want to send.

The TSOP is an active low device, it will output a high, the 1 you are getting, under all circumstances except when it's getting a 38kHz carrier at which point it will go low.

So the TSOP is working correctly right now: if you power the TSOP and send it a solid IR or no IR, it will still give a high. Your 1000ms blink from your transmitter, although it's working in the sense you can see the IR through your camear, is not working as far as the TSOP receiver is concerned. It needs a 38kHz carrier, not a "solid on".

So look further into my write-up and you'll see a few ways to do that. Easiest is to use tone()and if I recall there's an example of that code in there. In the presence of a 38kHz stream from that tone() code, the TSOP should go low.

Thank you very much Jimbo. Now it's working.

Sender Code:

const int LED_PIN = 3;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  tone(LED_PIN, 38000);
}

void loop() {

}

Notes:
Now it's working.

Excellent... glad to help

So how do you send a message over to the ir led. I like to send a command of "/?!" Over a 38kHz modulated ir led.
So while modulating sending some command.
Can you help me with that part?