IR trip wire/barrier

I'm attempting to use a TSSP4038 and a TSAL6200 to create an infrared trip wire. The trip wire only needs to be about 16" across. I've tried to pulse the emitter at 38kHz using tone() but I can't seem to get it working correctly. The circuit sort of works if I use continuous power to the emitter, which I can get up to about 7inches, so I'm fairly sure I have everything set up correctly.

I have a 555 timer I could use as well, but I've never used one before and just wanted to test the distance of the trip wire first. According to the data sheets I should be able to get up to 25 meters, so I would think 1 and a half feet should be easy.

Does ambient sunlight/ceiling light make a big difference? Any other tips? I have found pretty limited information online, but any good resource would be very helpful. Thanks.

How are you driving the emitter? A schematic would help. You can have the emitter inside a tube to shield it from some ambient light as well as make it more directional. Same with the detector.

You may find this useful:

I generate a 38Khz 50% duty cycle using the registers.

DDRB = 0
         | (1 << PB1); //Set pin PB1 as output

  OCR1C = 12;    // Counter Max...clock cycles before pin is toggled.

  TCCR1 = 0
          | (1 << COM1A0) //Bits 5 and 4 of TCCR1 (COM1A0 and COM1A1) indicate what to do when comparator == counter
          | (0 << COM1A1)  // When A0 is 1 and A1 is 0, the pin is toggled on a compare.
          | (0 << CS13)
          | (1 << CS12)  // Table 12-5. Timer/Counter1 Prescale Select. Divides the Clock by an amount.
          | (0 << CS11)
          | (0 << CS10);

This is using an ATtiny85 but the principle should apply with any ATMEL chip (check the register names).

Can you see the IR light with your mobile phone camera?

Hopefully this schematic is readable.

I'm using a mega2560 if that means anything.
I can see the light with my camera so it is definitely on. I'm not familiar with what is in the code that you posted or how I would use it, but thanks anyway.

Additionally, here is the simple code that I last tried, but doesn't seem to work.

const int detect = 2;
const int emit = 3;
const int led = 24;

void setup(){
  pinMode(detect, INPUT_PULLUP);
  pinMode(emit, OUTPUT);
  pinMode(led, OUTPUT);
}

void loop(){
  tone(emit,38000);
  digitalWrite(led,digitalRead(detect));
}

Using the IR library:

I would have expected tone() to work and the fact that you're only getting ~7" is very odd; you should be able to get several meters with a TSAL6200 even driving it at ~10ma. Are you sure you're not getting reflections that are causing the beam to not break? That IR LED can easily bounce light off of walls and the IR receiver is very sensitive.

I suppose its because I have the transistor connected, but the code in that post does not illuminate the emitter in my circuit.

I tried using this tape covered straw to create a tube and it didn't work. Maybe I have the detector connected wrong?

That picture is not very useful. We would have preferred the hand-drawn schematic.

What I would suggest is replacing the IR LED with a white or red LED. White or red will work fine with the receiver (shorter distances) and you'll actually be able to get a real idea how bright it is without trying to inspect it through your camera.

For a TSSP4038 you need to do more than simply send a 38 KHz carrier. You have to send it in bursts of 600 microseconds or so. See page 3 of the data sheet for a test signal.

see http://www.vishay.com/docs/82459/tsop48.pdf

6v6gt:
For a TSSP4038 you need to do more than simply send a 38 KHz carrier. You have to send it in bursts of 600 microseconds or so. See page 3 of the data sheet for a test signal.

see http://www.vishay.com/docs/82459/tsop48.pdf

Not true - you show a data sheet for a "tsop48xx" - for a "tssp48xx" part, the third character "s" indicates it is for a sensor use. See this data sheet for the TSSP part http://www.vishay.com/docs/82737/tssp4038ss1xb.pdf (I have been bitten in the past with the difference between ones that expect a modulated carrier and ones that respond to just the carrier which is why I am familiar with it). Look down on the data sheet in the packaging part and it indicates what the third character means: "O" is for receiver, "M" is for repeater/learning applications and "s" is for sensor applications.

This works (tested).
Leo..

const byte IR_LED = 11; // IR transmitter LED with 100ohm (minimum value) CL resistor
const byte IR_Receiver = 8; // from receiver output
const byte onboard_LED = 13; // onboard indicator LED
boolean receiverState;

void setup() {
  pinMode (onboard_LED, OUTPUT);
  pinMode (IR_LED, OUTPUT);
  pinMode (IR_Receiver, INPUT);
  // from Nick Gammon
  TCCR2A = _BV (COM2A0) | _BV(WGM21);
  TCCR2B = _BV (CS20);
  OCR2A =  209; // ~209 = ~38kHz | ~219 = ~36kHz
}

void loop() {
  receiverState = digitalRead (IR_Receiver);
  if (receiverState == HIGH) { // beam interrupted
    digitalWrite(onboard_LED, LOW); // green onboard LED off
    delay(1000);
  }
  else { // beam detected
    digitalWrite(onboard_LED, HIGH); // green LED on
  }
}

gpsmikey:
Not true - you show a data sheet for a "tsop48xx" - for a "tssp48xx" part, the third character "s" indicates it is for a sensor use. See this data sheet for the TSSP part http://www.vishay.com/docs/82737/tssp4038ss1xb.pdf (I have been bitten in the past with the difference between ones that expect a modulated carrier and ones that respond to just the carrier which is why I am familiar with it). Look down on the data sheet in the packaging part and it indicates what the third character means: "O" is for receiver, "M" is for repeater/learning applications and "s" is for sensor applications.

Your right. The datasheet I linked to was not for the same device that the OP quoted.
I have experimented in the past with the Receiver eg TSOP4838, the Light Barrier (Sensor) TSSP58038 and the proximity detector TSSP58P38 for an application (to detect letters in my mailbox!).
The proximity detector TSSP58P38 requires a constant 38 Khz signal to function and gives an output pulse width proportional to the distance of the object.
The Receiver type requires a carrier pulses and the burst length is restricted, the exact number depending on the device.
The Sensor, the one the OP is using appears not to have a restriction on the length of the bursts, so should accept a pure signal of 38KHz. If it is a battery powered application, however, it would be good to use bursts to optimise the battery life.

Could not get this to work, but found this IR Break Beam Sensor with Premium Wire Header Ends - 5mm LEDs : ID 2168 : $5.95 : Adafruit Industries, Unique & fun DIY electronics and kits which works incredibly well.

Does anyone know how this emitter/detector works, or how its different from the other components I had been trying?

cbramo55:
Does anyone know how this emitter/detector works, or how its different from the other components I had been trying?

The only difference between your attempt at using the TSSP4038 and the Adafruit product is that the person that made the Adafruit product knew what he was doing.

The datasheet for the Adafruit solution is too poor to see how the emitter/detector pair function. But based on the emitter requiring a massive 20mA at 5 volts and the range being limited to 50CM indicates that it could be a continuous beam (ie not bursts of 38KHz) . If that is the case, it could be susceptible to interference (ambient lighting etc.).
The TSSP4038 has a range of up to 25M according to the data sheet, if it is correctly driven.

The plan is to have both the sensor and emitter housed so that any ambient light reaching them is reduced.

And Chagrin, I wouldn't have come to the forum looking for help if I knew what I was doing. No need to be so harsh.