How to switch 5v through mosfet controlled via 12v

Hi All

I am wanting to switch 5v onto a pin off the arduino but the circuit I am breaking into uses 12v. I was wondering if I could control a mosfet with the 12v and switch the 5v to the arduino

Thank You

Ben

I'm interpreting what you are asking: you want to attach a signal from a 12v source to an Arduino input pin? But you realise that 12v will be too much?

If the above is correct then all you need really is a potential divider (two resistors to turn the 12v into 5v, so a 6.8K resistor and a 4.7K resistor in series might work, connected from the 12v signal to ground with the join of the resistors supplying the 5v signal, try that out, make sure it does not exceed 5v) or even better use an opto-isolator with a series resistor from the 12v supply into the LED side of the opto-isolator and use the other side (which is totally isolated from that other item) to control the Arduino pin.

If I have not understood your requirements, however, then the above will be nonsense so please explain again!

Thank you

I think a opto coupler would be best as I need to completely isolate the 12v from the 5v. The 12v can rise to as high as 14.5v so that would change the output of a voltage divider.

ullisees:
Hi All

I am wanting to switch 5v onto a pin off the arduino but the circuit I am breaking into uses 12v. I was wondering if I could control a mosfet with the 12v and switch the 5v to the arduino

Thank You

Ben

More information please - which pin? signal or power?
Sounds like you want to do high side switching of 5V from what is effectively 12V logic signal?

Perhaps a 1k resistor from 12V side to the gate of a p-channel logic-level MOSFET, MOSFET source to 5V, MOSFET
drain to Arduino pin? That would be active-low if that's an issue.

If you want to put a signal on a high-impedance input, I would second the opto-coupler. A PC817 is ridiculously cheap and easily available. Then you also do not have to worry about common ground and that sort of stuff. I even use them to connect different 5V circuits. (Last one I did was a detector if the TV is on, from the RPi mediacenter. If on, USB 5V drive an opto-coupler that goes to an input of the RPi.)

But if its power rather than signal , an opto coupler isn't going to handle it.

The 5v will be a signal wire so not high current.

I was looking at the PC817. What resistance would be needed to drop the 12v so that it would not blow up the IR LED inside the coupler.

Ben

What resistance would be needed to drop the 12v so that it would not blow up the IR LED inside the coupler.

Well, the IR LED would be on the 5V (Arduino) side of the circuit. The transistor side would switch the 12V load ... whatever that is.

To maintain isolation, do not connect the 12V GND to the 5V GND.

To limit the current to about 15mA, you could use a 220Ω resistor connected in series with the IR LED.

I suggest you post a circuit so we don't have to guess at what you're trying to do.

The 12v would be powering the IR Led and the 5v would be being switch via the transistor

Ok, I see now. How about this?

When 12V is present, the opto-transistor drives the Arduino input low (0V), otherwise its pulled high (5V).

ullisees:
The 5v will be a signal wire so not high current.

I was looking at the PC817. What resistance would be needed to drop the 12v so that it would not blow up the IR LED inside the coupler.

Ben

look at the datasheet, it says :

At If = 20mA - Vf (typ) = 1.2V
If the maximum you apply is 14V , then V=RI => R=V/I = (14-1.2)/0.02 = 640 Ohm -> 680 Ohm will be OK
you can even try higher values (around 1,2 kOhm), it works at If=10mA too -

Note that the datasheet for the PC817 show that the IRLED can hanlde up to 50mA max. The 20mA limitation of an Arduino pin does not apply in this case.

What does apply is how much current the 12V signal can source. Is this known?

I didn’t apply any arduino limitation :wink:
I just gave the example to show how to calculate the resistor, and I used a value for which the datasheet gives information -
And yes, it will work with 470 Ohm too -

I suspect the source is a car battery …