I would like to buy a
Noctua NF-A4x10 5V PWM which is PWM enabled 5V Fan for 4 pins. So I would like be able to control it via code. Here is a question:As I said, its for 4 pins. How can I plug it? Is it possible? Will it work? Here is a picture
You can't just plug it in. The Pi has no fan support.
You will have to identify the ground, 5V power, sense (output from fan), and PWM (input to fan) pins.
Connect ground and power to appropriate pins on the Pi.
If you want to use the sense output then connect it to any spare GPIO. Also add a 4k7 resistor between that GPIO and 3V3 (the sense output is open collector). You can then monitor the GPIO and read its frequency to determine the fan rotational speed (two pulses per revolution).
The PWM output requires a 25 kHz signal. The most effective way of getting that signal is by connecting to one of the hardware PWM GPIO, i.e. 12, 13, 18, or 19. You can then control the fan speed by varying the dutycycle. Several libraries are available to control the PWM signal (e.g. my pigpio, wiringPi, bcm2835 etc).