Build IR-light barriers

Basically I want to build a bunch of IR-light barriers. I use IR-LED and receivers PWMing at 38KHz.

Thing is, how do I create a constant "background signal" to detect objects in the way? ATM I use IRremote's "enableIROut()" for a PWM signal, however, pulseIn() detects more or less arbitrary pulse widths.

I tried to use my TV's remote (constantly pressing a button) and it worked great. How can I emulate that?

Download (and install this library).

Once installed close and reopen your IDE.

Goto File.. Examples.. IRremote.. IRsendDemo

Edit: Oops, forgot the link

Yeah, I knew that ( I use that library for reading the IR-receiver). My problem is, I need to send constantly something in the background.

My idea is, that the LED send some dummy signal and the receiver detects it, if there is some object in the way, the receiver won't detect anything and I know, there's something in the barrier. However, I can only either send OR receive, not both (at least with one Arduino).

Do you really need to use the IR library? You could use a Arduino timer to generate a 38KHz signal on an output pin or maybe just a simple 555 circuit like this and have the Arduino detect/check the receiver side.

Riva: Do you really need to use the IR library? You could use a Arduino timer to generate a 38KHz signal on an output pin or maybe just a simple 555 circuit like this and have the Arduino detect/check the receiver side.

This would be a better solution.

The IR-lib internally uses the timers, so there's not too much difference. But I would like (if possible) to avoid buying/building more circuitry.

Also, I do have a 38KHz signal, at least I can see it with my camera, but the receiver only receives a signal (according to pulseIn() ) when I wiggle the parts a bit - I basically measure the jitter which doesn't seem right.

You need to use a special IR receiver for this. Most IR receivers are designed to turn off (reject) signals that are on all the time.

Check out TSSP4038 (light barrier) from Vishay.

One possible way of overcoming the AGC feature with some standard IR receivers is to pulse the modulation on/off every 600uSecs - you may be lucky. You can also try to increase the pulse time if neccessary.

Using enableIROut @ 38kHz is a good way of doing this and when working you should get a LOW signal at your receiver. (IR receivers operate in an inverted mode, when receiving the output is LOW). Of course generating the PWW directly instead of using the library, will save some resources, if neccessary.

As an aside, we will be launching a range of IR related modules in the next while & coincidently one of them is a pair that operates like this, but generates its own PWM signal, freeing up resources on the Arduino or MCU. Can also operate standalone, without a Microcontroller.

Ok, but why is my remote's signal (which is constant) received? I think it's on the sending side. I tried different codes from here, but non of them really worked.

One sketch seems rather fitting, according to the author, it should create a PWM signal modulated with 500Hz:

// Example of modulating a 38 KHz carrier frequency at 500 Hz with a variable duty cycle
// Author: Nick Gammon
// Date: 24 September 2012


const byte POTENTIOMETER = A0;
const byte LED = 9;  // Timer 1 "A" output: OC1A

// 16 MHz clock divided by 500 Hz frequency desired (allowing for prescaler of 128)
const long timer2_OCR2A_Setting = 16000000L / 500L / 128L;

ISR (PCINT2_vect)
   {
    
   // if pin 3 now high, turn on toggling of OC1A on compare
   if (PIND & _BV (3))
     {
     TCCR1A |= _BV (COM1A0) ;  // Toggle OC1A on Compare Match
     }
   else
     {
     TCCR1A &= ~_BV (COM1A0) ;  // DO NOT Toggle OC1A on Compare Match
     digitalWrite (LED, LOW);  // ensure off
     }  // end of if
     
   }  // end of PCINT2_vect


void setup() {
  pinMode (LED, OUTPUT);
  pinMode (3, OUTPUT);  // OC2B
  
  // set up Timer 1 - gives us 38.095 KHz
  TCCR1A = 0; 
  TCCR1B = _BV(WGM12) | _BV (CS10);   // CTC, No prescaler
  OCR1A =  (16000000L / 38000L / 2) - 1;  // zero relative
  
  // Timer 2 - gives us our 1 mS counting interval
  // 16 MHz clock (62.5 nS per tick) - prescaled by 128
  //  counter increments every 8 uS. 
  // So we count 250 of them, giving exactly 2000 uS (2 mS period = 500 Hz frequency)
  TCCR2A = _BV (WGM20) | _BV (WGM21) | _BV (COM2B1);   // Fast PWM mode
  TCCR2B = _BV (WGM22) | _BV (CS20) | _BV (CS22) ;  // prescaler of 128
  OCR2A  = timer2_OCR2A_Setting - 1;                // count up to 250  (zero relative!!!!)
  
  // pin change interrupt
  PCMSK2 |= _BV (PCINT19);  // want pin 3
  PCIFR  |= _BV (PCIF2);    // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);    // enable pin change interrupts for D0 to D7
  
}  // end of setup

void loop()
  {
  // alter Timer 2 duty cycle in accordance with pot reading
  OCR2B = (((long) (analogRead (POTENTIOMETER) + 1) * timer2_OCR2A_Setting) / 1024L) - 1;

  // other stuff here
  }  // end of loop

I replaced the analogRead with a constant, but I'm not receiving anything.

BTW: I'm a bit confused about the pins, I connected the LED to pin 9 and GND, pin 3 is not connected.

Ok, but why is my remote's signal (which is constant) received? I think it's on the sending side.

Its not really constant - lots of marks/spaces/gaps etc (i.e on/off sequences). So not surprising that works.

What "constant" did you use in the posted code?

You could also check out: http://www.righto.com/2010/03/detecting-ir-beam-break-with-arduino-ir.html

Different values from 0 to 1023.

OK

I suggest you go back to enableIROut and try toggling on an off at at longer values until you get it to work.
Varying the distance should also provide different results.

As per my earlier post, the correct reveiver to use for this is the TSSP4038.

With standard IR receivers it more a case of time spent vs <$1 for the right sensor.

I can't toggle it on and off AND read simultaneously. That's the problem. I managed to get a relatively good signal with tone(PIN,38000), but it seems extremely unreliable.

And buying new receivers is not really an option right now.

I can't toggle it on and off AND read simultaneously. That's the problem. I managed to get a relatively good signal with tone(PIN,38000), but it seems extremely unreliable.

You should be able to toggle on/off from the main loop and use attachinterrupt(0,xxxx); on pin 2 to read the input signal from the IR receiver.

Most IR receivers are specifically designed to reject ongoing signals.

And buying new receivers is not really an option right now.

Right tool for the job = TSSP4038 @ US$0.72 on Mouser

Best of luck with your efforts.

I just looked up my receivers datasheet and according to that, my receivers are made for an "opictal switch", (source).

However, I ran into some new problems: the receivers almost nevers sends a "0"- signal, even when there's no IR-light source anywhere I only read (digitalRead(PIN)) ones. Only while breaking the barrier I can see some random zeros (and I mean really just entering and leaving the beam, not staying in there). I tried the simplest sketch and circuits possibles, still the same.

Sounds like this ‘OS-1838B’ is operating as expected/designed for a standard IR receiver - from your description.

It also looks like the IR receiver in the link below from our recent blog, although if it really is from OSRAM, I would expect not .
(Maybe the one in the link is poor copy?)

Infrared receiver showdown – TSOP34438 vs VS1838B winner revealed

Optical Switch: probably means that if you send a signal you can use the output pulse to switch something.
The data sheet also says that it is for RC5 which is @36 kHZ modulation. (Although it would work to some extent,this doesn’t inspire confidence). Strange that it doesn’t also say RC6 which is at 36kHz and a close cousin of RC5.

Note the clever use of english in the DS:
Applications:

  1. Optical switch
  2. Light detecting protion of remote contol

On second thoughts,It may actually be the same unit as in the link above ???

Sorry for the long time, but I had more important stuff to do lately.

However, I still can’t make it work here.

I just checked if the Arduino is actually generating a PWM signal, if I connect the LED-out pin to the receiver input pin it reliably detects pulses, so that works.
But the receiver itself still doesn’t recognize anything (and I mean, nothing, pulseIn() yields just zeros).
I’m totally baffled right now. It generates a signal and can read it, the LED flashes (or is on at least), the receiver seems to work with a regular remote control.

As AnalysIR mentioned earlier, typical IR receivers are designed to reject continuous signals. Your datasheet doesn't state that explicitly but it does state that it's designed for PCM or RC5 codes, and those codes do follow a standard where there are appropriate pauses between transmission of data.

Take a look at the Vishay datasheet for the TSOP4838, which is designed for RC5 encoding, and read page 5.

But shouldn't I receive at least something? It doesn't even make a difference if I plug the LED in or not.

By the way: I'm now using a 38KHz carrier signal that modulates a 500Hz signal, if that makes a difference.

38,000 divided by 1000 (500Hz) would give you bursts of 38 on and 38 off. Yeah, I would expect something, but the datasheet for your part doesn't state what its limitations are.

Make sure your IR led is illuminating correctly -- most cell phone cameras, etc. can see the IR light. When prototyping I suggest using a visible white or red LED (at ~10cm distance) just so you can see what's happening.

Did exactly that. As far as I can tell, the LED side works fine.