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.

simulate this circuit – Schematic created using CircuitLab
Third:
There are (at least) two ways to control your fan:
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.
pin #3 (3V3)
... no, pin #3 is GPIO2 – Bravo Nov 28 '21 at 05:00