Interfacing mega2560 with a 24vdc logic device

Hello, I am trying to use an Arduino to detect a signal from an IR Beam sensor, that is operating at a 24VDC logic. Now the IR Beam has Vs=24Vdc, gnd and a separate line having the common, NC, and NO. This means it has an onboard relay but the distances from my Arduino to the IR beam dont permit me to send a signal over one pin to the common of the IR and detect it back using another digital pin thats configured as input. The other operating mode for the IR Beams is the open collector configuration, i did some research and ordered BC547 to use as a switch mode transistor for detecting whenever the IR Beam is triggered. But i can't get the circuit to work. Any ideas on how to connect the arduino to the 24vdc ir beam safely without damaging the arduino. Heres my code and a link to the schematic i tried as well the manual to the IR beams am using. https://www.centsys.co.za/upload/product_link_files/0.07.A.0027.-Photon-infrared-beams-manual-insert-22072013-BM-for-web.pdf


const int IRBeamPin = 2;

void setup() {
  pinMode(IRBeamPin, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  Serial.begin(9600);
}

void loop() {
  int IRBeamState = digitalRead(IRBeamPin);

  if (IRBeamState == LOW) {
    Serial.println("IR beam interrupted");
    digitalWrite(LED_BUILTIN, HIGH);
    // Additional code for actions to be taken when the beam is interrupted
  }
  else {
    Serial.println("IR beam not interrupted");
    digitalWrite(LED_BUILTIN, LOW);
    // Additional code for actions to be taken when the beam is not interrupted
  }

  delay(100); 
}

Why would you need to send a signal out and back again?

Just use these contacts as any other switch to ground - so it just needs an input (with pullup) to read ?

if you use remote interface it is unimportant how big is voltage

upd
зображення

So here NO of the IR goes to what seems like an optocoupler? so the 2k resistor will make it he 24v safe to power the optocoupler?

theres voltage level difference, so i need level shifting. The 24v direct input to the arduino will damage it

I doubt it.

The NO, NC, COM are probably just the terminals of a SPDT switch - not attached to any voltage.
They might be described as "volt-free"

EDIT

"volt-free" aka "potential free":

image

"NC" = "N/C" = Normally Closed;
"NO" = "N/O" = Normally Open;

зображення

THE IR has a transmitter and reciever. The SPDT is present in the reciever IR. so i need a suggestion for the type of optocoupler i can wire in series with a resistor in series to feed the anode of the led in the opto coupler. I need it as a single IC

Yes thanks for poiniting it out. Now an open collector implementation using a transistor, i can be able to read the state change in the IR using an INPUT_PULLUP in the Arduino. I need an example circuit to help implement that.

@Mwasela

You don't need any of that.
Just connect the COM to the Arduino GND and the NO to a digital pin, that's it done

1 Like

Will this work upto 12meters? Am using standard outdoor utp cable for the connection. I think i2r losses wont be a big problem for say 12m yeah?

Yes it's OK but Iwould put a 4.7K ohm pullup resistor next to the arduino, it will help reduce noise pickup.
Connect one end of the resistor to 5V and the other end to the Arduino IRBeampin

1 Like

Yes it's OK but Iwould put a 4.7K ohm pullup resistor next to the arduino, it will help reduce noise pickup.
Connect one end of the resistor to 5V and the other end to the Arduino IRBeampin

Okay, I will implement this tomorrow morning and revert back. Thanks in advance.

Along with the external pullup resistor add a 0.1uF ceramic cap from the input to ground to bypass environmental electrical noise picked up by the long wire (antenna) to ground.

@groundFungus
Bad idea.
How much curent do you think the cap will source through the relay contacts when they close?
10A, 50A, 100A?

Bad idea.
How much curent do you think the cap will source through the relay contacts when they close?
10A, 50A, 100A?

Well the relay contacts are potential free, so I gather no over current will be expirienced if we added a filter cap. Wouldnt you agree?

Think about what happens when the contacts close with a charged capacitor connected across them ...

No. When the relay contacts close the capacitor will discharge a very large current through them, more than they are designed to handle.
Eventually the contacts will become pitted and corroded.
Never put a capacitor directly across relay contacts

1 Like

Notedd, the solution worked, with one IR pair, my ideal one is to daisy chain 3 IR sensors so i can detect a long vehicles appropriately. Would ferrite beads help?

Are you having some kind of problems?