-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

4
  • how do you know that there is no current flowing?
    – jsotola
    Nov 28, 2021 at 4:16
  • Don't connect a fan to ANY GPIO pin. They can only safety supply 16mA. You are overloading the GPIO and risk damaging your Pi. If you short the GPIO it will TRY to supply more current, but not for long.
    – Milliways
    Nov 28, 2021 at 4:41
  • pin #3 (3V3) ... no, pin #3 is GPIO2
    – Bravo
    Nov 28, 2021 at 5:00
  • I do not believe this worked on any Pi. Where did you buy a fan which can be powered by a 16mA 3V3 GPIO?
    – joan
    Nov 28, 2021 at 9:24

3 Answers 3

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

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.

3
  • Thanks a lot for all the info Seamus. I will study it. Can you tell me why there is a diode in reverse in your schema (and Milliways schema too)? Seems to me that it would work without it and that it would not light up at all...
    – Joe Mop
    Nov 29, 2021 at 1:10
  • @JoeMop: The diode is there to control the "inductive kick" or back emf that results when the current flow through the motor is interrupted; i.e. when you switch the transistor OFF. Without it, the voltage could increase to a level such that the transistor was damaged. The diode is not the only way (nor is it necessarily the most effective way) to limit the back emf, but it is the easiest.
    – Seamus
    Nov 29, 2021 at 18:04
  • Haa makes sense. Thanks again.
    – Joe Mop
    Nov 29, 2021 at 19:06
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.

3
  • It's a fan from canakit.com labeled DC 5V 0.12A. I connected it on pins 5 and 6 (GPIO 3 and ground). I understand from the answers here that it should never had worked but it was working nicely with one Pi with bash code using "vcgencmd measure_temp"
    – Joe Mop
    Nov 29, 2021 at 1:09
  • 5V * 0.12A = 0.6W. This is much more than 0.062W, the maximum rated power of a GPIO (almost ten times more). Beware of not burning something in the Raspi with this consumption.
    – Joan I
    Nov 29, 2021 at 8:07
  • Thanks, i will never do it again. Hope everything is ok.
    – Joe Mop
    Nov 29, 2021 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.