# Fan Speed Regulation PWM GPIO

**URL:** <https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240>\
**Category:** General\
**Tags:** node-red-dashboard, function-node\
**Created:** [9 August 2022 15:54 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240 "2022-08-09T15:54:58Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 August 2022 09:32 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/21 "2022-08-10T09:32:04Z")

</div>

@Sleep don't tie the grounds together until you have verified that the signal pin you are connecting to the fan can never have more than 3.3 volts on it, otherwise you may destroy the pi output pin, if not the pi itself.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [10 August 2022 09:39 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/22 "2022-08-10T09:39:47Z")

</div>

Good point Colin. I had assumed the Noctua input circuitry took care of that.  
I've looked at their datasheets and they don't show what's inside the fan's enclosure.

As I said before, I never allow my IoT students to connect things to the GPIO pins as it's so easy to destroy a Pi, much safer to use a Wemos or some other cheap microcontroller to do the interfacing.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 August 2022 09:42 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/23 "2022-08-10T09:42:28Z")

</div>

> [@dynamicdave](#):
>
> I've looked at their datasheets and they don't show what's inside the fan's enclosure.

Does it say what input signal it expects?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [10 August 2022 09:45 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/24 "2022-08-10T09:45:20Z")

</div>

I found this in their spec - looks like it will accept up to +5V TTL levels, so +3V3 should be acceptable ?

 ![spec](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6629fbaf447e6fd8db839839b0ddcb600c28ab8.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 August 2022 09:53 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/25 "2022-08-10T09:53:07Z")

</div>

> [@dynamicdave](#):
>
> looks like it will accept up to +5V TTL levels, so +3V3 should be acceptable

In terms of damage to the pi, the question is what voltage is on the pin when it is floating. If it floats up to 5v (which may be the case if it expects a pulldown signal) then it may damage the pi. The spec may well not define that. If I were doing this myself then I would probably not connect it directly.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [10 August 2022 09:55 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/26 "2022-08-10T09:55:57Z")

</div>

> [@Colin](#):
>
> If I were doing this myself then I would probably not connect it directly.

**Agreed** - that's what I think I said at the start of this thread.  
A pair of NMOS and PMOS transistors are dirt cheap and would avoid damaging a precious Pi.

---

<div class="post-metadata">

**Author:** ![Sleep](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@Sleep](https://discourse.nodered.org/u/Sleep)\
**Post date:** [10 August 2022 10:24 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/27 "2022-08-10T10:24:06Z")

</div>

![P_20220810_121505](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a76e7921d41a37f9bea6c9ff26fc5091d8c435a.jpeg)

Thats how it is connected. Should I connect the PWM signal cable to the GND?  
Should I use pullup or down?  
What about the RPM speed signal?

Time is the limiting factor right now. There are plenty of Pi:s

Thanks for your time

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [10 August 2022 10:43 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/28 "2022-08-10T10:43:44Z")

</div>

**OK - if you have plenty of spare Pi:s and willing to take the risk...**

I would some how get a connection from the GND on the Fan or power supply to a GND pin on the Pi.  
This might mean breaking into the GND wire on the lead that goes to the Fan's 4-pin plug.

Let's get the PWM part working first, then we can investigate the Speed-feedback.

Hope it works for you.

PS:  
Can I ask... is this part of a uni/college/school project?

PPS:  
Just to prove your RPi is still working, you could try wiring an LED to an output pin, like I showed above, and make sure you can control its brilliance via PWM, otherwise you could end-up trying to sort out the 'wrong' problem. Hope that makes sense?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [11 August 2022 05:37 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/30 "2022-08-11T05:37:31Z")

</div>

Sounds as if you are making progress.  
What frequency setting are you using for the PWM node?  
Looking at the spec on the Noctua datasheet it says... Target freq is 25kHz with an acceptable range between 21kHz to 28kHz. So you could try 25000 Hz in the PWM node.  
**I have no idea what the max value the PWM node will support, you'll have to look that up.**  
See @Colin comments below.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 August 2022 08:40 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/31 "2022-08-11T08:40:15Z")

</div>

I may not be up to date, but I suspect the standard node will not do anything like that frequency. I think you have to use a different node (node-red-node-pi-gpiod?) which uses the hardware rather than s/w to do the pwm. As I said, I may not be correct in this though. Hopefully someone more knowledgeable will comment.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 August 2022 11:17 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/32 "2022-08-11T11:17:25Z")

</div>

Yes. Better to use pi gpiod node as @Colin suggests

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [11 August 2022 12:23 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/33 "2022-08-11T12:23:29Z")

</div>

Here's part of a PM message I exchanged with @Sleep first thing this morning.

_I read somewhere that two pins on the Pi use hardware to perform PWM, the others use software (I assume 'bit banging') which may limit the switching frequency. You'll have to look that up._

---

<div class="post-metadata">

**Author:** ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)\
**Post date:** [11 August 2022 14:13 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/34 "2022-08-11T14:13:45Z")

</div>

See this link: [Using Raspberry Pi to Control a PWM Fan and Monitor its Speed - DriftKingTW's Blog](https://blog.driftking.tw/en/2019/11/Using-Raspberry-Pi-to-Control-a-PWM-Fan-and-Monitor-its-Speed/)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [11 August 2022 14:48 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/35 "2022-08-11T14:48:03Z")

</div>

Thanks for sharing your link - I'm sure that will help @Sleep tremendously.

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [16 August 2022 05:13 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/36 "2022-08-16T05:13:12Z")

</div>

I've got two Noctua 12v PC fans running from an ESP8266 (Same outputs as the Pi). You will find that the fan has 4 wires,

1. +12vdc
2. GRD
3. PWM input (12vdc)
4. Tach (Hall effect speed sensor) References ground.

I had no luck driving it at 3.3v from the ESP, I had to use a level shifter (3.3v to 12v) with common ground to get it to work reliably.  
1khz turned out to be the optimal PWM frequency (Less motor whine)

The schematic for my installation:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66d81e0a153765b2077a34011e8c32bfc0fc4f3c.jpeg)

Block chart:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83a7114abcc7e82b2cf07cf1a071ccd0b921925e.png)  
Installation images and some additional context:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9dba17a0a3ad1009f9a57331f5deb71e73bd978e.jpeg)

And finally, the (still work in progress) NR flow to control it (via Home Assistant).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5cf50833f8581e1eef87ea83c9f33a4a2965b20e.png)

Reading the thread, you seem to have the PWM part of the Pi working ok, so now you need to step up your pi's GPIO voltage to 12v to drive the fans internal circuit, and remember to use a suitable resistor on the output to protect the Pi - 47k will do it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 October 2022 05:13 UTC](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240/37 "2022-10-15T05:13:57Z")

</div>

Closed on 15 October 2022 05:13 UTC

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

[Previous page](https://discourse.nodered.org/t/fan-speed-regulation-pwm-gpio/66240.md?page=1)
