arduino - how to read and control the speed of a 12V - four wire fan?
Here is the recommended way to connect up a typical four wire fan. I have used this design multiple times with good success.

The input signal here is a PWM signal of about 20 KHz frequency that controls the fan speed via the duty cycle. As shown the input signal was designed for a 3.3V swing signal but would also work for 5V swing. Most fans have a lower control range at about the 30% duty cycle range where they stop operating. 

The output signal here is a 3.3V swing signal that is the tachometer signal from the fan. You measure the frequency of this signal to determine the fan speed. Note that fans vary and you will find fans that output two or four pulses per revolution on this output. If you need a 5V swing output from this output adjust the values of one of the two lower resistors in the divider. 



The fan connection wire colors are typical but you may find some variations in the colors used by various manufacturers.

This circuit does several things that are important to consider. One this is that it isolates the on-board microcontroller from the voltage range used by the fan which can be important if there are ever faults or mistakes made in the fan wiring harness or connection. Secondly it provides an isolation in the case of static discharge.