can analogWrite be used to set voltages?

Question in title since values range from 0-255, using this ratio can I set voltage values at analog pins?


Yes and no.

It is not a DAC, it is PWM, it is a pulsed output with the dutycycle ranging from 0 to 100%.

You can put a filter on it to get the average value rather than the pulse.

10K resistor and 4.7uF cap to Gnd make a good low pass filter.
Here’s PWM output with 0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250 as filtered output.