Confused about a schematic for controlling relay that I found

It would, as long as the MOSFET is a logic level type, that is the gate will respond to 5V and 3V3 inputs.
Most MOSFETs are not and even though the MOSFET may conduct with 5V or 3V3 the on resistance may be higher than quoted in the specs.

Tom.. :grinning: :+1: :coffee: :australia:

Well ,now we would get into a discussion about how MOSFETs work, how to read data sheets, etc
A little too much for a forum post.

I have not yet found a good tutorial for a beginner, many of them are either too complicated, too simple, or just wrong.

Yes, thank you, I learnt a lot from this discussion :slight_smile: Just one more, as for the MOSFET voltages, would something like this work? (adding a BJT, now the power to the MOSFET gate would come from the 5V source, so no issue with 3V). And the resistance of the resistors are wrong, but would that principle work?
image

According to KVL/KCL, energy flows from higher potential-point to
lower potential-point. So, everything is safe.

And after that point there's no voltage right, but the current still flows somewhere, right? The electrons doesn't just stop at the IO-pin? I'm always confusing GND with where the electrons actually end up.

Look at the following Current Flow Model (Fig-1, based on KVL) between 5V and DPin-8. There is a continuous flow of energy through R21 resistor being carried by current I (4.1 mA) and is attributed to the so called electron flow in the opposite direction of current. However, the modern theory is not the electron flow but it is impulse at the energy source.
IOCurrentModel
Figure-1:

Yes but it functionally does the same thing as the circuit in post #1 and is more complicated

After what point?

Thank you! Never heard of impulse at the energy source before. What's the difference? :slight_smile:

Thank you! I will go with the original schematic (I understand it much better now). Is that solution with the level-shifter safe to use, during startup of the microcontroller, with floating pins and what not? I know very little about electronics, but I know you need to take certain precautions when you connect an IO-pin to a MOSFET (such as adding a pulldown-resistor in the schematics of the fan I sent and so on). Is that something you need to worry about if you use the level-shifter design, given that you include the pullup-resistor?

I meant that the current flows from high to low potential, is that IO pin (with 0.9V) connected to something else with even lower potential? I have know idea how the wirings of the IO pins work.

For the level-shifter btw, is there no risk of applying that 5V to the IO-pin (when it's set to LOW)? I read about some cases where it would damage the device if 5V was applied to IO-pins?

The I/O pins of most micros default to being inputs during reset, so they are basically disconnected.

If you want to make sure that whatever is connected to an I/O pin has a HIGH or LOW signal during reset, then you need to either connect a pullup or pulldown resistor. For the level translator, the 1K pullup makes sure that the PWM signal to the servo is HIGH during a reset or booting.

Thank you so much for explaining so thouroughly and quickly! :slight_smile:

I meant that the current flows from high to low potential, is that IO pin (with 0.9V) connected to something else with even lower potential?

You need to ask @GolamMostafa about his circuit

Thanks for all of the replies!

In general for microcontrollers, if I want to sink current like in the example above, does the voltage matter? I.e. for a Raspberry Pi, which is said to not be able to handle 5V (just 3.3), would the lever-shifter fry the microcontroller with the above setup (even if the current, 5V / 1000Ohm is well below the maximum sink-capacity)?

Thats the whole point of a level shifter. The 3.3V side will only see 3.3V and the 5V side will only see 5V and never the twain shall meet.

But when the IO-pin is LOW and the MOSFET is activated, the 5V power source will pretty muc h be connected to the IO-pin right, and subject it to 5V? Wouldnt that be the same thing as connecting a 5V power source (with a 1000 resistor) to the IO-pin?

What is the voltage at the I/O pin when the MOSFET is off?
What is the voltage at the I/O pin when the MOSFET is on?

When the MOSFET is off, it's 3.3 (which makes the voltage between gate and source too low to activate the MOSFET).

When the MOSFET is on, the IO pin outputs 0 (or 0.9) volts and has a connection to the 5V power source?

On the other hand, I guess if the voltage at the IO pin becomes higher than 3.3 Volts from the 5V source, then the MOSFET would close?