I would like to use my ESP32 to controll a PWM PC Fan. To do that I need a 5V PWM signal. But the ESP32 only has 3,3V on its output. So I was thinking using a transistor could help me out.
But I am not sure if I just can use one transistor or do I need a second transistor or an optocoupler? (Because of the voltage difference and the voltage drop of 0,7V on the transistor?)
This would be how I imagine that it could look like:
The secound question that rised was how do I calcualte the resistors when I do not know the current of the PWM signal?
I also rode that often a mosfet is used, does it offer a big advantage over a transistor in this use case?
And how do you make it right like a professional, to do it in the future the right way too?
And would I have an advantage using a circuit like this which can turn faster off? The diode d1 is for example a BAT85.
Change 12v to 5v; for a PWM fan, the diode will not be required; resistor R30 can be increased in value too, 470R to 1k will probably work for a transistor like 2N2222.
Note it does invert the PWM signal but that will not matter in this case.
I think that looks like what I need. But why do I not need the second resistor? And how do I calculate the resistor the right way or can you just "see" that? (I got stuck with calculating as it required to know the current of the PWM signal for the resistor)
Can you please explain why inverting does not matter? (Maybe because I can invert it I my code or another reason?)
When I use a PNP transistor does that give me the normal PWM signal?
On your second post you show a circuit with 2 resistors. Can you explain to me how the resistors are calculated for the PWM signal.
I would like to understand it myself so I can use that knowlage on other circuits as well.
Thank your for your answer ^^ I hope you can answer my questions.
I could not control it. It just spinned at maximum speed.
I used different test projectes to test it e.g. ESP32 Web Server with Slider: Control LED Brightness (PWM) | Random Nerd Tutorials
This was with and led and not with a fan but I also used some other project to test it but they used a level shifter for the signal and they did not work for me.
When I tested that I only had the around 3,2 volts if i remember right. (I just tested to set the output to a constant output with no PWM to test if there is an signal. But on that test I also used and 5V Powersupply with a 12V Step-up converter for the Fans)
Don´t know if that changes something (They still had the same ground)
I would recommend trying @LarryD 's suggestion from post #3.
It will be a matter of experimenting. We do not know what the circuit inside the fan is, and they are probably not all the same. Different fan manufacturers probably use different circuits, for example.
My particular interest was @PaulRB 's comment about measuring V on the PWM pin and concerns about +12v
Reason being, I've just cooked 3 ESP32 devices and I think this may be the reason. From the thread, I'm using a similar circuit to what @LarryD described as C1 - i.e. with a MOSFET (N channel).
Whilst this isn't Arduino specific (sorry), I'm not sure what I'm doing wrong to get +12v on the PWM pin from the fan (Arctic 80mm PWM).
Appreciate any thoughts and guidance - thanks very much in advance,
My concern there was that if the fan circuit had a internal pull-up to 12V on the PWM pin, and that was directly connected to an ESP32 pin, damage could occur.
But if you are using the MOSFET circuit you described, that would protect the ESP32 from damage, if correctly connected.
So I think something else may have cooked your ESP32.
Post your schematic. Hand drawn is fine. Also maybe some close-up, bright, clear photos showing all the connections.