IR Breakbeam vs1838b

Hello everyone,

i have a problem with vs1838b sensor used as breakbeam.
Basically, instead of detecting the broken beam, it detects when it is opened but for a fraction of a second. I wanted to ask you how to solve without changing the receiver. This is a video of the operation: Video

These are the two variants of code with the same problem:

#include <IRremote.h>

#define PIN_IR 3
#define PIN_DETECT 6 //vs1838b sense pin
#define PIN_STATUS 13 //led interno arduino

IRsend irsend;
void setup ()
{
  Serial.begin(9600);

  pinMode (PIN_DETECT, INPUT);
  pinMode (PIN_STATUS, OUTPUT);
  irsend.enableIROut (38);
  irsend.mark (0);
}

void loop () {
  digitalWrite (PIN_STATUS, !digitalRead (PIN_DETECT));
  Serial.println((int)!digitalRead(PIN_DETECT));
}
#include <IRremote.h>
#define PULSE_TIME 1000
#define PIN_STATUS 13 //led interno arduino


int RECV_PIN = 6; //vs1838b sense pin
IRsend irsend;
unsigned long time;
boolean send = true;

void setup()
{
 Serial.begin(9600);
 pinMode(RECV_PIN, INPUT);
 pinMode (PIN_STATUS, OUTPUT);
 irsend.enableIROut(38);
 time = 0;
}

void loop()
{
 if(millis() - time >= (PULSE_TIME/1000))
 {
   if(send)
   {
     irsend.mark(PULSE_TIME);
   }
   else
   {
     irsend.space(PULSE_TIME);
   }
   
   time = millis();
   send = !send;
 }
 
 Serial.println((int)digitalRead(RECV_PIN));
 digitalWrite (PIN_STATUS, !digitalRead (RECV_PIN));
}

Thanks a lot to anyone who can help me

Hi lorenzing,

Having a similar problem with another such IR receiver, my guess is that you do not switch your LED between "1" and "0" in proper intervals. Those receivers have internal Automatic Gain Control circuits that might spoil your job if the duration of continuous "1" or "0" is very long.
An oscilloscope or a logic analyzer should help you a lot on this, to see if your code switches between "mark" and "space" your LED as you intent to do....
Try a simpler code on this like (sorry the following is not tested):

void loop()
{
	irsend.space(1);
	irsend.mark(1);
	Serial.println((int)digitalRead(RECV_PIN));
	digitalWrite (PIN_STATUS, !digitalRead (RECV_PIN));
}

try also first "mark" then "space"

Keep on trying ! :slight_smile:
Jim

Practical Electronics and Arduino in 8 Hours

SNAG-2021-01-13-21-16-42.png

SNAG-2021-01-13-21-16-42.png

The video shows less than 10cm distance between LED and 3-pin sensor.
How much current are you pushing through the LED (I don't see any current limiting resistor).
Those sensors are very sensitive, and also pick up reflected light.

Beam break for what.
Can't use interrupted IR if you're making a fast sports timer.
But ok for things like people counter.
Leo..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.