I wish to control a 4 pin 12V dc pc fan (https://www.arctic.ac/en/F9-PWM/AFACO-090P2-GBA01) with my raspberry pie. After reading several threads I came up with the following:
First problem is that the PWM signal must be 5V but the GPIOs only give 3.3V. So I decided to use a level shifter from 3.3V to 5V (https://www.amazon.com/-/de/dp/B07LG646VS/ref=sr_1_3?dchild=1&keywords=level+shifter&qid=1605728038&sr=8-3) to feed a 5V PWM signal to the fan. Other than that I connected an external 12V dc power supply to the fan (first two pins on the fan connector).
The only thing left to do is to connect the GPIO pin which I use for the PWM signal to the 4th pin of the fan. In the end my circuit looks like the one from this tutorial: https://www.raspberrypi-spy.co.uk/2018/09/using-a-level-shifter-with-the-raspberry-pi-gpio/ except that I don´t use a 5V sensor but the 5V PWM input of the fan. So the PWM signal wire is the only connection between the pie and the fan.
Good thing is that the fan is running (at full speed) when I connect the power supply. I use the following code to vary the duty cycle.
import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 25000) p.start(0) time.sleep(2) try: while True: p.ChangeDutyCycle(100) print('100') time.sleep(5) p.ChangeDutyCycle(50) print('50') time.sleep(5) p.ChangeDutyCycle(0) print('0') time.sleep(5) except KeyboardInterrupt: pass p.ChangeDutyCycle(0) p.stop() GPIO.cleanup()
When I connect the fan to the dc power supply, connect the 5V PWM signal and start the script the fan will continue to run at full speed, no matter what.
To test if my circuit is wrong I installed a LED which gets the 5V PWM signal as the positive voltage. The LED changes from 100% brightness to 50% and then switches off as expected.
I tested every connection line of the four from the level shifter. I tested another fan. I switched to other GPIOs. Unfortuntely it´s always the same result. LED works perfectly. Fan runs at full speed all the time.
I really like the idea of using a level shifter. It´s a compact and simple solution for me. So my question is if somebody has an idea where the problem is and how to solve it.
A second question related to this is if it would be beneficial to use a L298n motor driver for fan control.