Controlling cooling fan for Raspberry Pi 4

It’ll depend on the pin used and you might need a transistor as I explained earlier.

I am using the pimoroni fan shim, it uses GPIO 18 for fan control.
I did look at what you had done but was under the impression that this was what the shim component of my fan handled… It would be hard to implement something like you have i think in my situation as the shim sits over the GPIO pins.

ok, I see the design now. I’m really not sure if you can do that with the Shim. Likely depends on the fan itself and how much current it draws.

I have worked it out. there was poor contact with GPIO 18, I flexed the pin a little and the fan worked as expected.
I did some reading on the Pimoroni forum seems the friction fit isn’t that great (personally I was always not sure of it) there is a few reports of people trying 3 fan shims before they get one that works properly. All can be fixed by some solder or bending of pins but I’d rather not have to resort to that.

1 Like

Thank you for the inspiration, might make the fan controller in node-red instead though :slight_smile:

(Godt at se, der er andre i Odense, som bruger Home Assistant!)

Thanks for pointing me in the right direction. I just got the fan shim installed and the logic still didn’t seem to be working. Simply touching the GPIO 18 pin so that it made contact with the fan shim PCB turned the fan off and on properly. It’s a bit hacky, but I’ve just got the male end of a jumper wire lightly wedged in there to help it make contact and now it’s working as expected.

1 Like

it’s work fine !
thank you so much

Hi,

Thanks a lot for sharing this very nice piece of work! I’m quite new both in RPi and HA, but I noticed that GPIO18 has a built-in hardware PWM, and was wondering if we can go beyond the (possibily noisy!) on/off control directly from HA.

I noticed the link provided previously ( https://www.instructables.com/id/PWM-Regulated-Fan-Based-on-CPU-Temperature-for-Ras/ ), but I don’t know how it could be adapted to HA.

Thanks again!
Mick

I use this, having wired up a fan along the lines of the instructions link. What I found (like you) is that the fan switches on / off regularly. I had bought a Pi case with the fan in a perforated lid, it also came with small heatsinks for 4 of the chips.
I mounted the Pi vertically, removed the top of the case and had the fan vertical, off to one side so it doesn’t impede airflow and pointing at the board (so pushing air rather than pulling it). The convection airflow is now efficient enough that the fan only rarely turns on, when it does it is more efficient by pushing air. It is far from the ‘elegant’ solution that the box provides, but has a relatively constant temperature rather than the see-saw effect that this fan / case combination generates. and sits at a fairly constant 48C: image

As mentioned in the first post:

I don’t suggest setting it to 55°C for other than testing

So I was not that surprised about the frequent fan triggering (approx. every 10 minutes on my side after setting the cold tolerance to -10°C and the hot one to 5° C). However, I finished up with setting the target temperature to 64.5 with hot tolerance of 0.5 °C and cold one to 15° C. It seems the Pi found its comfort zone. The fan triggers no more than 4-5 times/day now. And it seems this temperature (so 65°C for starting the fan).

However I am impressed by your set up and how efficient air convection :slight_smile: ! What is the load of the Pi (e.g., on my side I have several dockers like Plex running)? If you have some time, would you mind posting a photo of the set up? Thanks!

Excellent documentation. For those that are interested, I found it easier to use systemmonitor in your config file to get the processor temperature data. It seems to be a little more accurate and easier to integrate where I prefer farenheit.

Also, if you don’t have a pimroni fan shim with a built in controlling circuit, I believe the same thing can be accomplished with one transistor. I’m going to give it a shot when I get the transistor in the mail.

Yes, this is how I implemented it, using a old school 2N2222. I don’t remember exactly, but I guess I used a base resistor around 10 kOhms.

Hi!

Thanx for sharing.

What I would like is to to have the fan controlled with a rpm span from 0 to 100% not just like a switch like now, on or off. Kinda annoying everytime the fan kicks in 100%.
This is the case when you install pimoroni’s python script.
https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-fan-shim
But that’s not possible then running HA with HassOs !?

Running HassOs in the summerhouse (annoyed), and raspbian os + Home Assistant Supervised at the flat.
I’ve got 3 or 4 of the Pimoroni’s for my Pi’s, all worked flawless.

I haven’t tried it, but I would say PWM would be a possibility for that. While all GPIOs can have software PWM to my knowledge, GPIO18 has a built-in hardware one.

@Odenseaner Great Code, thanks for that! May I ask you how I could hide the second card (the Switch card) in dashboard view? Because now it is a duplicate as I can toggle the fan from within the Climate card, too.

Am i understanding the component correctly, in that you adjust the wheel to set a target temperature, and if the pi is hotter than the above temp then the fan starts up and will run until it hits desired temperature?

I can’t seem to get this working on mine - my fan shim runs all the time. I’ve copied in the configuration, and added the climate entity to my dashboard. Manually switching between “cool” and “off” doesn’t do anything.

As the fan is running all the time the pi is relatively cool (around 45/47), so it’s under the “min_temp” threshold. So i would expect the fan to stop running until it hits the target temp.

Is there anything i missed out when installing this?

TIA.

Hi, so I’m new to this and raspberry pi’s

Where do I put the code in HA?

Also, I got the Pi fan - https://thepihut.com/products/raspberry-pi-4-case-fan and raspberry 4.
I have it setup on 5v, GND, and GIPO as per the instructions on the box. In Raspbian it manages the fan speed but now I’ve got HA installed it doesn’t.

Once I find out where to put the code do I just change the line " 18: RPI Cooling Fan" to " 4: RPI Cooling Fan"?
(4 is assuming from pins are numbered left to right one row at a time)image

Thanks! Glad to be part of this community!

EDIT: I figured out the above.

But I can’t get the code to work. I get the UI but the off button doesn’t work so the fan is on 24/7 still.

EDIT 2: Fixed it. I had two things in my configuration.yaml code: that were named “switch.***”

1 Like

Can I connect the Fan Shim and MH-Z19B to one device?

Thank you! Works fine with RPi4 and the cooling fan for the official case. We only need change to the gpio 14. I’m using HASS OS 5.12

2 Likes

This is a cool interface. I was looking for it. But I noticed that the fan comes On & Off at short intervals. I setup the target to 60 and min_cycle_duration to 60seconds. Cooling the Pi soon but after the fan is off the Pi heats up again soon.

Should the fan blow in air or out?