fast switching

hi, i have an arduino recieving a signal from a 24v sensor through a mechanical relay, im thinking that the relay wont be fast enough.

the sensor is a reflective led that counts objects passing front of it.

So, should i use a transistor? i've also looked at optoisolators, what should be best?

Thanks

I'd use transistor. Have the 24V drive the base of a NPN transitor, pull an input with internal pullup resistor enabled.

Or, use a voltage divider and drive a pin directly.

24V
|

< R1

|
|--- Vout
|

< R2

|
Gnd

Vout = Vin * R2/(R1 + R2)
5V = 24V*5000/(R1 + 5000)
R1 = 19000
Use 20K, max out is 4.8V.

If the 24V supply to the sensor has a common ground with the Arduino, then I'd use a voltage divider as Crossroads suggested. If is doesn't have a common ground or you are not sure, then use an opto isolator. Connect the input side of the opto isolator to the sensor output via a series resistor of about 2.2K, observing the correct polarity of the opto isolator. Connect the emitter pin of the opto isolator output to Ardiono ground, connect the collector pin to an Arduino input pin, and enable the internal pullup resistor on that Arduino pin.

the 24v comes from a lm317 and the 5v from an ftdi chip, i do have the grounds together. will the voltage divider work?

sensor4.sch (844 KB)

pato_llaguno:
the 24v comes from a lm317 and the 5v from an ftdi chip, i do have the grounds together. will the voltage divider work?

Yes.

comercial values come in 4.7k and 18k that gives me 4.96 am i right?

Personally I'd go a bit higher, e.g. 10K and 39K, so that the current into the pin protection diode will be lower if the input goes above 24V.