Optocoupler or mosfet

I'm going to send a signal from a 24v machine, to my Pico. Obviously that voltage would destroy my MCU immediately so I need to run it through an optocoupler or a mosfet before going to the gpio. I'm unsure which to use.

I will be powering my Pico from the 24v machine through an L7805 voltage regulator. Since they will have a common ground, I'm not sure if an optocoupler would give me the electrical isolation protection I would need. A mosfet seems like it would work but would require 2 resistors for a voltage divider and they seem to be a bit more expensive.


A simple NPN BJT transistor inverter circuit would be sufficient.

image

The Opto coupler shows no current limiting resistor in the input LED, so when you put 24V on that your LED burns out instantly.

Also as you have connected both sides of the opto coupler to the same ground, you have no isolation anyway.

The opto will isolate the +24V when the resistor is added. I have done this many of times but that was before built in pull up resistors in processors. The 24V ground will be connected via the 5V ground, they are the same.

.. the electrical isolation protection I would need Why would you need that?

A mosfet seems like it would work but would require 2 resistors for a voltage divider and they seem to be a bit more expensive.

Depends where you live. £1.27 doesnt seem excessive.

Hi,
Have you checked how much current the Pico will need and anything else on the 5V supply?

Linear regulating from 24V to 5V is not efficient and you need to calculate the power dissipated in the 7805, and work out if it needs a heatsink.
A DC-DC converter may be better, more efficient and cooler to run.

Tom... :smiley: :+1: :coffee: :australia:
PS. Good that you have read the specs and put bypass caps on the 7805. :+1:

I'll look into the NPN BJT, thank you.

I don't NEED electrical isolation, I just want to protect the weak feeble gpio pins from the relentless 24v. I'm looking for the best way to do it.

The 5v power supply is only running the pico and some gpio pins, no real current. the 7805 wont need a heat sink.

If you don't need isolation why not just have a potential divider straight to the Pico input? I look after a clock that has a 24v contact driving an electromagnet. There's a snubber across the contact 1k parallel with 220nF; then a 1k shunt, 8k2 series, 1k2 shunt and a 1N4148 to protect against negative spikes (observe polarity of diode). This drives a 3v3 input on a Due, has been doing so for years with no issue.

+1

100K and 10K would give you 2.18V at the GPIO, which might be high enough to register as high. If not, 100K and 15K would work.

If your 24V signal was actually at ground when not asserted, you could enable the internal pullup resistor on the I/O, and use a single diode for the connection.

For spikes, add a 100nF across the 10k/15k.

Yeah, I guess. Although - it's 100K, and there's no doubt a protection diode on the GPIO. So maybe just the resistors would be good enough for the girls I date.

I do like the idea of the voltage divider straight to the GPIO on the pico. I would need a divider anyway for a transistor. I could just forgo the transistor.

image

Highly recommend using the transistor as any spikes on the input are removed completely by the circuit.

You only need the base resistor of appropriate value (start with ≈ 22k).

The collector resistor (R1) can be the Arduino input pull-up resistor.

Arduino pullup is a bit weak for this, would suggest a physical resistor ~10k.

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