Can´t get GPIO switch to work for fan on RPI4

This morning I switched over from an RPI3+ to RPI4 (standard HassOS, 32bit install) as I was hitting the limit of the memory.of the 3.
As the RPI4 is getting hotter, I wanted to regulate the fan according to the code posted here:

The fan works on 3.3v (proven by the fact if I connect it to the ground and 3.3v), but the code in the attached does not work and I am quite sure I use the right pin GPIO18:

The code seems to work, but the pin does not seem to activate the fan, so looks like the GPIO switch does not trigger the in to go up…


Anyone have any clue why this might be?

Just measured with a volt meter and the GPIO works. It however is not providing enough power over the GPIO as it gets to 2.5v, so my suspicion is that the fan is pulling too much current. Any suggestion? Worst case I’ll just keep it on always on the 3.3v pin, but I’d rather regulate it.

Did you just connect a 2 wire fan directly to the ground pin and a GPIO pin? In that case you need to incorporate a transistor and resistor into your setup. That way a low voltage GPIO pin can switch on/off a higher voltage fan. You can see an Instructables guide here. (look at the hardware part only)

Thanks! that is finally indeed what I did. I noticed with a voltmeter that it worked, but it was not enough indeed. So I indeed came to a similar solution (transistor and resistor) and just now fixed it 5 mins ago (so it fits in the case)!