Voltage regulation via PWM works very well from 0V, but only without the load. The lowest possible setting the output voltage after connecting the load is 4-5V. How can I fix this?
A capacitor at the Arduino's ADC input will filter the PWM to give you an average. 1uF - 10uF should be about right with your 10K resistors.
Vout = 18V - analogRead(A0) / 1024 * 5V * 4 (in sketch arduino)
int R = 200;byte value = map(R, 0, 1023, 0, 255);analogWrite(9, value);
How about if you turn and & off pin-9 digitally (without PWM)? If you're measuring PWM with a multimeter you won't generally read the average unless you have a mechanical/analog meter.
You have probably blown up that analogue input because when your TIP122 is off there is in effect no current down the potential divider so you are blasting 18V into the analogue input.
To measure the voltage you want you will need to measure the voltage on the 18V rail, and measure the voltage on the transistor cathode, then subtract one from the other to get the voltage across your fans.
Dont forget its PWM so you may need to place a low pass filter between the resistor array and the analog input.
You have issues around the +ve input of U5. Op amps work off voltage Inputs not current. That opto isolator output is not going to be able to control the output of U5.
That does look a lot better. It's still an unconventional way to do it. The LM317 means that you can never have your output go below 1.25v. Do you never want to switch this regulated output completely off?