Infrared Break beam Sensor

Hello,

I am a beginner in the process of making a break beam sensor.

I bought a couple TSOP 4038 receivers and have a couple LED/LED IRs.

Im looking for a basic schematic and code to test (make sure they work). I tried to search around and try a couple from youtube but have had no luck getting it going.

Hopefully you can help

Thanks

Did your examples modulate the IR with 38kHZ

For a very basic test, you can use the tone library to generate a 38kHz carrier wave to drive the IR led (with series resistor say 220 ohms). Ideally, you should generate bursts of the carrier wave (say 600uS on 600uS off). The output of the TSOP4038 can drive ( actually sink) an indicator led via a 1k series resistor.

EDIT
datasheet TSPO4038: https://www.vishay.com/docs/81926/tsop4038.pdf

THis is what I have tried

#include <IRremote.h>

#define PIN_IR 3
#define PIN_DETECT 2
#define PIN_STATUS 13

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

void loop() {
digitalWrite(PIN_STATUS, !digitalRead(PIN_DETECT));
}

the receiver is picking up signal (from a tv remote), but the IR LED doesnt seem to be transmitting any signal

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

The IR LED is a polarized component, make sure it is the right way around.

The IR LED should be driven by a Logic level MOSFET @ ≈ 100mA.


Did you look at the examples that come with the library ?

No I haven’t. I’m very much a beginner just trying to shortcut my way to this project so learning as I go.

Do I need a resistor on that LED? I am using a 220 ohm currently

I’m a school teacher and just trying to get it going for a demo in my class

Doesn’t work this way :wink:


Vf of the IR LED is ~1.3V

Current in LED = (5v - 1.3V) ÷ 220 = 17mA

Probably too small to send TX signal very far.

Use circuit F2.

R16 = ( 5V - 1.3V ) ÷ 100mA ≈33 Ω (for 100mA of current flow)


If you are making a beam break project, why the TV remote ?

Did you try 38kHz as mentioned ?

Ya tv remote was just testing the TSOP receiver.

I do appreciate your help.

I’ve been trying to following this YouTube video

So i found out that the IR LED is in fact working.

Therefore I am assuming it is not emitting at 38Khz.

Anything you see in the code that would show it not prompting that?

Run this test sketch, make and break the beam with a black piece of cardboard.

What are your results ?

#define TX           3
#define statusLED    13

#define RX           2

//************************************************************************************
void setup()
{
  pinMode(statusLED, OUTPUT);
  pinMode(TX, OUTPUT);

  pinMode(RX, INPUT);

  tone(TX, 38000);

} //END of setup()


//************************************************************************************
void loop()
{
  byte receive = digitalRead(RX);

  digitalWrite(statusLED , receive);

} //END of loop




Then try

#define LEDon            LOW
#define LEDoff           HIGH

#define noSIGNAL         HIGH
#define SIGNAL           LOW

const byte TX          = 3;
const byte statusLED   = 13;

const byte RX          = 2;

byte lastSensorStatus;

//timing stuff
unsigned long checkInputsMillis;
unsigned long detectedMillis;

//************************************************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(statusLED, OUTPUT);
  digitalWrite(statusLED, LEDoff);

  pinMode(TX, OUTPUT);

  pinMode(RX, INPUT);

  tone(TX, 38000);

} //END of setup()


//************************************************************************************
void loop()
{
  //********************************************
  //time to check the inputs (every 20ms) ?
  if (millis() - checkInputsMillis >= 20)
  {
    //restart this TIMER
    checkInputsMillis = millis();

    checkInputs();

  }

  //********************************************
  //other non-blocking code goes here
  //********************************************

} //END of loop


//************************************************************************************
void checkInputs()
{
  byte inputStatus;

  //********************************************
  inputStatus = digitalRead(RX);

  //was there a change in sensor status ?
  if (lastSensorStatus != inputStatus)
  {
    //update to the new state
    lastSensorStatus = inputStatus;

    //**********************
    //has the signal disappeared ?
    if (inputStatus == noSIGNAL)
    {
      digitalWrite(statusLED, LEDon);

      //the time the object went into the IR beam
      detectedMillis = millis();
    }

    //**********************
    //the signal has returned
    else
    {
      digitalWrite(statusLED, LEDoff);

      Serial.print("Object was in beam for ");
      Serial.print(millis() - detectedMillis);
      Serial.println(" milliseconds.");
    }

  }

} //END of   checkInputs()

//************************************************************************************

How could I ever thank you!

Both are working
So many questions for you lmao!

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