Using ESP to drive a computer 4pin fan

Hi, I’m new to the forum and an enthusiastic about electronics, with very limited knowledge. In my current project I’m using an ESP (nodeMCU/Wemos D1 - have both available) board to control the fan speed based on the temperature reading. Using DHT22 for the temperature and a Noctua NF-P12 (4 pin) as the fan. I’m using a 12v power supply to drive the fan and a buck converter regulator to power the microcontroller. The main problem I’m facing is with the signal the MC sends to the fan PWM. The fan requires a 5v input but the board only sends 3.3v, thus the fan only spin at ~50% its full rpm due to the lower voltage. Any suggestion on how to fix this? Thanks

you likely need logic level shifter

Hi, Using a bistable logic converter the 3.3V can be pulled up to 5V. You can also try using a pull-up resistor of the appropriate value. Hope this helps!

The text telling about 50% speed looks really strange. Post a wiring diagram.

KASSIMSAMJI: you likely need logic level shifter

Yes, but that is probably not a suitable one.

robu: You can also try using a pull-up resistor of the appropriate value.

No you cannot!

Use a 74HCT14. Two gates in cascade so the signal is inverted and then inverted again. Powered from 5 V and the inputs of the unused gates connected to ground.

Oh yes, don't forget to put a 100 nF capacitor across the 5 V and ground on the 74HCT14. :grinning:

Thanks all for replying. I really want to conclude this project and I can feel you will show me the way!

Railroader:
The text telling about 50% speed looks really strange.
Post a wiring diagram.

I attached the wiring diagram, with the board schematics and the serial monitor print. The rpm this time is 1/3 of full speed. If you look at the last reads, I removed the PWM pin from the board and the fan went full speed ~1700rpm.

Serial Monitor.png

Wemos D1 schematics.png

Do I understand that You just cut the D4 to PWM connection and got 100%? Something is misinterfacing then. Do You have a link to the data sheet of the fan? What is the capacity of the controller to source/sink current? I'm an Arduino UNO guy....

Paul__B: Yes, but that is probably not a suitable one. No you cannot!

Use a 74HCT14. Two gates in cascade so the signal is inverted and then inverted again. Powered from 5 V and the inputs of the unused gates connected to ground.

Oh yes, don't forget to put a 100 nF capacitor across the 5 V and ground on the 74HCT14. :grinning:

What would be a suitable lvl converter? I'm really new to electronics, so building one from without an image/diagram would be hard for me. Thanks

Railroader: Do I understand that You just cut the D4 to PWM connection and got 100%? Something is misinterfacing then. Do You have a link to the data sheet of the fan? What is the capacity of the controller to source/sink current? I'm an Arduino UNO guy....

That is correct. When I remove the PWM pin the fan goes 100%. For this code, I removed the DHT and made it in a way just to test the fan control, so all I'm doing is an "analogWrite(pin, pwm)" and I'm varying the PWM to read the fan rpm. If I ran this exact same diagram and code on a Mega2560 everything works flawless. My assumption of the issue is that the Mega (and the Uno) operate at 5v and the ESP only at 3.3v, not providing enough V on the PWM pin. The following links relate to the FAN specs https://noctua.at/en/nf-p12-redux-1700-pwm/faq - Product page https://noctua.at/en/productfaqs/productfaq/view/id/215/ - Fan pin specs

I think I've found the explanation. The fan needs 5 volt logic but Your controller only offers 3.3 volt. You need a 0 - 5 volt PWM to the fan. Do You have any 5 volt available? If the fan has a 5 volt pullup on the PWM pin and the controller controls a transistor switching/PWM-ing the fan, it could work. What do You think?

Railroader: I think I've found the explanation. The fan needs 5 volt logic but Your controller only offers 3.3 volt. You need a 0 - 5 volt PWM to the fan. Do You have any 5 volt available? If the fan has a 5 volt pullup on the PWM pin and the controller controls a transistor switching/PWM-ing the fan, it could work. What do You think?

It could work, but would this allow me to control the PWM or will be more like a on/off state?

Also, can you assist me with a diagram or point me to literature on how to identify the right transistor/resistor for it?

The key question is, do You have 5 volt available for the pullup? It will handle PWM. I think a common bipolar NPN transistor would work. A signal transistor, not any power one. From controller D4 a serial resistor of some 1 kOhm to transistor Base. From +5 volt a 1 kOhm to transistor Collector. From Collector connect to fan PWM pin. Emitter connects to GND. PWM will be reversed. PWM 255 will give 0% fan and PWM 0 will give 100%.

Why use a transistor? :astonished:

A 74HCT14 is cheap enough and does the job with one component. OK, plus a capacitor.

You are powering the WeMOS D1 Mini from 5 V, so you have 5 V. :sunglasses:

Railroader: The key question is, do You have 5 volt available for the pullup? It will handle PWM. I think a common bipolar NPN transistor would work. A signal transistor, not any power one. From controller D4 a serial resistor of some 1 kOhm to transistor Base. From +5 volt a 1 kOhm to transistor Collector. From Collector connect to fan PWM pin. Emitter connects to GND. PWM will be reversed. PWM 255 will give 0% fan and PWM 0 will give 100%.

Thanks. I'll give it a shoot this weekend. I have two transistors in hand, the PN222 and the S8050. Looked at the specs of both and they seam to work. Any suggestion on which one to go with?

Paul__B: Why use a transistor? :astonished:

A 74HCT14 is cheap enough and does the job with one component. OK, plus a capacitor.

You are powering the WeMOS D1 Mini from 5 V, so you have 5 V. :sunglasses:

Thanks Paul. I'll try the transistor first as I already have some spare. But will do some further research on the hex Schmitt trigger you suggested. Hopefully this project will be a success! Thanks again for all your help

The PN2222 will do fine.

Railroader:
The key question is, do You have 5 volt available for the pullup?
It will handle PWM.
I think a common bipolar NPN transistor would work. A signal transistor, not any power one.
From controller D4 a serial resistor of some 1 kOhm to transistor Base. From +5 volt a 1 kOhm to transistor Collector. From Collector connect to fan PWM pin. Emitter connects to GND.
PWM will be reversed. PWM 255 will give 0% fan and PWM 0 will give 100%.

Its “kind of” working now. Good thing is that with the pwm pin on, fan is now spinning at 100% - see image. But two things I noticed:
1- duty is inverted - with 0 fan goes to full speed and as duty increases (until get to 255 - 100%) rpm reduces. tis is not a problem at all for me, as can be fixed with the code;
2- The lowest speed the fan is getting to (at full duty - inverted as per point above) is 1380 rpm, and I would need this to go much lower (ideally 0)
I have the assumption that with the transistor, the voltage going to the fan PWM pin got inverted. Before I was sending 0 to ~+0, and now I’m sending 5 and ~-5v. Checking the RPM numbers, before I was getting 0 to 600, a delta of 600. Now I’m getting ~1700 to ~1450, delta of 250rpm. So looks like the voltage variance now is lower.
Any thoughts?

Serial Monitor 2021-02-27.png

laoc: Its "kind of" working now. Good thing is that with the pwm pin on, fan is now spinning at 100% - see image.

Good. I expected that.

But two things I noticed: 1- duty is inverted - with 0 fan goes to full speed and as duty increases (until get to 255 - 100%) rpm reduces. tis is not a problem at all for me, as can be fixed with the code;

Just as I told in my reply.

2- The lowest speed the fan is getting to (at full duty - inverted as per point above) is 1380 rpm, and I would need this to go much lower (ideally 0)

That's a surprice. My first thought is that the transistor is either not connected the right way or the resistors need to be modified. Measure voltages around the transistor, GND - collector and GND - base. If You can measure the current from fan down to the collector it would be fine. I assumed "signal level" current.

I have the assumption that with the transistor, the voltage going to the fan PWM pin got inverted. Before I was sending 0 to ~+0, and now I'm sending 5 and ~-5v. Checking the RPM numbers, before I was getting 0 to 600, a delta of 600. Now I'm getting ~1700 to ~1450, delta of 250rpm. So looks like the voltage variance now is lower. Any thoughts?

I don't understand the "delta" You tell about. Can You try another way to express that? The span of the RPM is not what I expected. Good and perfectly posted attachments!

Sorry I missed the part on your reply about inverting the duty cycle. And by the delta I meant the difference between the rpm measured on the first state and now with the resistor. The difference in rpm is lower now.

I managed to measure the V on the transistor, they are as following: Base: .15 to .3v Emitter: 5 to 4.7v

I'm using the 1kOhm resistor in series with the base to the board pin and 1kOhm on the Vcc in to the emitter, and then the emitter is connected to the fan PWM

Okey. I was not clear enough. Measure the collector - emitter, as well as base - emitter voltage when PWM is 255 in the code, no other value. Make a test version code, or lock the PWM temporarily in Your present code.

Base to GND resp. collector to GND, please. The emitter must be connected to GND.

Railroader: Okey. I was not clear enough. Measure the collector - emitter, as well as base - emitter voltage when PWM is 255 in the code, no other value. Make a test version code, or lock the PWM temporarily in Your present code.

Base to GND resp. collector to GND, please. The emitter must be connected to GND.

| Measurement (V) | PWM - 0 | PWM - 255 | | - | - | - | | Collector - Emitter: | 4.9 | 3.7 | | Base - emitter: | 0.12 | 0.22 |