-2

I have 2 RPi-4.

I've been using a fan inside a case that is designed by Canakit to be used with RPi-4. I've been using the fan for a few weeks by connecting it to constant 5V and ground. Everything was fine.

I am now trying to plug the fan on pin #3 so i can start it only when the cpu temp goes above a certain value. It works well on my first RPi4 but not my second RPi4. On that one, i measured with a voltmeter and saw that voltage is effectively triggered on or off on that pin when the fan is not conencted... but when i connect the fan between ground and pin #3, it stays on for a fraction of a second and then turns off. This behavior only happens on my second RPi.

I did read 1 or 2 other questions very similar to this one and i understand that RPi would try to turn off the pin if too much current was drawn into it, but the current should not be too high, as it was working on the 5V pin. It also woks on my first RPi4. Any suggestion?

Thanks,

Joe

Joe Mop
  • 7
  • 4

3 Answers3

1

If you want to control a fan from GPIO you need some external circuitry, although this is minimal.

I use the following with my Pi4 Fan control

Milliways
  • 62,573
  • 32
  • 113
  • 225
1

First:

The pin reference you used (pin #3 (3V3)) in your question is ambiguous. Please see the Raspberry Pi pinout, and edit your question to indicate whether you're using GPIO pin numbers, or physical pin numbers. For example, physical pin #3 is GPIO 2, and 3V3 is at physical pin #1.

Second:

If your fan is one of the two-wire fans, do not connect either fan terminal to a GPIO pin. To be clear: The red/+V fan wire may need to be connected to one of the RPi's power pins (physical pins #1, #2 or #4), but these are not GPIO pins. Again, refer to the Raspberry Pi pinout.

Instead, to control your fan based on chip temperatures on the RPi, your fan should be wired as shown in the schematic below. Most fans can be wired to either the 3V3 bus for slower speed, or the 5V bus for higher speed; check your fan specs to verify.

schematic

simulate this circuit – Schematic created using CircuitLab

Third:

There are (at least) two ways to control your fan:

1. Use the device tree overlay:

This is the easiest way to control your fan based on the chip temperature. Open the file /boot/overlays/README on your RPi & find the following:

Name: gpio-fan
Info: Configure a GPIO pin to control a cooling fan.
Load: dtoverlay=gpio-fan,=
Params:
gpiopin GPIO used to control the fan (default 12)
temp Temperature at which the fan switches on, in millicelcius (default 55000)

To switch the fan on at 48℃ with GPIO 17 (physical pin # 11 on the header) requires only the addition of the following line to your file /boot/config.txt:

dtoverlay=gpio-fan,temp=48000,gpiopin=17

Assuming your hardware is properly wired, and /boot/config.txt has been edited, a reboot will commence the automated fan control.

2. Write your own code to implement fan control

Using your language of choice (e.g. Python, bash, C, etc), and corresponding GPIO library (or sysfs), write code to set the appropriate GPIO pin to logic HIGH to turn the transistor Q1 on, and power the fan. Temperature may be measured using the command vcgencmd measure_temp. Writing your own code may be preferable if you wish to gain some experience in programming the GPIO, or if other control variables need to be incorporated.

Seamus
  • 23,558
  • 5
  • 42
  • 83
0

A Raspberry should not be able to run any fan without some additional circuitry: GPIOs can supply 16 mA @ 3.3V, that is, it can supply only 52 mW. This is enough to light a led but not enough to drive a fan. I do not know any fan that could run with such small power.

You say that the fan worked in a Pi4 but not on a second one. Could you give some details of the fan and how it was connected to the first Pi4 ? Normally you should use either a relay or a transistor, as suggested by Milliways. Knowing the details of the fan should allow a precise answer to your question.

Joan I
  • 9
  • 5